From 886302f86aec4b4ca9c76a8c1871d249de2ad15a Mon Sep 17 00:00:00 2001 From: John Sundell Date: Wed, 7 Jun 2017 22:25:26 +0200 Subject: [PATCH 1/6] Add Linux CI using Travis --- .swift-version | 1 + .travis.yml | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 .swift-version create mode 100644 .travis.yml diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..8c50098 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +3.1 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..06f52f3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +os: linux +language: generic +sudo: required +dist: trusty +install: + - eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)" +script: + - swift test From ce2318ff4ed2307a5196c70fd69ebac20776960d Mon Sep 17 00:00:00 2001 From: John Sundell Date: Wed, 7 Jun 2017 22:25:48 +0200 Subject: [PATCH 2/6] Run all relevant tests on Linux --- Tests/ShellOutTests/ShellOutTests+Linux.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/ShellOutTests/ShellOutTests+Linux.swift b/Tests/ShellOutTests/ShellOutTests+Linux.swift index fef0b31..aee786d 100644 --- a/Tests/ShellOutTests/ShellOutTests+Linux.swift +++ b/Tests/ShellOutTests/ShellOutTests+Linux.swift @@ -13,8 +13,10 @@ extension ShellOutTests { ("testWithoutArguments", testWithoutArguments), ("testWithArguments", testWithArguments), ("testWithInlineArguments", testWithInlineArguments), - ("testThrowingError", testThrowingError), - ("testRedirection", testRedirection) + ("testSingleCommandAtPath", testSingleCommandAtPath), + ("testSeriesOfCommands", testSeriesOfCommands), + ("testSeriesOfCommandsAtPath", testSeriesOfCommandsAtPath), + ("testThrowingError", testThrowingError) ] } #endif From d18b7b6bd27873d00199d7c66e4e6ae8f18cd699 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Wed, 7 Jun 2017 22:26:19 +0200 Subject: [PATCH 3/6] Only support custom output/error handles on macOS Attaching handlers to FileHandles is not yet supported in the standard library on Linux. --- Sources/ShellOut.swift | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Sources/ShellOut.swift b/Sources/ShellOut.swift index 528a40c..83ee592 100644 --- a/Sources/ShellOut.swift +++ b/Sources/ShellOut.swift @@ -15,7 +15,9 @@ import Foundation * - parameter arguments: The arguments to pass to the command * - parameter path: The path to execute the commands at (defaults to current folder) * - parameter outputHandle: Any `FileHandle` that any output (STDOUT) should be redirected to + * (at the moment this is only supported on macOS) * - parameter errorHandle: Any `FileHandle` that any error output (STDERR) should be redirected to + * (at the moment this is only supported on macOS) * * - returns: The output of running the command * - throws: `ShellOutError` in case the command couldn't be performed, or it returned an error @@ -39,7 +41,9 @@ import Foundation * - parameter commands: The commands to run * - parameter path: The path to execute the commands at (defaults to current folder) * - parameter outputHandle: Any `FileHandle` that any output (STDOUT) should be redirected to + * (at the moment this is only supported on macOS) * - parameter errorHandle: Any `FileHandle` that any error output (STDERR) should be redirected to + * (at the moment this is only supported on macOS) * * - returns: The output of running the command * - throws: `ShellOutError` in case the command couldn't be performed, or it returned an error @@ -79,25 +83,25 @@ private extension Process { var outputData = Data() var errorData = Data() - let stdoutHandler: (FileHandle) -> Void = { handler in + let outputPipe = Pipe() + standardOutput = outputPipe + + let errorPipe = Pipe() + standardError = errorPipe + + #if !os(Linux) + outputPipe.fileHandleForReading.readabilityHandler = { handler in let data = handler.availableData outputData.append(data) outputHandle?.write(data) } - let stderrHandler: (FileHandle) -> Void = { handler in + errorPipe.fileHandleForReading.readabilityHandler = { handler in let data = handler.availableData errorData.append(data) errorHandle?.write(data) } - - let outputPipe = Pipe() - standardOutput = outputPipe - outputPipe.fileHandleForReading.readabilityHandler = stdoutHandler - - let errorPipe = Pipe() - standardError = errorPipe - errorPipe.fileHandleForReading.readabilityHandler = stderrHandler + #endif launch() waitUntilExit() From 8c959f57229326d8dfc5b0e15cc3740bf8178c99 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Wed, 7 Jun 2017 22:29:36 +0200 Subject: [PATCH 4/6] Linux: Strip out nil assignment to readability handlers --- Sources/ShellOut.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/ShellOut.swift b/Sources/ShellOut.swift index 83ee592..2c1703d 100644 --- a/Sources/ShellOut.swift +++ b/Sources/ShellOut.swift @@ -109,8 +109,10 @@ private extension Process { outputHandle?.closeFile() errorHandle?.closeFile() + #if !os(Linux) outputPipe.fileHandleForReading.readabilityHandler = nil errorPipe.fileHandleForReading.readabilityHandler = nil + #endif if terminationStatus != 0 { throw ShellOutError( From 58ae4789c0d5c20de9db0795f8ee2622298ef4be Mon Sep 17 00:00:00 2001 From: John Sundell Date: Mon, 28 Aug 2017 23:08:03 +0200 Subject: [PATCH 5/6] Linux: Read output/error data by reading to the end of file Since readability handlers are not available yet on Linux --- Sources/ShellOut.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/ShellOut.swift b/Sources/ShellOut.swift index b6a2df5..6cee545 100644 --- a/Sources/ShellOut.swift +++ b/Sources/ShellOut.swift @@ -340,6 +340,12 @@ private extension Process { #endif launch() + + #if os(Linux) + outputData = outputPipe.fileHandleForReading.readDataToEndOfFile() + errorData = errorPipe.fileHandleForReading.readDataToEndOfFile() + #endif + waitUntilExit() outputHandle?.closeFile() From 9f17ef0f687473dc64b995ce4610454e1f64530c Mon Sep 17 00:00:00 2001 From: John Sundell Date: Mon, 28 Aug 2017 23:11:38 +0200 Subject: [PATCH 6/6] Linux: Run tests for pre-defined commands --- Tests/ShellOutTests/ShellOutTests+Linux.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/ShellOutTests/ShellOutTests+Linux.swift b/Tests/ShellOutTests/ShellOutTests+Linux.swift index aee786d..508ad34 100644 --- a/Tests/ShellOutTests/ShellOutTests+Linux.swift +++ b/Tests/ShellOutTests/ShellOutTests+Linux.swift @@ -16,7 +16,9 @@ extension ShellOutTests { ("testSingleCommandAtPath", testSingleCommandAtPath), ("testSeriesOfCommands", testSeriesOfCommands), ("testSeriesOfCommandsAtPath", testSeriesOfCommandsAtPath), - ("testThrowingError", testThrowingError) + ("testThrowingError", testThrowingError), + ("testGitCommands", testGitCommands), + ("testSwiftPackageManagerCommands", testSwiftPackageManagerCommands) ] } #endif