#![allow(clippy::missing_panics_doc)]
use std::path::Path;
use kawauso_process::Invocation;
use kawauso_process::invocation::Argument;
#[test]
fn arg_with_a_metacharacter_keeps_the_argument() {
let invocation = Invocation::new("ls").arg("*.rs");
assert_eq!(invocation.arguments()[0].get(), "*.rs");
}
#[test]
fn arg_with_a_space_keeps_one_argument() {
let invocation = Invocation::new("git").arg("--message=two words");
assert_eq!(invocation.arguments().len(), 1);
}
#[test]
fn arg_with_two_arguments_keeps_the_order_of_the_calls() {
let invocation = Invocation::new("git").arg("status").arg("--short");
let arguments: Vec<_> = invocation.arguments().iter().map(Argument::get).collect();
assert_eq!(arguments, vec!["status", "--short"]);
}
#[test]
fn args_with_a_collection_appends_every_argument() {
let invocation = Invocation::new("cargo")
.arg("build")
.args(["--release", "--locked"]);
assert_eq!(invocation.arguments().len(), 3);
}
#[test]
fn display_with_a_program_that_holds_a_space_marks_it() {
let invocation = Invocation::new("/opt/my tool/bin/tool");
assert_eq!(invocation.to_string(), "\"/opt/my tool/bin/tool\"");
}
#[test]
fn display_with_an_argument_that_holds_a_space_marks_it() {
let invocation = Invocation::new("sh").arg("-c").arg("echo hello world");
assert_eq!(invocation.to_string(), "sh -c \"echo hello world\"");
}
#[test]
fn display_with_arguments_names_the_program_and_every_argument() {
let invocation = Invocation::new("git").arg("status").arg("--short");
assert_eq!(invocation.to_string(), "git status --short");
}
#[test]
fn in_directory_with_a_directory_keeps_it() {
let invocation = Invocation::new("cargo").in_directory("crates/example");
assert_eq!(
invocation
.working_directory()
.map(|directory| directory.get()),
Some(Path::new("crates/example"))
);
}
#[test]
fn new_with_a_program_keeps_the_program() {
let invocation = Invocation::new("/usr/bin/git");
assert_eq!(invocation.program().get(), Path::new("/usr/bin/git"));
}
#[test]
fn new_without_a_directory_reports_no_directory() {
let invocation = Invocation::new("git").arg("status");
assert!(invocation.working_directory().is_none());
}