Skip to content

Commit 5bde380

Browse files
committed
Tests: ensure that the path will be relative
There is no guarantee that the path between the temporary directory and current working directory can be represented with a relative path. This is particularly important on Windows where the paths may reside on different volumes, which have separate roots. Alter the two instances in the test to use the current directory for the temporary storage, and ensure that we clean up afterwards as we are likely in the source tree.
1 parent dffa61d commit 5bde380

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,11 @@ final class SwiftDriverTests: XCTestCase {
303303
#if os(Windows)
304304
throw XCTSkip("TSCUtility.RelativePath failure")
305305
#else
306-
try withTemporaryDirectory { path in
307-
guard let cwd = localFileSystem.currentWorkingDirectory else {
308-
fatalError()
309-
}
306+
guard let cwd = localFileSystem.currentWorkingDirectory else {
307+
fatalError()
308+
}
309+
310+
try withTemporaryDirectory(dir: cwd, removeTreeOnDeinit: true) { path in
310311
let main = path.appending(component: "main.swift")
311312
let util = path.appending(component: "util.swift")
312313
let utilRelative = util.relative(to: cwd)
@@ -1134,10 +1135,11 @@ final class SwiftDriverTests: XCTestCase {
11341135
#if os(Windows)
11351136
throw XCTSkip("TSCUtility.RelativePath failure")
11361137
#else
1137-
try withTemporaryDirectory { path in
1138-
guard let cwd = localFileSystem.currentWorkingDirectory else {
1139-
fatalError()
1140-
}
1138+
guard let cwd = localFileSystem.currentWorkingDirectory else {
1139+
fatalError()
1140+
}
1141+
1142+
try withTemporaryDirectory(dir: cwd, removeTreeOnDeinit: true) { path in
11411143
let outputFileMap = path.appending(component: "outputFileMap.json")
11421144
try localFileSystem.writeFileContents(outputFileMap) {
11431145
$0 <<< """

0 commit comments

Comments
 (0)