Skip to content

Commit 618bbbb

Browse files
committed
Tests: compute the TestInputs path more robustly
This adjusts the computation of the `TestInputs` path by walking the components in reverse. Doing so ensures that we can use the native path separator character, which is required for the proper behaviour on Windows. With this change we now pass additional tests in the SwiftDriverTests test suite.
1 parent 05fff44 commit 618bbbb

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ private func rebase(_ arcs: String..., at base: AbsolutePath) -> String {
3535
base.appending(components: arcs).pathString.nativePathString()
3636
}
3737

38+
private var testInputsPath: AbsolutePath = {
39+
var root: AbsolutePath = AbsolutePath(#file)
40+
while root.basename != "Tests" {
41+
root = root.parentDirectory
42+
}
43+
return root.parentDirectory.appending(component: "TestInputs")
44+
}()
45+
3846
final class SwiftDriverTests: XCTestCase {
3947

4048
private var envWithFakeSwiftHelp: [String: String] {
@@ -3426,12 +3434,9 @@ final class SwiftDriverTests: XCTestCase {
34263434

34273435
func testDarwinSDKTooOld() throws {
34283436
func getSDKPath(sdkDirName: String) -> AbsolutePath {
3429-
let packageRootPath = AbsolutePath(String(URL(fileURLWithPath: #file).pathComponents
3430-
.prefix(while: { $0 != "Tests" }).joined(separator: "/").dropFirst()))
3431-
let testInputsPath = packageRootPath.appending(component: "TestInputs")
3432-
.appending(component: "SDKChecks")
3433-
return testInputsPath.appending(component: sdkDirName)
3437+
return testInputsPath.appending(component: "SDKChecks").appending(component: sdkDirName)
34343438
}
3439+
34353440
// Ensure an error is emitted for an unsupported SDK
34363441
func checkSDKUnsupported(sdkDirName: String)
34373442
throws {
@@ -5375,10 +5380,8 @@ final class SwiftDriverTests: XCTestCase {
53755380
}
53765381

53775382
func testPrebuiltModuleCacheFlags() throws {
5378-
let packageRootPath = URL(fileURLWithPath: #file).pathComponents
5379-
.prefix(while: { $0 != "Tests" }).joined(separator: "/").dropFirst()
5380-
let testInputsPath = packageRootPath + "/TestInputs"
5381-
let mockSDKPath : String = testInputsPath + "/mock-sdk.sdk"
5383+
let mockSDKPath: String =
5384+
testInputsPath.appending(component: "mock-sdk.sdk").pathString.nativePathString()
53825385

53835386
do {
53845387
var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-ios13.1-macabi", "foo.swift", "-sdk", mockSDKPath])

0 commit comments

Comments
 (0)