repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

fix cargo x mutants

2649cbc4c33eb62c3aa5d04375f4a35433c118ee

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

+29 / −16 text lines

Diff layout

xtask/src/main.rs

Modified

+29 / −16 text lines

1818};
2020const HELP: &str = concat!(
21 "usage: cargo x <check|lint|fmt|test|doc|arch|mutants|audit|bootstrap>\n",
21 "usage: cargo x <check|lint|fmt|test|doc|arch|mutants [args...]|audit|bootstrap>\n",
2222 " cargo x dev [args...] build and launch the dev smith binary\n",
2323);
5353 if command.to_str() == Some("dev") {
5454 return dev(&rest);
5555 }
56 if command.to_str() == Some("mutants") {
57 return cargo_mutants(&rest);
58 }
5659 if !rest.is_empty() {
5760 return fail("xtask accepts exactly one command\n");
5861 }
6366 Some("test") => cargo_nextest(),
6467 Some("doc") => cargo(&["doc", "--workspace", "--no-deps"]),
6568 Some("arch") => arch(),
66 Some("mutants") => cargo_mutants(),
6769 Some("audit") => audit(),
6870 Some("bootstrap") => bootstrap(),
6971 _ => fail(HELP),
111113/// 16G RAM and tree copies crawl the machine), a modest default job
112114/// count overridable through `CARGO_MUTANTS_JOBS`, and a skipped
113115/// baseline because `cargo x check` owns test verification.
114fn cargo_mutants() -> ExitCode {
116fn cargo_mutants(extra: &[OsString]) -> ExitCode {
115117 let installed = tool_present_bin("cargo-mutants", MUTANTS_VERSION, || {
116118 cargo(&[
117119 "binstall",
126128 if std::fs::create_dir_all(&scratch).is_err() {
127129 return fail("cannot create target/mutants-tmp\n");
128130 }
129 let jobs = std::env::var("CARGO_MUTANTS_JOBS").unwrap_or_else(|_| "4".to_string());
130 match Command::new("cargo")
131 .env("TMPDIR", &scratch)
132 .args([
133 "mutants",
134 "--jobs",
135 &jobs,
136 "--baseline",
137 "skip",
138 "--no-shuffle",
139 ])
140 .status()
141 {
131 let jobs = std::env::var("CARGO_MUTANTS_JOBS").unwrap_or_else(|_| "1".to_string());
132 // `cargo x mutants -- -f x` and `cargo x mutants -f x` are equivalent:
133 // a leading separator is stripped so cargo-run habits cannot turn
134 // scope flags into stray nextest test filters.
135 let extra: Vec<OsString> = if extra.first().is_some_and(|arg| arg == "--") {
136 extra[1..].to_vec()
137 } else {
138 extra.to_vec()
139 };
140 let mut command = Command::new("cargo-mutants");
141 command.env("TMPDIR", &scratch).args([
142 "mutants",
143 "--jobs",
144 &jobs,
145 "--baseline",
146 "skip",
147 "--no-shuffle",
148 ]);
149 // Passthrough args come last and override the defaults above.
150 command.args(extra);
151 match command.status() {
142152 Ok(status) if status.success() => ExitCode::SUCCESS,
153 Ok(status) if status.code() == Some(2) => fail(
154 "missed mutants: tests did not catch everything (see target/mutants.out/missed.txt)\n",
155 ),
143156 Ok(status) => fail(&format!("cargo mutants exited with {status}\n")),
144157 Err(error) => fail(&format!("failed to run cargo mutants: {error}\n")),
145158 }