Make AsyncShellTask.finish return self.

For method chaining.
This commit is contained in:
Kare Morstol
2015-09-03 18:25:28 +02:00
parent de708331a8
commit c6975aefd1
2 changed files with 11 additions and 2 deletions
+4 -2
View File
@@ -121,13 +121,15 @@ public struct AsyncShellTask {
/**
Wait for this shell task to finish.
- returns: itself
- throws: a ShellError if the return code is anything but 0.
*/
public func finish() throws {
public func finish() throws -> AsyncShellTask {
task.waitUntilExit()
if task.terminationStatus != 0 {
guard task.terminationStatus == 0 else {
throw ShellError.ReturnedErrorCode(errorcode: task.terminationStatus)
}
return self
}
}
+7
View File
@@ -50,4 +50,11 @@ class RunAsync_Tests: XCTestCase {
AssertThrows(ShellError.ReturnedErrorCode(errorcode: 1)) { try asynctask.finish() }
XCTAssertEqual( asynctask.stderror.read(), "errormessage\n" )
}
func testFinishReturnsSelf () {
AssertNoThrow {
let output = try main.runAsync(bash: "echo hi").finish().stdout.read()
XCTAssertEqual(output, "hi\n")
}
}
}