Skip to content

Commit b4c92f8

Browse files
committed
Fix tests on Linux
1 parent cac06d8 commit b4c92f8

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ A file-system pathing library focused on developer experience and robust
44
end‐results.
55

66
```swift
7+
import Path
8+
79
// convenient static members
810
let home = Path.home
911

@@ -26,7 +28,7 @@ try Path.root.join("foo").copy(into: Path.root.mkdir("bar"))
2628
// were meant to be directory destinations
2729
```
2830

29-
Paths are just string representations, there *may not* be a real file there.
31+
Paths are just string representations, there *might not* be a real file there.
3032

3133
# Support mxcl
3234

Sources/Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public extension Data {
4747
func write(to: Path, atomically: Bool = false) throws -> Path {
4848
let opts: NSData.WritingOptions
4949
if atomically {
50-
#if os(macOS)
50+
#if !os(Linux)
5151
opts = .atomicWrite
5252
#else
5353
opts = .atomic

Sources/Path+FileManager.swift

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,37 @@ public extension Path {
7373
return try "".write(to: self)
7474
}
7575

76-
@inlinable
77-
@discardableResult
78-
public func mkdir() throws -> Path {
76+
private func _foo(go: () throws -> Void) throws {
77+
#if !os(Linux)
7978
do {
80-
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: false, attributes: nil)
79+
try go()
8180
} catch CocoaError.Code.fileWriteFileExists {
8281
// noop
8382
}
83+
#else
84+
do {
85+
try go()
86+
} catch {
87+
let error = error as NSError
88+
guard error.domain == NSCocoaErrorDomain, error.code == CocoaError.Code.fileWriteFileExists.rawValue else {
89+
throw error
90+
}
91+
}
92+
#endif
93+
}
94+
95+
@discardableResult
96+
public func mkdir() throws -> Path {
97+
try _foo {
98+
try FileManager.default.createDirectory(at: self.url, withIntermediateDirectories: false, attributes: nil)
99+
}
84100
return self
85101
}
86102

87-
@inlinable
88103
@discardableResult
89104
public func mkpath() throws -> Path {
90-
do {
105+
try _foo {
91106
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
92-
} catch CocoaError.Code.fileWriteFileExists {
93-
// noop
94107
}
95108
return self
96109
}

Sources/TemporaryDirectory.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class TemporaryDirectory {
55
public var path: Path { return Path(string: url.path) }
66

77
public init() throws {
8-
#if os(macOS)
8+
#if !os(Linux)
99
url = try FileManager.default.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: "/"), create: true)
1010
#else
1111
let envs = ProcessInfo.processInfo.environment

Tests/PathTests/PathTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ class PathTests: XCTestCase {
3737

3838
func testExists() {
3939
XCTAssert(Path.root.exists)
40-
XCTAssert((Path.root/"Users").exists)
40+
XCTAssert((Path.root/"bin").exists)
4141
}
4242

4343
func testIsDirectory() {
4444
XCTAssert(Path.root.isDirectory)
45-
XCTAssert((Path.root/"Users").isDirectory)
45+
XCTAssert((Path.root/"bin").isDirectory)
4646
}
4747

4848
func testMktemp() throws {

Tests/PathTests/XCTestManifests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension PathTests {
1515
]
1616
}
1717

18-
#if !os(macOS)
18+
#if os(Linux)
1919
public func __allTests() -> [XCTestCaseEntry] {
2020
return [
2121
testCase(PathTests.__allTests),

0 commit comments

Comments
 (0)