Skip to content

Updated to Swift 5.1 and fixed deprecations #46

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.2
// swift-tools-version:5.1

/**
* ShellOut
Expand Down
22 changes: 10 additions & 12 deletions Sources/ShellOut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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()

Expand All @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions Tests/ShellOutTests/ShellOutTests+Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
Expand Down
4 changes: 2 additions & 2 deletions Tests/ShellOutTests/ShellOutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down