Add unit tests for running commands from custom context.

This commit is contained in:
Kare Morstol
2015-10-04 19:22:23 +02:00
parent 604756f5b3
commit d4c2bbed89
+34 -1
View File
@@ -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")
}
}