mod common;
use common::Repo;
use std::process::Command;
fn run(r: &Repo, args: &[&str]) -> String {
let out = Command::new(env!("CARGO_BIN_EXE_amont"))
.args(args)
.current_dir(&r.dir)
.env("NO_COLOR", "1")
.output()
.expect("run amont");
let mut s = String::from_utf8_lossy(&out.stdout).into_owned();
s.push_str(&String::from_utf8_lossy(&out.stderr));
s
}
fn concealing_manifest() -> String {
format!(
"pre-commit first * block /bin/true\n\
pre-commit {}hidden * block /bin/true\n\
pre-commit third * block /bin/true\n",
"\u{1b}[8m"
)
}
#[test]
fn a_declaration_cannot_conceal_the_next_one_from_the_trust_prompt() {
let r = Repo::new();
r.stage("x.txt", "seed\n");
r.commit("chore: seed");
r.stage("amont.conf", &concealing_manifest());
let shown = run(&r, &["trust", "--show"]);
assert!(
!shown.contains('\u{1b}'),
"an escape byte from the manifest reached the terminal: {shown:?}"
);
for name in ["first", "hidden", "third"] {
assert!(
shown.contains(name),
"declaration {name:?} is missing from the listing:\n{shown}"
);
}
}
#[test]
fn the_check_listing_does_not_pass_escapes_through_either() {
let r = Repo::new();
r.stage("x.txt", "seed\n");
r.commit("chore: seed");
r.stage("amont.conf", &concealing_manifest());
let shown = run(&r, &["list"]);
assert!(
!shown.contains('\u{1b}'),
"an escape byte from the manifest reached the terminal: {shown:?}"
);
}
#[test]
fn a_parse_error_does_not_carry_the_manifests_escapes() {
let r = Repo::new();
r.stage("x.txt", "seed\n");
r.commit("chore: seed");
r.stage(
"amont.conf",
&format!("pre-commit bad * {}nonsense /bin/true\n", "\u{1b}[8m"),
);
let shown = run(&r, &["trust", "--show"]);
assert!(
!shown.contains('\u{1b}'),
"an escape byte reached the terminal through an error: {shown:?}"
);
}