const BUDGETS: &str = include_str!("../benches/budgets.rs");
#[test]
fn no_group_is_opened_without_its_control() {
let sites: Vec<(usize, &str)> = BUDGETS
.lines()
.enumerate()
.filter(|(_, l)| l.contains("benchmark_group("))
.map(|(i, l)| (i + 1, l.trim()))
.collect();
assert_eq!(
sites.len(),
1,
"benches/budgets.rs opens a criterion group somewhere other than \
`controlled_group`, so that group has no control row and its figures \
cannot be normalised against session noise (T4.3, D-090). Sites:\n{}",
sites
.iter()
.map(|(n, l)| format!(" budgets.rs:{n}: {l}"))
.collect::<Vec<_>>()
.join("\n")
);
let (line, _) = sites[0];
let ctor = BUDGETS
.lines()
.position(|l| l.starts_with("fn controlled_group"))
.expect("controlled_group must exist")
+ 1;
assert!(
line > ctor && line < ctor + 12,
"the single benchmark_group call is at line {line}, not inside \
controlled_group at line {ctor}"
);
}
#[test]
fn the_constructor_still_adds_the_row() {
let body: String = BUDGETS
.lines()
.skip_while(|l| !l.starts_with("fn controlled_group"))
.take(20)
.collect::<Vec<_>>()
.join("\n");
assert!(
body.contains("bench_function(\"control/select_1\""),
"controlled_group no longer benches a control operation, so every group \
in the file lost its T4.3 row at once:\n{body}"
);
}
#[test]
fn the_control_has_exactly_one_name() {
let names: Vec<&str> = BUDGETS
.match_indices("\"control/")
.map(|(i, _)| {
let rest = &BUDGETS[i + 1..];
&rest[..rest.find('"').unwrap()]
})
.collect();
assert!(!names.is_empty(), "no control row found at all");
assert!(
names.iter().all(|n| *n == names[0]),
"the control row is spelled more than one way: {names:?}"
);
}