diff --git a/Package.swift b/Package.swift index 8a29037..5543c35 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.2 +// swift-tools-version:5.1 /** * ShellOut diff --git a/Sources/ShellOut.swift b/Sources/ShellOut.swift index fc60261..9fa6d67 100644 --- a/Sources/ShellOut.swift +++ b/Sources/ShellOut.swift @@ -376,7 +376,12 @@ extension ShellOutError: LocalizedError { private extension Process { @discardableResult func launchBash(with command: String, outputHandle: FileHandle? = nil, errorHandle: FileHandle? = nil) throws -> String { - launchPath = "/bin/bash" + + if #available(OSX 10.13, *) { + executableURL = URL(fileURLWithPath: "/bin/bash") + } else { + launchPath = "/bin/bash" + } arguments = ["-c", command] // Because FileHandle's readabilityHandler might be called from a @@ -394,7 +399,6 @@ private extension Process { let errorPipe = Pipe() standardError = errorPipe - #if !os(Linux) outputPipe.fileHandleForReading.readabilityHandler = { handler in let data = handler.availableData outputQueue.async { @@ -410,16 +414,12 @@ private extension Process { errorHandle?.write(data) } } - #endif - - launch() - #if os(Linux) - outputQueue.sync { - outputData = outputPipe.fileHandleForReading.readDataToEndOfFile() - errorData = errorPipe.fileHandleForReading.readDataToEndOfFile() + if #available(OSX 10.13, *) { + try run() + } else { + launch() } - #endif waitUntilExit() @@ -431,10 +431,8 @@ private extension Process { handle.closeFile() } - #if !os(Linux) outputPipe.fileHandleForReading.readabilityHandler = nil errorPipe.fileHandleForReading.readabilityHandler = nil - #endif // Block until all writes have occurred to outputData and errorData, // and then read the data back out. diff --git a/Tests/ShellOutTests/ShellOutTests+Linux.swift b/Tests/ShellOutTests/ShellOutTests+Linux.swift index 508ad34..f237aca 100644 --- a/Tests/ShellOutTests/ShellOutTests+Linux.swift +++ b/Tests/ShellOutTests/ShellOutTests+Linux.swift @@ -14,9 +14,14 @@ extension ShellOutTests { ("testWithArguments", testWithArguments), ("testWithInlineArguments", testWithInlineArguments), ("testSingleCommandAtPath", testSingleCommandAtPath), + ("testSingleCommandAtPathContainingSpace", testSingleCommandAtPathContainingSpace), + ("testSingleCommandAtPathContainingTilde", testSingleCommandAtPathContainingTilde), ("testSeriesOfCommands", testSeriesOfCommands), ("testSeriesOfCommandsAtPath", testSeriesOfCommandsAtPath), ("testThrowingError", testThrowingError), + ("testErrorDescription", testErrorDescription), + ("testCapturingOutputWithHandle", testCapturingOutputWithHandle), + ("testCapturingErrorWithHandle", testCapturingErrorWithHandle), ("testGitCommands", testGitCommands), ("testSwiftPackageManagerCommands", testSwiftPackageManagerCommands) ] diff --git a/Tests/ShellOutTests/ShellOutTests.swift b/Tests/ShellOutTests/ShellOutTests.swift index 90a8fd3..68c00d6 100644 --- a/Tests/ShellOutTests/ShellOutTests.swift +++ b/Tests/ShellOutTests/ShellOutTests.swift @@ -41,8 +41,8 @@ class ShellOutTests: XCTestCase { } func testSingleCommandAtPathContainingTilde() throws { - let homeContents = try shellOut(to: "ls", at: "~") - XCTAssertFalse(homeContents.isEmpty) + let homeFolders = try shellOut(to: "ls", at: "~/..") + XCTAssertFalse(homeFolders.isEmpty) } func testSeriesOfCommands() throws {