Skip to content

Commit 3d21379

Browse files
committed
TestFoundation: use .standardizingPath for normalization
Rather than use `realpath` which is not universally available, use `.standardizingPath` which should normalize the path as `realpath` on all the targets since we are testing `Process` rather than `FileManager`.
1 parent 953257c commit 3d21379

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

TestFoundation/TestProcess.swift

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -281,27 +281,8 @@ class TestProcess : XCTestCase {
281281
}
282282
}
283283

284-
private func realpathOf(path: String) -> String? {
285-
let fm = FileManager.default
286-
let length = Int(PATH_MAX) + 1
287-
var buf = [Int8](repeating: 0, count: length)
288-
let fsRep = fm.fileSystemRepresentation(withPath: path)
289-
#if !DARWIN_COMPATIBILITY_TESTS
290-
defer { fsRep.deallocate() }
291-
#endif
292-
guard let result = realpath(fsRep, &buf) else {
293-
return nil
294-
}
295-
return fm.string(withFileSystemRepresentation: result, length: strlen(result))
296-
}
297-
298284
func test_current_working_directory() {
299-
let tmpDir = "/tmp"
300-
301-
guard let resolvedTmpDir = realpathOf(path: tmpDir) else {
302-
XCTFail("Cant find realpath of /tmp")
303-
return
304-
}
285+
let tmpDir = "/tmp".standardizingPath
305286

306287
let fm = FileManager.default
307288
let previousWorkingDirectory = fm.currentDirectoryPath
@@ -310,7 +291,7 @@ class TestProcess : XCTestCase {
310291
do {
311292
let (pwd, _) = try runTask([xdgTestHelperURL().path, "--getcwd"], currentDirectoryPath: tmpDir)
312293
// Check the sub-process used the correct directory
313-
XCTAssertEqual(pwd.trimmingCharacters(in: .newlines), resolvedTmpDir)
294+
XCTAssertEqual(pwd.trimmingCharacters(in: .newlines), tmpDir)
314295
} catch {
315296
XCTFail("Test failed: \(error)")
316297
}

0 commit comments

Comments
 (0)