Skip to content

Commit adc2200

Browse files
authored
SwiftDocCUtilitiesTests: adjust TestFileSystem's handling of paths (#655)
When constructing a `URL` with a file path, we should always use `init(fileURLWithPath:)` as not all paths are represented as a URL and require additional encoding. On Windows, this would result in us stripping the drive prefix (`C:`) which would corrupt the path and thus fail to lookup the item. In the second instance, this allowed us to simply avoid an object copy entirely. This helps improve the test pass rate significantly on Windows.
1 parent d3239b1 commit adc2200

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

Tests/SwiftDocCUtilitiesTests/Utility/TestFileSystem.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,7 @@ class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProvider {
209209
filesLock.lock()
210210
defer { filesLock.unlock() }
211211

212-
guard let target = URL(string: path) else {
213-
throw Errors.invalidPath(path)
214-
}
215-
216-
let parent = target.deletingLastPathComponent()
217-
212+
let parent = URL(fileURLWithPath: path).deletingLastPathComponent()
218213
if parent.pathComponents.count > 1 {
219214
// If it's not the root folder, check if parents exist
220215
if createIntermediates == false {
@@ -262,8 +257,7 @@ class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProvider {
262257
filesLock.lock()
263258
defer { filesLock.unlock() }
264259

265-
guard let fileURL = URL(string: at.path),
266-
files.keys.contains(fileURL.deletingLastPathComponent().path) else {
260+
guard files.keys.contains(at.deletingLastPathComponent().path) else {
267261
throw NSError(domain: NSCocoaErrorDomain, code: NSFileNoSuchFileError, userInfo: [NSFilePathErrorKey: at.path])
268262
}
269263

0 commit comments

Comments
 (0)