use std::process::Command;
const GOLDEN: &str = "tests/golden/ecosystem_report.txt";
fn binary() -> std::path::PathBuf {
let mut p = std::env::current_exe().expect("test exe");
p.pop();
if p.ends_with("deps") {
p.pop();
}
p.join("foreguard")
}
#[test]
fn the_published_ecosystem_report_still_says_what_it_says() {
let out = Command::new(binary())
.arg("ecosystem")
.output()
.expect("run `foreguard ecosystem`");
assert!(out.status.success(), "the command failed");
let actual = String::from_utf8(out.stdout).expect("utf8");
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(GOLDEN);
let expected = std::fs::read_to_string(&path).expect("golden is checked in");
assert_eq!(
expected.trim_end(),
actual.trim_end(),
"\n\nThe ecosystem report changed.\n\
nlj.dev quotes these figures, so the site is now wrong.\n\n\
Regenerate with:\n \
cargo build && ./target/debug/foreguard ecosystem > {GOLDEN}\n\
then update the finding in mac-portfolio/src/content/projects.js in the\n\
same change.\n"
);
}
#[test]
fn the_headline_claim_holds() {
let out = Command::new(binary())
.arg("ecosystem")
.output()
.expect("run `foreguard ecosystem`");
let text = String::from_utf8(out.stdout).expect("utf8");
assert!(
text.contains("false negatives: 0."),
"a mutating tool was classified read-only:\n{text}"
);
assert!(
text.contains("81.0% of 63 scoreable tools"),
"the headline figure moved:\n{text}"
);
assert!(
text.contains("TOTAL 98"),
"the corpus size changed:\n{text}"
);
}