mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
🏗 Ensure Shellable has PATH
This commit is contained in:
@ -32,4 +32,10 @@ class FakeShellTest: XCTestCase {
|
||||
|
||||
XCTAssertEqual("Hello world\nGoodbye world", output.out)
|
||||
}
|
||||
|
||||
func test_fake_shell_has_path() {
|
||||
ActiveShell.useTestable([:])
|
||||
|
||||
XCTAssertEqual(Shell.PATH, "/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin")
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class WarningManager {
|
||||
public let evaluations: [Warning] = [
|
||||
Warning(
|
||||
command: {
|
||||
return LegacyShell.pipe("sysctl -n sysctl.proc_translated")
|
||||
return await Shell.pipe("sysctl -n sysctl.proc_translated").out
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines) == "1"
|
||||
},
|
||||
name: "Running PHP Monitor with Rosetta on M1",
|
||||
@ -32,7 +32,7 @@ class WarningManager {
|
||||
),
|
||||
Warning(
|
||||
command: {
|
||||
return !LegacyShell.user.PATH.contains("\(Paths.homePath)/.config/phpmon/bin") &&
|
||||
return !Shell.PATH.contains("\(Paths.homePath)/.config/phpmon/bin") &&
|
||||
!FileManager.default.isWritableFile(atPath: "/usr/local/bin/")
|
||||
},
|
||||
name: "Helpers cannot be symlinked and not in PATH",
|
||||
|
@ -30,9 +30,19 @@ struct ShellOutput {
|
||||
}
|
||||
|
||||
protocol Shellable {
|
||||
/**
|
||||
The PATH for the current shell.
|
||||
*/
|
||||
var PATH: String { get }
|
||||
|
||||
/**
|
||||
Run a command asynchronously.
|
||||
Returns the most relevant output (prefers error output if it exists).
|
||||
|
||||
Common usage:
|
||||
```
|
||||
let output = await Shell.pipe("php -v")
|
||||
```
|
||||
*/
|
||||
func pipe(_ command: String) async -> ShellOutput
|
||||
|
||||
|
@ -9,13 +9,15 @@
|
||||
import Foundation
|
||||
|
||||
public class TestableShell: Shellable {
|
||||
public typealias Input = String
|
||||
var PATH: String {
|
||||
return "/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin"
|
||||
}
|
||||
|
||||
init(expectations: [Input: BatchFakeShellOutput]) {
|
||||
init(expectations: [String: BatchFakeShellOutput]) {
|
||||
self.expectations = expectations
|
||||
}
|
||||
|
||||
var expectations: [Input: BatchFakeShellOutput] = [:]
|
||||
var expectations: [String: BatchFakeShellOutput] = [:]
|
||||
|
||||
func quiet(_ command: String) async {
|
||||
_ = try! await self.attach(command, didReceiveOutput: { _, _ in }, withTimeout: 60)
|
||||
|
Reference in New Issue
Block a user