Skip to content

Commit 0ebe975

Browse files
committed
fix driver unittests
1 parent 1e0301b commit 0ebe975

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Tests/SwiftDriverTests/SwiftDriverTests.swift

+23-1
Original file line numberDiff line numberDiff line change
@@ -7144,10 +7144,14 @@ final class SwiftDriverTests: XCTestCase {
71447144

71457145
func testRelativeResourceDir() throws {
71467146
do {
7147+
// Reset the environment to avoid 'SDKROOT' influencing the
7148+
// linux driver paths and taking the priority over the resource directory.
7149+
var env = ProcessEnv.vars
7150+
env["SDKROOT"] = nil
71477151
var driver = try Driver(args: ["swiftc",
71487152
"-target", "x86_64-unknown-linux", "-lto=llvm-thin",
71497153
"foo.swift",
7150-
"-resource-dir", "resource/dir"])
7154+
"-resource-dir", "resource/dir"], env: env)
71517155
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
71527156
let compileJob = plannedJobs[0]
71537157
XCTAssertEqual(compileJob.kind, .compile)
@@ -7163,6 +7167,24 @@ final class SwiftDriverTests: XCTestCase {
71637167
}
71647168
}
71657169

7170+
func testSDKDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() throws {
7171+
do {
7172+
let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk")
7173+
var env = ProcessEnv.vars
7174+
env["SDKROOT"] = sdkRoot.pathString
7175+
var driver = try Driver(args: ["swiftc",
7176+
"-target", "x86_64-unknown-linux", "-lto=llvm-thin",
7177+
"foo.swift",
7178+
"-resource-dir", "resource/dir"], env: env)
7179+
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
7180+
let compileJob = plannedJobs[0]
7181+
XCTAssertEqual(compileJob.kind, .compile)
7182+
let linkJob = plannedJobs[1]
7183+
XCTAssertEqual(linkJob.kind, .link)
7184+
XCTAssertTrue(linkJob.commandLine.contains(try toPathOption(sdkRoot.pathString + "/usr/lib/swift/linux/x86_64/swiftrt.o")))
7185+
}
7186+
}
7187+
71667188
func testSanitizerArgsForTargets() throws {
71677189
let targets = ["x86_64-unknown-freebsd", "x86_64-unknown-linux", "x86_64-apple-macosx10.9"]
71687190
try targets.forEach {

0 commit comments

Comments
 (0)