1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-07 05:10:06 +01:00

Add tests for RealFileSystem class

This commit is contained in:
2022-11-08 20:14:10 +01:00
parent bc739e1982
commit fa5c843619
3 changed files with 88 additions and 10 deletions

View File

@@ -61,7 +61,7 @@ class RealFileSystem: FileSystemProtocol {
// MARK: FS Attributes
func makeExecutable(_ path: String) throws {
system("chmod +x \(path.replacingTildeWithHomeDirectory)")
_ = system("chmod +x \(path.replacingTildeWithHomeDirectory)")
}
// MARK: - Checks
@@ -69,6 +69,8 @@ class RealFileSystem: FileSystemProtocol {
func isExecutableFile(_ path: String) -> Bool {
return FileManager.default.isExecutableFile(
atPath: path.replacingTildeWithHomeDirectory
) && FileManager.default.isReadableFile(
atPath: path.replacingTildeWithHomeDirectory
)
}

View File

@@ -8,11 +8,21 @@
import Foundation
public func system(_ command: String) {
let argsArray = command.split(separator: " ").map { String($0) }
guard argsArray.isEmpty else { return }
let command = strdup(argsArray.first!)
let args = argsArray.map { strdup($0) } + [nil]
posix_spawn(nil, command, nil, nil, args, nil)
return
/**
Run a simple blocking Shell command on the user's own system.
Avoid using this method in favor of the fakeable Shell class unless needed for express system operations.
*/
public func system(_ command: String) -> String {
let task = Process()
task.launchPath = "/bin/sh"
task.arguments = ["-c", command]
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue)! as String
return output
}