Skip to content

[Windows] Added a test for _getFilesystemRepresentation #2367

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
Apr 25, 2020
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
57 changes: 56 additions & 1 deletion Tests/Foundation/Tests/TestFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,55 @@ VIDEOS=StopgapVideos
}
#endif
}

func test_windowsPaths() throws {
let fm = FileManager.default
let tmpPath = writableTestDirectoryURL.path
do {
try fm.createDirectory(atPath: tmpPath, withIntermediateDirectories: true, attributes: nil)
} catch {
XCTFail()
}
fm.changeCurrentDirectoryPath(tmpPath)
func checkPath(path: String) throws {
XCTAssertTrue(fm.createFile(atPath: path, contents: Data(), attributes: nil))
XCTAssertTrue(fm.fileExists(atPath: path))
try fm.removeItem(atPath: path)
XCTAssertFalse(fm.fileExists(atPath: path))

let url = URL(fileURLWithPath: path)
try "hello world".write(to: url, atomically: false, encoding: .utf8)
try fm.removeItem(atPath: path)
XCTAssertFalse(fm.fileExists(atPath: path))
}
let paths = [
// Absolute Paths
"\(tmpPath)\\testfile", // C:/Users/...\testfile
"\(tmpPath)/testfile", // C:/Users.../testfile
"\(tmpPath)/testfile", // /Users/user/.../testfile
"\(tmpPath.first!):testfile", // C:testfile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, this fails when runner has no Administrator privileges. CI agents are usually elevated, but manual run as user would report failure.


// Relative Paths
".\\testfile",
"..\\\(tmpPath.lastPathComponent)\\.\\testfile",
"testfile",
"./testfile",
"../\(tmpPath.lastPathComponent)/./testfile",

// UNC Paths
"\\\\.\\\(tmpPath)\\testfile",
"\\\\.\\\(tmpPath)/testfile",
"\\\\?\\\(String(tmpPath.map({ $0 == "/" ? "\\" : $0})))\\testfile",

// Unicode characters which require a single WCHAR
"λf.(λx.f(x x) λx.f(x x))",
// Unicode characters which require more than a single WCHAR
"👁️💖🐦",
]
for path in paths {
try checkPath(path: path)
}
}

// -----

Expand Down Expand Up @@ -1827,7 +1876,13 @@ VIDEOS=StopgapVideos
("test_fetchXDGPathsFromHelper", test_fetchXDGPathsFromHelper),
])
#endif


#if os(Windows)
tests.append(contentsOf: [
("test_windowsPaths", test_windowsPaths),
])
#endif

return tests
}
}