Skip to content

Commit f6e32d1

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 8e51230 commit f6e32d1

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ final class BuildPlanTests: XCTestCase {
4343
"/barPkg/Sources/BarLogging/file.swift"
4444
)
4545
let observability = ObservabilitySystem.makeForTesting()
46+
let fooPkg: AbsolutePath = "/fooPkg"
47+
let barPkg: AbsolutePath = "/barPkg"
4648
XCTAssertThrowsError(try loadPackageGraph(
4749
fileSystem: fs,
4850
manifests: [
4951
Manifest.createFileSystemManifest(
5052
displayName: "fooPkg",
51-
path: "/fooPkg",
53+
path: fooPkg,
5254
products: [
5355
ProductDescription(name: "Logging", type: .library(.dynamic), targets: ["FooLogging"]),
5456
],
@@ -57,7 +59,7 @@ final class BuildPlanTests: XCTestCase {
5759
]),
5860
Manifest.createFileSystemManifest(
5961
displayName: "barPkg",
60-
path: "/barPkg",
62+
path: barPkg,
6163
products: [
6264
ProductDescription(name: "Logging", type: .library(.static), targets: ["BarLogging"]),
6365
],
@@ -69,24 +71,21 @@ final class BuildPlanTests: XCTestCase {
6971
path: "/thisPkg",
7072
toolsVersion: .v5_8,
7173
dependencies: [
72-
.localSourceControl(path: "/fooPkg", requirement: .upToNextMajor(from: "1.0.0")),
73-
.localSourceControl(path: "/barPkg", requirement: .upToNextMajor(from: "2.0.0")),
74+
.localSourceControl(path: fooPkg, requirement: .upToNextMajor(from: "1.0.0")),
75+
.localSourceControl(path: barPkg, requirement: .upToNextMajor(from: "2.0.0")),
7476
],
7577
targets: [
7678
TargetDescription(name: "exe",
77-
dependencies: [.product(name: "Logging",
78-
package: "fooPkg"
79-
),
80-
.product(name: "Logging",
81-
package: "barPkg"
82-
),
79+
dependencies: [.product(name: "Logging", package: "fooPkg"),
80+
.product(name: "Logging", package: "barPkg"),
8381
],
8482
type: .executable),
8583
]),
8684
],
8785
observabilityScope: observability.topScope
8886
)) { error in
89-
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple products named 'Logging' in: 'barpkg' (at '/barPkg'), 'foopkg' (at '/fooPkg')")
87+
XCTAssertEqual((error as? PackageGraphError)?.description,
88+
"multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')")
9089
}
9190
}
9291

@@ -418,13 +417,15 @@ final class BuildPlanTests: XCTestCase {
418417
"/barPkg/Sources/BarLogging/file.swift"
419418
)
420419
let observability = ObservabilitySystem.makeForTesting()
420+
let fooPkg: AbsolutePath = "/fooPkg"
421+
let barPkg: AbsolutePath = "/barPkg"
421422

422423
XCTAssertThrowsError(try loadPackageGraph(
423424
fileSystem: fs,
424425
manifests: [
425426
Manifest.createFileSystemManifest(
426427
displayName: "fooPkg",
427-
path: "/fooPkg",
428+
path: fooPkg,
428429
toolsVersion: .v5_8,
429430
products: [
430431
ProductDescription(name: "Logging", type: .library(.automatic), targets: ["FooLogging"]),
@@ -434,7 +435,7 @@ final class BuildPlanTests: XCTestCase {
434435
]),
435436
Manifest.createFileSystemManifest(
436437
displayName: "barPkg",
437-
path: "/barPkg",
438+
path: barPkg,
438439
products: [
439440
ProductDescription(name: "Logging", type: .library(.automatic), targets: ["BarLogging"]),
440441
],
@@ -450,19 +451,16 @@ final class BuildPlanTests: XCTestCase {
450451
],
451452
targets: [
452453
TargetDescription(name: "exe",
453-
dependencies: [.product(name: "Logging",
454-
package: "fooPkg"
455-
),
456-
.product(name: "Logging",
457-
package: "barPkg"
458-
),
454+
dependencies: [.product(name: "Logging", package: "fooPkg"),
455+
.product(name: "Logging", package: "barPkg"),
459456
],
460457
type: .executable),
461458
]),
462459
],
463460
observabilityScope: observability.topScope
464461
)) { error in
465-
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple products named 'Logging' in: 'barpkg' (at '/barPkg'), 'foopkg' (at '/fooPkg')")
462+
XCTAssertEqual((error as? PackageGraphError)?.description,
463+
"multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')")
466464
}
467465
}
468466

@@ -3526,7 +3524,7 @@ final class BuildPlanTests: XCTestCase {
35263524
toolset: .init(
35273525
knownTools: [
35283526
.cCompiler: .init(extraCLIOptions: ["-I/fake/sdk/sysroot", "-clang-flag-from-json"]),
3529-
.swiftCompiler: .init(extraCLIOptions: ["-swift-flag-from-json"])
3527+
.swiftCompiler: .init(extraCLIOptions: ["-use-ld=lld", "-swift-flag-from-json"])
35303528
],
35313529
rootPaths: try UserToolchain.default.swiftSDK.toolset.rootPaths
35323530
),
@@ -3557,7 +3555,17 @@ final class BuildPlanTests: XCTestCase {
35573555
XCTAssertMatch(try lib.basicArguments(isCXX: false), args)
35583556

35593557
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
3560-
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"])
3558+
XCTAssertMatch(exe, [
3559+
"-module-cache-path", "\(buildPath.appending(components: "ModuleCache"))",
3560+
.anySequence,
3561+
"-swift-flag-from-json",
3562+
.anySequence,
3563+
"-swift-command-line-flag",
3564+
.anySequence,
3565+
"-Xcc", "-clang-flag-from-json",
3566+
.anySequence,
3567+
"-Xcc", "-clang-command-line-flag"
3568+
])
35613569
}
35623570

35633571
func testUserToolchainWithToolsetCompileFlags() throws {
@@ -3740,14 +3748,17 @@ final class BuildPlanTests: XCTestCase {
37403748
XCTAssertNoDiagnostics(observability.diagnostics)
37413749

37423750
let targetTriple = try UserToolchain.default.targetTriple
3743-
let sdkIncludeSearchPath = "/usr/lib/swift_static/none/include"
3744-
let sdkLibrarySearchPath = "/usr/lib/swift_static/none/lib"
3751+
let sdkIncludeSearchPath = AbsolutePath("/usr/lib/swift_static/none/include")
3752+
let sdkLibrarySearchPath = AbsolutePath("/usr/lib/swift_static/none/lib")
37453753
let swiftSDK = try SwiftSDK(
37463754
targetTriple: targetTriple,
37473755
properties: .init(
37483756
sdkRootPath: "/fake/sdk",
3749-
includeSearchPaths: [sdkIncludeSearchPath],
3750-
librarySearchPaths: [sdkLibrarySearchPath]))
3757+
includeSearchPaths: [sdkIncludeSearchPath.pathString],
3758+
librarySearchPaths: [sdkLibrarySearchPath.pathString]),
3759+
toolset: .init(knownTools: [
3760+
.swiftCompiler: .init(extraCLIOptions: ["-use-ld=lld"]),
3761+
]))
37513762
let toolchain = try UserToolchain(swiftSDK: swiftSDK)
37523763
let buildParameters = mockBuildParameters(toolchain: toolchain)
37533764
let result = try BuildPlanResult(plan: BuildPlan(
@@ -4740,9 +4751,8 @@ final class BuildPlanTests: XCTestCase {
47404751

47414752
let yamlContents: String = try fs.readFileContents(yaml)
47424753
XCTAssertMatch(yamlContents, .contains("""
4743-
inputs: ["/Pkg/Snippets/ASnippet.swift","/Pkg/.build/debug/Lib.swiftmodule"
4754+
inputs: ["\(AbsolutePath("/Pkg/Snippets/ASnippet.swift")._nativePathString(escaped: true))","\(AbsolutePath("/Pkg/.build/debug/Lib.swiftmodule")._nativePathString(escaped: true))"
47444755
"""))
4745-
47464756
}
47474757

47484758
private func sanitizerTest(_ sanitizer: PackageModel.Sanitizer, expectedName: String) throws {

0 commit comments

Comments
 (0)