Skip to content

Commit 76942a6

Browse files
committed
Tests: adjust the BuildPlanTests for Windows
The Windows toolchain does not find the default linker by default as that requires the sourcing of Visual Studio's scripts to setup the environment. Adjust the tests to explicitly specify the linker to ensure that the toolchain is usable on Windows without constraint on the environment. While in the area, adjust the expectations to account for platform path spellings. This allows us to pass these tests on Windows now. Adjust the path representation to account for Windows to allow the matching to succeed.
1 parent 696e9d7 commit 76942a6

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3536,7 +3536,7 @@ final class BuildPlanTests: XCTestCase {
35363536
toolset: .init(
35373537
knownTools: [
35383538
.cCompiler: .init(extraCLIOptions: ["-I/fake/sdk/sysroot", "-clang-flag-from-json"]),
3539-
.swiftCompiler: .init(extraCLIOptions: ["-swift-flag-from-json"])
3539+
.swiftCompiler: .init(extraCLIOptions: ["-swift-flag-from-json", "-use-ld=lld"]),
35403540
],
35413541
rootPaths: try UserToolchain.default.destination.toolset.rootPaths
35423542
),
@@ -3567,7 +3567,18 @@ final class BuildPlanTests: XCTestCase {
35673567
XCTAssertMatch(try lib.basicArguments(isCXX: false), args)
35683568

35693569
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
3570-
XCTAssertMatch(exe, ["-module-cache-path", "\(buildPath.appending(components: "ModuleCache"))", .anySequence, "-swift-flag-from-json", "-g", "-swift-command-line-flag", .anySequence, "-Xcc", "-clang-flag-from-json", "-Xcc", "-g", "-Xcc", "-clang-command-line-flag"])
3570+
XCTAssertMatch(exe, [
3571+
"-module-cache-path",
3572+
"\(buildPath.appending(components: "ModuleCache"))",
3573+
.anySequence,
3574+
"-swift-flag-from-json",
3575+
.anySequence,
3576+
"-swift-command-line-flag",
3577+
.anySequence,
3578+
"-Xcc", "-clang-flag-from-json",
3579+
.anySequence,
3580+
"-Xcc", "-clang-command-line-flag"
3581+
])
35713582
}
35723583

35733584
func testUserToolchainWithToolsetCompileFlags() throws {
@@ -3757,7 +3768,10 @@ final class BuildPlanTests: XCTestCase {
37573768
properties: .init(
37583769
sdkRootPath: "/fake/sdk",
37593770
includeSearchPaths: [sdkIncludeSearchPath],
3760-
librarySearchPaths: [sdkLibrarySearchPath]))
3771+
librarySearchPaths: [sdkLibrarySearchPath]),
3772+
toolset: .init(knownTools: [
3773+
.swiftCompiler: .init(extraCLIOptions: ["-use-ld=lld"]),
3774+
]))
37613775
let toolchain = try UserToolchain(destination: destination)
37623776
let buildParameters = mockBuildParameters(toolchain: toolchain)
37633777
let result = try BuildPlanResult(plan: BuildPlan(
@@ -3770,17 +3784,17 @@ final class BuildPlanTests: XCTestCase {
37703784

37713785
// Compile C Target
37723786
let cLibCompileArguments = try result.target(for: "cLib").clangTarget().basicArguments(isCXX: false)
3773-
let cLibCompileArgumentsPattern: [StringPattern] = ["-I", "\(sdkIncludeSearchPath)"]
3787+
let cLibCompileArgumentsPattern: [StringPattern] = ["-I", "\(AbsolutePath(sdkIncludeSearchPath)._nativePathString(escaped: false))"]
37743788
XCTAssertMatch(cLibCompileArguments, cLibCompileArgumentsPattern)
37753789

37763790
// Compile Swift Target
37773791
let exeCompileArguments = try result.target(for: "exe").swiftTarget().compileArguments()
3778-
let exeCompileArgumentsPattern: [StringPattern] = ["-I", "\(sdkIncludeSearchPath)"]
3792+
let exeCompileArgumentsPattern: [StringPattern] = ["-I", "\(AbsolutePath(sdkIncludeSearchPath)._nativePathString(escaped: false))"]
37793793
XCTAssertMatch(exeCompileArguments, exeCompileArgumentsPattern)
37803794

37813795
// Link Product
37823796
let exeLinkArguments = try result.buildProduct(for: "exe").linkArguments()
3783-
let exeLinkArgumentsPattern: [StringPattern] = ["-L", "\(sdkIncludeSearchPath)"]
3797+
let exeLinkArgumentsPattern: [StringPattern] = ["-L", "\(AbsolutePath(sdkIncludeSearchPath)._nativePathString(escaped: false))"]
37843798
XCTAssertMatch(exeLinkArguments, exeLinkArgumentsPattern)
37853799
}
37863800

@@ -4750,7 +4764,7 @@ final class BuildPlanTests: XCTestCase {
47504764

47514765
let yamlContents: String = try fs.readFileContents(yaml)
47524766
XCTAssertMatch(yamlContents, .contains("""
4753-
inputs: ["/Pkg/Snippets/ASnippet.swift","/Pkg/.build/debug/Lib.swiftmodule"
4767+
inputs: ["\(AbsolutePath("/Pkg/Snippets/ASnippet.swift")._nativePathString(escaped: true))","\(AbsolutePath("/Pkg/.build/debug/Lib.swiftmodule")._nativePathString(escaped: true))"
47544768
"""))
47554769

47564770
}

0 commit comments

Comments
 (0)