Skip to content

Commit 85cf046

Browse files
authored
Merge pull request swiftlang#39 from benlangmuir/tr-tests
[test] Add a couple of tests for the toolchain registration API
2 parents ca42583 + 3c1b068 commit 85cf046

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

Tests/SKCoreTests/ToolchainRegistryTests.swift

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ final class ToolchainRegistryTests: XCTestCase {
2929
XCTAssertEqual(tr.default?.identifier, "b")
3030
tr.default = nil
3131
XCTAssertEqual(tr.default?.identifier, "a")
32+
XCTAssert(tr.default === tr.toolchain(identifier: "a"))
3233
}
3334

3435
func testDefaultDarwin() {
@@ -169,6 +170,10 @@ final class ToolchainRegistryTests: XCTestCase {
169170
overrideReg.darwinToolchainOverride = "org.fake.global.B"
170171
XCTAssertEqual(overrideReg.darwinToolchainIdentifier, "org.fake.global.B")
171172
XCTAssertEqual(overrideReg.default?.identifier, "org.fake.global.B")
173+
174+
let checkByDir = ToolchainRegistry()
175+
checkByDir.scanForToolchains(xctoolchainSearchPath: toolchains, fs)
176+
XCTAssertEqual(checkByDir.toolchains.count, 4)
172177
#endif
173178
}
174179

@@ -198,9 +203,23 @@ final class ToolchainRegistryTests: XCTestCase {
198203
XCTAssertNil(tc.swiftc)
199204
XCTAssertNotNil(tc.sourcekitd)
200205
XCTAssertNil(tc.libIndexStore)
206+
207+
let binPath2 = AbsolutePath("/other/my_toolchain/bin")
208+
try! setenv("SOME_TEST_ENV_PATH", value: "/bogus:\(binPath2.asString):/bogus2")
209+
makeToolchain(binPath: binPath2, fs, sourcekitd: true)
210+
tr.scanForToolchains(pathVariables: ["NOPE", "SOME_TEST_ENV_PATH", "MORE_NOPE"], fs)
211+
212+
guard let tc2 = tr.toolchains.first(where: { tc in tc.path == binPath2 }) else {
213+
XCTFail("couldn't find expected toolchain")
214+
return
215+
}
216+
217+
XCTAssertEqual(tr.default?.identifier, tc.identifier)
218+
XCTAssertEqual(tc2.identifier, binPath2.asString)
219+
XCTAssertNotNil(tc2.sourcekitd)
201220
}
202221

203-
func testSearchExplicitEnv() {
222+
func testSearchExplicitEnvBuiltin() {
204223
let fs = InMemoryFileSystem()
205224
let tr = ToolchainRegistry(fs)
206225
let binPath = AbsolutePath("/foo/bar/my_toolchain/bin")
@@ -228,6 +247,35 @@ final class ToolchainRegistryTests: XCTestCase {
228247
XCTAssertNil(tc.libIndexStore)
229248
}
230249

250+
func testSearchExplicitEnv() {
251+
let fs = InMemoryFileSystem()
252+
let tr = ToolchainRegistry(fs)
253+
let binPath = AbsolutePath("/foo/bar/my_toolchain/bin")
254+
makeToolchain(binPath: binPath, fs, sourcekitd: true)
255+
256+
XCTAssertNil(tr.default)
257+
XCTAssert(tr.toolchains.isEmpty)
258+
259+
try! setenv("TEST_ENV_SOURCEKIT_TOOLCHAIN_PATH", value: binPath.parentDirectory.asString)
260+
261+
tr.scanForToolchains(
262+
environmentVariables: ["TEST_ENV_SOURCEKIT_TOOLCHAIN_PATH"],
263+
setDefault: false,
264+
fs)
265+
266+
guard let tc = tr.toolchains.first(where: { tc in tc.path == binPath.parentDirectory }) else {
267+
XCTFail("couldn't find expected toolchain")
268+
return
269+
}
270+
271+
XCTAssertEqual(tc.identifier, binPath.parentDirectory.asString)
272+
XCTAssertNil(tc.clang)
273+
XCTAssertNil(tc.clangd)
274+
XCTAssertNil(tc.swiftc)
275+
XCTAssertNotNil(tc.sourcekitd)
276+
XCTAssertNil(tc.libIndexStore)
277+
}
278+
231279
func testFromDirectory() {
232280
// This test uses the real file system because the in-memory system doesn't support marking files executable.
233281
let fs = localFileSystem
@@ -264,6 +312,14 @@ final class ToolchainRegistryTests: XCTestCase {
264312
XCTAssertNotNil(t2.clang)
265313
XCTAssertNotNil(t2.clangd)
266314
XCTAssertNotNil(t2.swiftc)
315+
316+
let tr = ToolchainRegistry()
317+
let t3 = try! tr.registerToolchain(path.parentDirectory, fs)
318+
XCTAssertEqual(t3.identifier, t2.identifier)
319+
XCTAssertEqual(t3.sourcekitd, t2.sourcekitd)
320+
XCTAssertEqual(t3.clang, t2.clang)
321+
XCTAssertEqual(t3.clangd, t2.clangd)
322+
XCTAssertEqual(t3.swiftc, t2.swiftc)
267323
}
268324

269325
func testDylibNames() {

Tests/SKCoreTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extension ToolchainRegistryTests {
2727
("testFromDirectory", testFromDirectory),
2828
("testSearchDarwin", testSearchDarwin),
2929
("testSearchExplicitEnv", testSearchExplicitEnv),
30+
("testSearchExplicitEnvBuiltin", testSearchExplicitEnvBuiltin),
3031
("testSearchPATH", testSearchPATH),
3132
("testSubDirs", testSubDirs),
3233
("testUnknownPlatform", testUnknownPlatform),

0 commit comments

Comments
 (0)