Skip to content

TestFoundation: use .standardizingPath for normalization #2010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions TestFoundation/TestProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,27 +281,8 @@ class TestProcess : XCTestCase {
}
}

private func realpathOf(path: String) -> String? {
let fm = FileManager.default
let length = Int(PATH_MAX) + 1
var buf = [Int8](repeating: 0, count: length)
let fsRep = fm.fileSystemRepresentation(withPath: path)
#if !DARWIN_COMPATIBILITY_TESTS
defer { fsRep.deallocate() }
#endif
guard let result = realpath(fsRep, &buf) else {
return nil
}
return fm.string(withFileSystemRepresentation: result, length: strlen(result))
}

func test_current_working_directory() {
let tmpDir = "/tmp"

guard let resolvedTmpDir = realpathOf(path: tmpDir) else {
XCTFail("Cant find realpath of /tmp")
return
}
let tmpDir = "/tmp".standardizingPath

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