Skip to content

Commit 24d86c4

Browse files
authored
Merge pull request #2606 from buttaface/droid
TestFoundation: change CWD to TMPDIR and restore previous CWD when test finishes
2 parents 13aa5ee + 35fcc79 commit 24d86c4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

TestFoundation/TestURL.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ class TestURL : XCTestCase {
286286
static var gBaseCurrentWorkingDirectoryPath : String {
287287
return FileManager.default.currentDirectoryPath
288288
}
289+
static var gSavedPath = ""
289290
static var gRelativeOffsetFromBaseCurrentWorkingDirectory: UInt = 0
290291
static let gFileExistsName = "TestCFURL_file_exists\(ProcessInfo.processInfo.globallyUniqueString)"
291292
static let gFileDoesNotExistName = "TestCFURL_file_does_not_exist"
@@ -339,9 +340,8 @@ class TestURL : XCTestCase {
339340
}
340341
}
341342

342-
#if os(Android)
343-
FileManager.default.changeCurrentDirectoryPath("/data/local/tmp")
344-
#endif
343+
TestURL.gSavedPath = FileManager.default.currentDirectoryPath
344+
FileManager.default.changeCurrentDirectoryPath(NSTemporaryDirectory())
345345

346346
let cwd = FileManager.default.currentDirectoryPath
347347
let cwdURL = URL(fileURLWithPath: cwd, isDirectory: true)
@@ -358,6 +358,7 @@ class TestURL : XCTestCase {
358358
let error = strerror(errno)!
359359
XCTFail("Failed to set up test paths: \(String(cString: error))")
360360
}
361+
defer { FileManager.default.changeCurrentDirectoryPath(TestURL.gSavedPath) }
361362

362363
// test with file that exists
363364
var path = TestURL.gFileExistsPath
@@ -403,6 +404,7 @@ class TestURL : XCTestCase {
403404
let error = strerror(errno)!
404405
XCTFail("Failed to set up test paths: \(String(cString: error))")
405406
}
407+
defer { FileManager.default.changeCurrentDirectoryPath(TestURL.gSavedPath) }
406408

407409
// test with file that exists
408410
var path = TestURL.gFileExistsPath

0 commit comments

Comments
 (0)