mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-07 21:20:07 +01:00
🏗 WIP: Even better Shell functionality
This commit is contained in:
@@ -8,19 +8,20 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
struct ShellOutput: CustomStringConvertible {
|
||||
var output: String
|
||||
var isError: Bool
|
||||
var description: String {
|
||||
return output
|
||||
struct ShellOutput {
|
||||
var out: String
|
||||
var err: String
|
||||
|
||||
var hasError: Bool {
|
||||
return err.lengthOfBytes(using: .utf8) > 0
|
||||
}
|
||||
|
||||
static func out(_ output: String) -> ShellOutput {
|
||||
return ShellOutput(output: output, isError: false)
|
||||
static func out(_ out: String?, _ err: String? = nil) -> ShellOutput {
|
||||
return ShellOutput(out: out ?? "", err: err ?? "")
|
||||
}
|
||||
|
||||
static func err(_ output: String) -> ShellOutput {
|
||||
return ShellOutput(output: output, isError: true)
|
||||
static func err(_ err: String?) -> ShellOutput {
|
||||
return ShellOutput(out: "", err: err ?? "")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,11 +103,7 @@ class SystemShell: Shellable {
|
||||
encoding: .utf8
|
||||
)!
|
||||
|
||||
if stdErr.lengthOfBytes(using: .utf8) > 0 {
|
||||
return ShellOutput(output: stdErr, isError: true)
|
||||
}
|
||||
|
||||
return ShellOutput(output: stdOut, isError: false)
|
||||
return .out(stdOut, stdErr)
|
||||
}
|
||||
|
||||
func pipe(_ command: String) async -> ShellOutput {
|
||||
|
||||
@@ -35,10 +35,11 @@ public class TestableShell: Shellable {
|
||||
|
||||
func sync(_ command: String) -> ShellOutput {
|
||||
guard let expectation = expectations[command] else {
|
||||
return ShellOutput(output: "Unexpected Command", isError: true)
|
||||
return .err("Unexpected Command")
|
||||
}
|
||||
|
||||
return ShellOutput(output: expectation.getOutputAsString(), isError: expectation.outputsToError())
|
||||
let output = expectation.getOutputAsString()
|
||||
return expectation.outputsToError() ? .err(output) : .out(output)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user