Fix tests on Linux
This commit is contained in:
@@ -4,6 +4,8 @@ A file-system pathing library focused on developer experience and robust
|
|||||||
end‐results.
|
end‐results.
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
|
import Path
|
||||||
|
|
||||||
// convenient static members
|
// convenient static members
|
||||||
let home = Path.home
|
let home = Path.home
|
||||||
|
|
||||||
@@ -26,7 +28,7 @@ try Path.root.join("foo").copy(into: Path.root.mkdir("bar"))
|
|||||||
// were meant to be directory destinations
|
// were meant to be directory destinations
|
||||||
```
|
```
|
||||||
|
|
||||||
Paths are just string representations, there *may not* be a real file there.
|
Paths are just string representations, there *might not* be a real file there.
|
||||||
|
|
||||||
# Support mxcl
|
# Support mxcl
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public extension Data {
|
|||||||
func write(to: Path, atomically: Bool = false) throws -> Path {
|
func write(to: Path, atomically: Bool = false) throws -> Path {
|
||||||
let opts: NSData.WritingOptions
|
let opts: NSData.WritingOptions
|
||||||
if atomically {
|
if atomically {
|
||||||
#if os(macOS)
|
#if !os(Linux)
|
||||||
opts = .atomicWrite
|
opts = .atomicWrite
|
||||||
#else
|
#else
|
||||||
opts = .atomic
|
opts = .atomic
|
||||||
|
|||||||
@@ -73,24 +73,37 @@ public extension Path {
|
|||||||
return try "".write(to: self)
|
return try "".write(to: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@inlinable
|
private func _foo(go: () throws -> Void) throws {
|
||||||
@discardableResult
|
#if !os(Linux)
|
||||||
public func mkdir() throws -> Path {
|
|
||||||
do {
|
do {
|
||||||
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: false, attributes: nil)
|
try go()
|
||||||
} catch CocoaError.Code.fileWriteFileExists {
|
} catch CocoaError.Code.fileWriteFileExists {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
do {
|
||||||
|
try go()
|
||||||
|
} catch {
|
||||||
|
let error = error as NSError
|
||||||
|
guard error.domain == NSCocoaErrorDomain, error.code == CocoaError.Code.fileWriteFileExists.rawValue else {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
public func mkdir() throws -> Path {
|
||||||
|
try _foo {
|
||||||
|
try FileManager.default.createDirectory(at: self.url, withIntermediateDirectories: false, attributes: nil)
|
||||||
|
}
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
@inlinable
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func mkpath() throws -> Path {
|
public func mkpath() throws -> Path {
|
||||||
do {
|
try _foo {
|
||||||
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
|
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
|
||||||
} catch CocoaError.Code.fileWriteFileExists {
|
|
||||||
// noop
|
|
||||||
}
|
}
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ public class TemporaryDirectory {
|
|||||||
public var path: Path { return Path(string: url.path) }
|
public var path: Path { return Path(string: url.path) }
|
||||||
|
|
||||||
public init() throws {
|
public init() throws {
|
||||||
#if os(macOS)
|
#if !os(Linux)
|
||||||
url = try FileManager.default.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: "/"), create: true)
|
url = try FileManager.default.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: "/"), create: true)
|
||||||
#else
|
#else
|
||||||
let envs = ProcessInfo.processInfo.environment
|
let envs = ProcessInfo.processInfo.environment
|
||||||
|
|||||||
@@ -37,12 +37,12 @@ class PathTests: XCTestCase {
|
|||||||
|
|
||||||
func testExists() {
|
func testExists() {
|
||||||
XCTAssert(Path.root.exists)
|
XCTAssert(Path.root.exists)
|
||||||
XCTAssert((Path.root/"Users").exists)
|
XCTAssert((Path.root/"bin").exists)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testIsDirectory() {
|
func testIsDirectory() {
|
||||||
XCTAssert(Path.root.isDirectory)
|
XCTAssert(Path.root.isDirectory)
|
||||||
XCTAssert((Path.root/"Users").isDirectory)
|
XCTAssert((Path.root/"bin").isDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMktemp() throws {
|
func testMktemp() throws {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ extension PathTests {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !os(macOS)
|
#if os(Linux)
|
||||||
public func __allTests() -> [XCTestCaseEntry] {
|
public func __allTests() -> [XCTestCaseEntry] {
|
||||||
return [
|
return [
|
||||||
testCase(PathTests.__allTests),
|
testCase(PathTests.__allTests),
|
||||||
|
|||||||
Reference in New Issue
Block a user