Make AsyncShellTask.finish return self.
For method chaining.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user