Skip to content

Tests: correct environment testing for Windows #949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2833,12 +2833,28 @@ final class SwiftDriverTests: XCTestCase {
}

XCTAssertFalse(job.commandLine.contains(.flag("--")))
// On darwin, swift ships in the OS. Immediate mode should use that runtime.
#if os(macOS)
XCTAssertFalse(job.extraEnvironment.keys.contains("\(driver.targetTriple.isDarwin ? "DYLD" : "LD")_LIBRARY_PATH"))
#else
XCTAssertTrue(job.extraEnvironment.keys.contains("\(driver.targetTriple.isDarwin ? "DYLD" : "LD")_LIBRARY_PATH"))
#endif

let envVar: String
if driver.targetTriple.isDarwin {
envVar = "DYLD_LIBRARY_PATH"
} else if driver.targetTriple.isWindows {
envVar = "Path"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don’t have any assertions for this case. If I understand the comment below, there isn’t anything to assert?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct; there is nothing to really assert on - Path is always part of the environment. So the assertion would check absolutely nothing.

} else {
// assume Unix
envVar = "LD_LIBRARY_PATH"
}

// The library search path applies to import libraries not runtime
// libraries on Windows. There is no way to derive the path from the
// command on Windows.
if !driver.targetTriple.isWindows {
#if os(macOS)
// On darwin, swift ships in the OS. Immediate mode should use that runtime.
XCTAssertFalse(job.extraEnvironment.keys.contains(envVar))
#else
XCTAssertTrue(job.extraEnvironment.keys.contains(envVar))
#endif
}
}

do {
Expand Down Expand Up @@ -2869,11 +2885,25 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertEqual(job.inputs.count, 1)
XCTAssertEqual(job.inputs[0].file, .relative(RelativePath("foo.swift")))
XCTAssertEqual(job.outputs.count, 0)
XCTAssertTrue(job.extraEnvironment.contains {
$0 == "\(driver.targetTriple.isDarwin ? "DYLD" : "LD")_LIBRARY_PATH" && $1.contains("/path/to/lib")
})

let envVar: String
if driver.targetTriple.isDarwin {
XCTAssertTrue(job.extraEnvironment.contains { $0 == "DYLD_FRAMEWORK_PATH" && $1.contains("/path/to/framework") })
envVar = "DYLD_LIBRARY_PATH"
} else if driver.targetTriple.isWindows {
envVar = "Path"
} else {
// assume Unix
envVar = "LD_LIBRARY_PATH"
}

// The library search path applies to import libraries not runtime
// libraries on Windows. There is no way to derive the path from the
// command on Windows.
if !driver.targetTriple.isWindows {
XCTAssertTrue(job.extraEnvironment[envVar, default: ""].contains("/path/to/lib"))
if driver.targetTriple.isDarwin {
XCTAssertTrue(job.extraEnvironment["DYLD_FRAMEWORK_PATH", default: ""].contains("/path/to/framework"))
}
}

XCTAssertTrue(job.commandLine.contains(.flag("-lsomelib")))
Expand Down