Skip to content

Commit a38e32c

Browse files
committed
TestFoundation: don't use hard-coded TestURL test directory on Android
Use NSTemporaryDirectory() instead and reset the working directory when done.
1 parent e6e0046 commit a38e32c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

TestFoundation/TestURL.swift

Lines changed: 7 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)
@@ -396,6 +396,8 @@ class TestURL : XCTestCase {
396396
let lengthOfRelativePath = Int(strlen(TestURL.gFileDoesNotExistName))
397397
let relativePath = fileSystemRep.advanced(by: Int(TestURL.gRelativeOffsetFromBaseCurrentWorkingDirectory))
398398
XCTAssertTrue(strncmp(TestURL.gFileDoesNotExistName, relativePath, lengthOfRelativePath) == 0, "fileSystemRepresentation of file path is wrong")
399+
400+
FileManager.default.changeCurrentDirectoryPath(TestURL.gSavedPath)
399401
}
400402

401403
func test_fileURLWithPath_isDirectory() {
@@ -451,6 +453,8 @@ class TestURL : XCTestCase {
451453
let lengthOfRelativePath = Int(strlen(TestURL.gFileDoesNotExistName))
452454
let relativePath = fileSystemRep.advanced(by: Int(TestURL.gRelativeOffsetFromBaseCurrentWorkingDirectory))
453455
XCTAssertTrue(strncmp(TestURL.gFileDoesNotExistName, relativePath, lengthOfRelativePath) == 0, "fileSystemRepresentation of file path is wrong")
456+
457+
FileManager.default.changeCurrentDirectoryPath(TestURL.gSavedPath)
454458
}
455459

456460
func test_URLByResolvingSymlinksInPath() {

0 commit comments

Comments
 (0)