1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Integration tests for the Rust mutation rule (#201).
//!
//! These run REAL `cargo mutants` over the fixture crates via the SDK
//! ([`mutation::measure_rust`]) and assert the surviving-mutant set. Per the #3
//! guardrail the *crates themselves* are the fixtures: `killed` (every mutant caught
//! by an asserting test) reports no survivors, and `survivors` (an assertion-light
//! test that runs the code but pins nothing) reports several — the gap mutation
//! testing exposes that coverage can't. Requires only a cargo toolchain — the tool
//! provisions cargo-mutants itself (#242).
use std::path::PathBuf;
use testing_conventions::mutation::measure_rust;
fn crate_dir(name: &str) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/unit_mutation/rust")
.join(name)
}
#[test]
fn killed_reports_no_survivors() {
let survivors = measure_rust(
&crate_dir("killed"),
&[],
&std::collections::BTreeMap::new(),
None,
&[],
)
.expect("cargo-mutants runs");
assert!(
survivors.is_empty(),
"every mutant should be caught; got {survivors:?}"
);
}
#[test]
fn survivors_are_reported() {
let survivors = measure_rust(
&crate_dir("survivors"),
&[],
&std::collections::BTreeMap::new(),
None,
&[],
)
.expect("cargo-mutants runs");
assert!(
!survivors.is_empty(),
"the assertion-light suite should leave survivors"
);
assert!(
survivors.iter().all(|m| m.file == "src/lib.rs"),
"every survivor is in src/lib.rs; got {survivors:?}"
);
}
#[test]
fn a_mutation_exemption_drops_the_survivors() {
// Exempting the survivors' file lifts all of them — an equivalent / deliberately
// defensive mutation, waived with a reason via `[[rust.exempt]] rules = ["mutation"]`.
let exempt = vec!["src/lib.rs".to_string()];
let survivors = measure_rust(
&crate_dir("survivors"),
&exempt,
&std::collections::BTreeMap::new(),
None,
&[],
)
.expect("cargo-mutants runs");
assert!(
survivors.is_empty(),
"the exemption should drop every survivor; got {survivors:?}"
);
}