Template support for input parameters #4

Merged
javier merged 81 commits from feature/arguments-templating into main 2025-02-17 22:11:06 +00:00
2 changed files with 71 additions and 3 deletions
Showing only changes of commit 36f1b8fe5c - Show all commits

View File

@ -60,7 +60,7 @@ struct RunProcessTask {
} catch let error as RunProcessError {
throw error
} catch {
throw RunProcessError.captured(error)
throw RunProcessError.captured(error.localizedDescription)
}
}
@ -68,8 +68,8 @@ struct RunProcessTask {
// MARK: - Errors
public enum RunProcessError: Error {
case captured(_ error: Error)
public enum RunProcessError: Error, Equatable {
case captured(_ output: String)
case output(_ output: String)
case unexpected
}

View File

@ -0,0 +1,68 @@
import Foundation
import Testing
@testable import ColibriLibrary
struct RunProcessTaskTests {
// MARK: Properties
private var process: Process
// MARK: Initialisers
init() {
self.process = Process()
}
// MARK: Functions tests
@Test(arguments: [Argument.empty, Argument.listAllInFolder])
func run(with arguments: [String]) async throws {
// GIVEN
var task = RunProcessTask(process: process)
// WHEN
let output = try await task(path: .ls, arguments: arguments)
// THEN
#expect(output.isEmpty == false)
}
@Test(arguments: zip([Argument.help, Argument.listAllInPWD], Throw.outputs))
func runThrows(with arguments: [String], throws error: RunProcessError) async throws {
// GIVEN
var task = RunProcessTask(process: process)
// WHEN
// THEN
await #expect(throws: error) {
try await task(path: .ls, arguments: arguments)
}
}
}
// MARK: - String+Constants
private extension String {
static let ls = "/bin/ls"
}
// MARK: - Parameters
private extension RunProcessTaskTests {
enum Argument {
static let empty: [String] = []
static let help: [String] = ["--help"]
static let listAllInFolder: [String] = ["-la", "."]
static let listAllInPWD: [String] = ["-la", "~"]
}
enum Throw {
static let outputs: [RunProcessError] = [
.output("ls: unrecognized option `--help\'\nusage: ls [-@ABCFGHILOPRSTUWXabcdefghiklmnopqrstuvwxy1%,] [--color=when] [-D format] [file ...]\n"),
.output("ls: ~: No such file or directory\n")
]
}
}