repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

build(xtask): cargo x mutants on demand with disk-backed scratch and nextest mutants profile

a17c74e0d65cef854f077d68a38bdb5a77b62b8a

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (3)

+69 / −2 text lines

Diff layout

.config/nextest.toml

Modified

+8 / −0 text lines

1919[profile.thorough]
2020retries = 1
2121slow-timeout = "120s"
23# Selected by cargo-mutants via additional_cargo_test_args.
24# Mutant detection: a failure is the signal; retries and slow timeouts
25# would mask exactly what mutation testing measures.
26[profile.mutants]
27retries = 0
28fail-fast = true
29slow-timeout = "30s"

Cargo.toml

Modified

+7 / −0 text lines

9595criterion = { version = "0.5", features = ["async_tokio"] }
9696tokio = { version = "1", features = ["full"] } # dev-only until an explicit runtime decision
98# Mutation-testing profile: lean debug build, many rebuilds.
99[profile.mutants]
100inherits = "test"
101debug = "none"
102strip = "debuginfo"
98104[profile.release]
99105opt-level = 3
100106lto = "thin"
105111[profile.release.package."*"]
106112opt-level = 3

xtask/src/main.rs

Modified

+54 / −2 text lines

1818};
2020const HELP: &str = concat!(
21 "usage: cargo x <check|lint|fmt|test|doc|arch|audit|bootstrap>\n",
21 "usage: cargo x <check|lint|fmt|test|doc|arch|mutants|audit|bootstrap>\n",
2222 " cargo x dev [args...] build and launch the dev smith binary\n",
2323);
3030const MACHETE_VERSION: &str = "0.9.2";
3131const DENY_VERSION: &str = "0.20.2";
3232const AUDIT_VERSION: &str = "0.22.2";
33const MUTANTS_VERSION: &str = "27.1.0";
3334const CRATES: &[&str] = &[
3435 "smith",
3536 "smith-core",
6263 Some("test") => cargo_nextest(),
6364 Some("doc") => cargo(&["doc", "--workspace", "--no-deps"]),
6465 Some("arch") => arch(),
66 Some("mutants") => cargo_mutants(),
6567 Some("audit") => audit(),
6668 Some("bootstrap") => bootstrap(),
6769 _ => fail(HELP),
100102 sequence(&[install_deny, install_audit, cargo_deny, cargo_audit])
105/// Mutation testing runs on demand, never in the blocking check chain.
106///
107/// Scratch lives under `target/mutants-tmp` on disk: the system tmpfs is
108/// 16G of RAM and tree copies would crawl the machine. Jobs stay low for
109/// the same reason. The baseline test run is skipped because `cargo x
110/// check` owns test verification.
111fn cargo_mutants() -> ExitCode {
112 let installed = tool_present_bin("cargo-mutants", MUTANTS_VERSION, || {
113 cargo(&[
114 "binstall",
115 "--no-confirm",
116 &format!("cargo-mutants@{MUTANTS_VERSION}"),
117 ])
118 });
119 if installed != ExitCode::SUCCESS {
120 return installed;
121 }
122 let scratch = target_dir().join("mutants-tmp");
123 if std::fs::create_dir_all(&scratch).is_err() {
124 return fail("cannot create target/mutants-tmp\n");
125 }
126 match Command::new("cargo")
127 .env("TMPDIR", &scratch)
128 .args([
129 "mutants",
130 "--jobs",
131 "4",
132 "--baseline",
133 "skip",
134 "--no-shuffle",
135 ])
136 .status()
137 {
138 Ok(status) if status.success() => ExitCode::SUCCESS,
139 Ok(status) => fail(&format!("cargo mutants exited with {status}\n")),
140 Err(error) => fail(&format!("failed to run cargo mutants: {error}\n")),
141 }
142}
103144fn cargo_fmt() -> ExitCode {
104145 cargo(&["fmt", "--check"])
195236/// `cargo-nextest` arrives as a prebuilt binary through `cargo-binstall`.
196237/// The step is idempotent.
197238fn bootstrap() -> ExitCode {
198 let steps: [Step; 5] = [
239 let steps: [Step; 6] = [
199240 install_binstall,
200241 install_nextest,
201242 install_machete,
202243 install_deny,
203244 install_audit,
245 install_mutants,
204246 ];
205247 sequence(&steps)
237279 })
282fn install_mutants() -> ExitCode {
283 tool_present_bin("cargo-mutants", MUTANTS_VERSION, || {
284 cargo(&[
285 "binstall",
286 "--no-confirm",
287 &format!("cargo-mutants@{MUTANTS_VERSION}"),
288 ])
289 })
290}
240292fn install_binstall() -> ExitCode {
241293 tool_present_bin("cargo-binstall", BINSTALL_VERSION, || {
242294 cargo(&[