Add unit tests for running commands from custom context.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
import XCTest
|
||||
import SwiftShell
|
||||
|
||||
class Context_Tests: XCTestCase {
|
||||
class MainContext_Tests: XCTestCase {
|
||||
|
||||
func testCurrentDirectory_IsCurrentDirectory () {
|
||||
XCTAssertEqual( main.currentdirectory, NSFileManager.defaultManager().currentDirectoryPath )
|
||||
@@ -22,6 +22,9 @@ class Context_Tests: XCTestCase {
|
||||
XCTAssertEqual( main.run("/bin/pwd"), "/tmp" )
|
||||
XCTAssertEqual( main.currentdirectory, NSFileManager.defaultManager().currentDirectoryPath )
|
||||
}
|
||||
}
|
||||
|
||||
class ShellContext_Tests: XCTestCase {
|
||||
|
||||
func testBlankShellContext () {
|
||||
let context = ShellContext()
|
||||
@@ -34,4 +37,34 @@ class Context_Tests: XCTestCase {
|
||||
|
||||
XCTAssert( context.stdin === main.stdin )
|
||||
}
|
||||
|
||||
func testRunCommand () {
|
||||
let context = ShellContext()
|
||||
|
||||
XCTAssertEqual(context.run("echo", "one"), "one")
|
||||
}
|
||||
|
||||
func testRunAsyncCommand () {
|
||||
let context = ShellContext()
|
||||
let task = context.runAsync("echo", "one")
|
||||
|
||||
XCTAssertEqual(task.stdout.read(), "one\n")
|
||||
}
|
||||
|
||||
func testRunAndPrintCommand () {
|
||||
var context = ShellContext()
|
||||
|
||||
AssertNoThrow {
|
||||
try context.runAndPrint("echo", "one") // sent to null
|
||||
}
|
||||
|
||||
let outputpipe = NSPipe()
|
||||
context.stdout = outputpipe.fileHandleForWriting
|
||||
let output = outputpipe.fileHandleForReading
|
||||
|
||||
AssertNoThrow {
|
||||
try context.runAndPrint("echo", "two")
|
||||
}
|
||||
XCTAssertEqual(output.readSome(), "two\n")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user