Skip to content

Commit bb84e7b

Browse files
authored
Merge pull request swiftlang#42 from benlangmuir/test-fallback
[test] Add tests for FallbackBuildSystem
2 parents eb1c5df + 92ccb25 commit bb84e7b

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
@testable import SKCore
14+
15+
import Basic
16+
import XCTest
17+
18+
final class FallbackBuildSystemTests: XCTestCase {
19+
20+
func testSwift() {
21+
let sdk = AbsolutePath("/my/sdk")
22+
let source = AbsolutePath("/my/source.swift")
23+
24+
let bs = FallbackBuildSystem()
25+
bs.sdkpath = sdk
26+
27+
XCTAssertNil(bs.indexStorePath)
28+
XCTAssertNil(bs.indexDatabasePath)
29+
30+
let settings = bs.settings(for: source.asURL, .swift)!
31+
XCTAssertNil(settings.preferredToolchain)
32+
XCTAssertNil(settings.workingDirectory)
33+
34+
let args = settings.compilerArguments
35+
XCTAssertEqual(args, [
36+
"-sdk",
37+
sdk.asString,
38+
source.asString,
39+
])
40+
41+
bs.sdkpath = nil
42+
43+
XCTAssertEqual(bs.settings(for: source.asURL, .swift)?.compilerArguments, [
44+
source.asString,
45+
])
46+
}
47+
48+
func testCXX() {
49+
let sdk = AbsolutePath("/my/sdk")
50+
let source = AbsolutePath("/my/source.cpp")
51+
52+
let bs = FallbackBuildSystem()
53+
bs.sdkpath = sdk
54+
55+
let settings = bs.settings(for: source.asURL, .cpp)!
56+
XCTAssertNil(settings.preferredToolchain)
57+
XCTAssertNil(settings.workingDirectory)
58+
59+
let args = settings.compilerArguments
60+
XCTAssertEqual(args, [
61+
"-isysroot",
62+
sdk.asString,
63+
source.asString,
64+
])
65+
66+
bs.sdkpath = nil
67+
68+
XCTAssertEqual(bs.settings(for: source.asURL, .cpp)?.compilerArguments, [
69+
source.asString,
70+
])
71+
}
72+
73+
func testC() {
74+
let source = AbsolutePath("/my/source.c")
75+
let bs = FallbackBuildSystem()
76+
bs.sdkpath = nil
77+
XCTAssertEqual(bs.settings(for: source.asURL, .c)?.compilerArguments, [
78+
source.asString,
79+
])
80+
}
81+
82+
func testObjC() {
83+
let source = AbsolutePath("/my/source.m")
84+
let bs = FallbackBuildSystem()
85+
bs.sdkpath = nil
86+
XCTAssertEqual(bs.settings(for: source.asURL, .objective_c)?.compilerArguments, [
87+
source.asString,
88+
])
89+
}
90+
91+
func testObjCXX() {
92+
let source = AbsolutePath("/my/source.mm")
93+
let bs = FallbackBuildSystem()
94+
bs.sdkpath = nil
95+
XCTAssertEqual(bs.settings(for: source.asURL, .objective_cpp)?.compilerArguments, [
96+
source.asString,
97+
])
98+
}
99+
100+
func testUnknown() {
101+
let source = AbsolutePath("/my/source.mm")
102+
let bs = FallbackBuildSystem()
103+
XCTAssertNil(bs.settings(for: source.asURL, .unknown))
104+
}
105+
}

Tests/SKCoreTests/XCTestManifests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ extension CompilationDatabaseTests {
1616
]
1717
}
1818

19+
extension FallbackBuildSystemTests {
20+
// DO NOT MODIFY: This is autogenerated, use:
21+
// `swift test --generate-linuxmain`
22+
// to regenerate.
23+
static let __allTests__FallbackBuildSystemTests = [
24+
("testC", testC),
25+
("testCXX", testCXX),
26+
("testObjC", testObjC),
27+
("testObjCXX", testObjCXX),
28+
("testSwift", testSwift),
29+
("testUnknown", testUnknown),
30+
]
31+
}
32+
1933
extension ToolchainRegistryTests {
2034
// DO NOT MODIFY: This is autogenerated, use:
2135
// `swift test --generate-linuxmain`
@@ -37,6 +51,7 @@ extension ToolchainRegistryTests {
3751
public func __allTests() -> [XCTestCaseEntry] {
3852
return [
3953
testCase(CompilationDatabaseTests.__allTests__CompilationDatabaseTests),
54+
testCase(FallbackBuildSystemTests.__allTests__FallbackBuildSystemTests),
4055
testCase(ToolchainRegistryTests.__allTests__ToolchainRegistryTests),
4156
]
4257
}

0 commit comments

Comments
 (0)