mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-13 14:30:06 +02:00
🏗 WIP: Even better Shell functionality
This commit is contained in:
@@ -31,14 +31,18 @@ class FakeShellTest: XCTestCase {
|
||||
|
||||
XCTAssertTrue(Shell is TestableShell)
|
||||
|
||||
XCTAssertEqual(expectedPhpOutput, Shell.sync("php -v").output)
|
||||
XCTAssertEqual(expectedPhpOutput, Shell.sync("php -v").out)
|
||||
|
||||
XCTAssertEqual(expectedPhpOutput, Shell.sync("php --version").output)
|
||||
XCTAssertEqual(expectedPhpOutput, Shell.sync("php --version").out)
|
||||
}
|
||||
|
||||
func test_unrecognized_commands_output_stderr() {
|
||||
ActiveShell.useTestable([:])
|
||||
|
||||
XCTAssertEqual("Unexpected Command", Shell.sync("unrecognized command").output)
|
||||
let output = Shell.sync("unrecognized command")
|
||||
|
||||
XCTAssertTrue(output.hasError)
|
||||
XCTAssertEqual("Unexpected Command", output.err)
|
||||
XCTAssertEqual("", output.out)
|
||||
}
|
||||
}
|
||||
|
@@ -9,10 +9,16 @@
|
||||
import XCTest
|
||||
|
||||
class SystemShellTest: XCTestCase {
|
||||
|
||||
override class func setUp() {
|
||||
// Reset to the default shell
|
||||
ActiveShell.useSystem()
|
||||
}
|
||||
|
||||
func test_system_shell_is_default() {
|
||||
XCTAssertTrue(Shell is SystemShell)
|
||||
|
||||
XCTAssertTrue(Shell.sync("php -v").output.contains("Copyright (c) The PHP Group"))
|
||||
XCTAssertTrue(Shell.sync("php -v").out.contains("Copyright (c) The PHP Group"))
|
||||
}
|
||||
|
||||
func test_system_shell_has_path() {
|
||||
@@ -28,14 +34,14 @@ class SystemShellTest: XCTestCase {
|
||||
let shellOutput = try! await Shell.attach(
|
||||
"php -r \"echo 'Hello world' . PHP_EOL; usleep(200); echo 'Goodbye world';\"",
|
||||
didReceiveOutput: { incoming in
|
||||
bits.append(incoming.output)
|
||||
bits.append(incoming.out)
|
||||
},
|
||||
withTimeout: 2.0
|
||||
)
|
||||
|
||||
XCTAssertTrue(bits.contains("Hello world\n"))
|
||||
XCTAssertTrue(bits.contains("Goodbye world"))
|
||||
XCTAssertEqual("Hello world\nGoodbye world", shellOutput.output)
|
||||
XCTAssertEqual("Hello world\nGoodbye world", shellOutput.out)
|
||||
}
|
||||
|
||||
func test_system_shell_can_timeout_and_throw_error() async {
|
||||
@@ -52,6 +58,6 @@ class SystemShellTest: XCTestCase {
|
||||
expectation.fulfill()
|
||||
}
|
||||
|
||||
wait(for: [expectation], timeout: 3.0)
|
||||
wait(for: [expectation], timeout: 5.0)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user