Skip to content

Commit 1611127

Browse files
authored
Merge pull request #949 from compnerd/environment
Tests: correct environment testing for Windows
2 parents b0e5353 + 43eabbf commit 1611127

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,12 +2833,28 @@ final class SwiftDriverTests: XCTestCase {
28332833
}
28342834

28352835
XCTAssertFalse(job.commandLine.contains(.flag("--")))
2836-
// On darwin, swift ships in the OS. Immediate mode should use that runtime.
2837-
#if os(macOS)
2838-
XCTAssertFalse(job.extraEnvironment.keys.contains("\(driver.targetTriple.isDarwin ? "DYLD" : "LD")_LIBRARY_PATH"))
2839-
#else
2840-
XCTAssertTrue(job.extraEnvironment.keys.contains("\(driver.targetTriple.isDarwin ? "DYLD" : "LD")_LIBRARY_PATH"))
2841-
#endif
2836+
2837+
let envVar: String
2838+
if driver.targetTriple.isDarwin {
2839+
envVar = "DYLD_LIBRARY_PATH"
2840+
} else if driver.targetTriple.isWindows {
2841+
envVar = "Path"
2842+
} else {
2843+
// assume Unix
2844+
envVar = "LD_LIBRARY_PATH"
2845+
}
2846+
2847+
// The library search path applies to import libraries not runtime
2848+
// libraries on Windows. There is no way to derive the path from the
2849+
// command on Windows.
2850+
if !driver.targetTriple.isWindows {
2851+
#if os(macOS)
2852+
// On darwin, swift ships in the OS. Immediate mode should use that runtime.
2853+
XCTAssertFalse(job.extraEnvironment.keys.contains(envVar))
2854+
#else
2855+
XCTAssertTrue(job.extraEnvironment.keys.contains(envVar))
2856+
#endif
2857+
}
28422858
}
28432859

28442860
do {
@@ -2869,11 +2885,25 @@ final class SwiftDriverTests: XCTestCase {
28692885
XCTAssertEqual(job.inputs.count, 1)
28702886
XCTAssertEqual(job.inputs[0].file, .relative(RelativePath("foo.swift")))
28712887
XCTAssertEqual(job.outputs.count, 0)
2872-
XCTAssertTrue(job.extraEnvironment.contains {
2873-
$0 == "\(driver.targetTriple.isDarwin ? "DYLD" : "LD")_LIBRARY_PATH" && $1.contains("/path/to/lib")
2874-
})
2888+
2889+
let envVar: String
28752890
if driver.targetTriple.isDarwin {
2876-
XCTAssertTrue(job.extraEnvironment.contains { $0 == "DYLD_FRAMEWORK_PATH" && $1.contains("/path/to/framework") })
2891+
envVar = "DYLD_LIBRARY_PATH"
2892+
} else if driver.targetTriple.isWindows {
2893+
envVar = "Path"
2894+
} else {
2895+
// assume Unix
2896+
envVar = "LD_LIBRARY_PATH"
2897+
}
2898+
2899+
// The library search path applies to import libraries not runtime
2900+
// libraries on Windows. There is no way to derive the path from the
2901+
// command on Windows.
2902+
if !driver.targetTriple.isWindows {
2903+
XCTAssertTrue(job.extraEnvironment[envVar, default: ""].contains("/path/to/lib"))
2904+
if driver.targetTriple.isDarwin {
2905+
XCTAssertTrue(job.extraEnvironment["DYLD_FRAMEWORK_PATH", default: ""].contains("/path/to/framework"))
2906+
}
28772907
}
28782908

28792909
XCTAssertTrue(job.commandLine.contains(.flag("-lsomelib")))

0 commit comments

Comments
 (0)