requirements.test-coverage.index.file_map.minimum.descendants
Requirements index · View definition
Example
A map lists
src/a.rswith 1 of 2 instrumented lines covered,src/nested/b.rswith 1 of 4 covered, andsrc/nested/c.rsas not measured. Both thesrcandsrc/nestedgroups show a minimum measured file coverage of 25% and one not-measured file, including while collapsed.![]()
Rationale
The example is concrete. It gives three files: src/a.rs at 1/2, src/nested/b.rs at 1/4, and src/nested/c.rs not measured. It expects both the src and src/nested groups to show a 25% minimum and one not-measured file, including while collapsed.
The test src/execution_coverage/book.rs#mod[tests]/fn[directory_minima_use_exact_fractions_and_count_unmeasured_descendants] is marked {test} for the example’s requirements. It renders exactly this scenario through gaps_map, using (1,2), (1,4) and (0,0) for the three files. It checks the outcomes as follows:
- Both groups. A loop over
srcandsrc/nestedasserts that the summary contains “Minimum measured file coverage:”, “25.0%” and “1 not measured”. It also asserts that the summary does not contain “0 unavailable” or “2 not measured”. The negative checks rule out countingsrc/a.rsor the measuredb.rsas not measured, and also an unavailable-style label. - Descendant counting.
assert_directory_contentsconfirms the nesting.srcholds the childsrc/nestedand the filea.rs.src/nestedholdsb.rsandc.rs. Sosrcreports the nested descendants without double counting. - Collapsed state. The test builds a copy of the map with the
src/nesteddetails element’sopenattribute removed. It asserts thatsrcstays open andsrc/nestedis closed. It then asserts that thesrc/nestedgroup content after the opening tag is identical, which includes its summary. It also asserts that every file card is identical and that re-addingopenrestores the original map. The summary is static HTML inside a nativedetailselement, so collapsing changes only the attribute. The helpersdirectory_summary,directory_groupandfile_cardextract the correct regions. I read them. - Extra cases. The test also covers cases beyond the example. These include exact-fraction comparison (1001/2000 against 501/1000), all-unmeasured directories showing “No measured files” with no percentage, a measured 0/4 file showing 0.0%, per-directory descendant counts across deep and sibling directories, and unlisted empty or accepted files not inflating the count.
The only thin point is that the example scenario collapses src/nested but not src itself. The summary markup is independent of the open attribute, and the final scenario checks the same summary equality for all directories with src/nested closed. I don’t consider this a gap.
Inputs
Tests
Input 2: outline src/execution_coverage/book.rs mod[tests]/fn[directory_minima_use_exact_fractions_and_count_unmeasured_descendants]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[directory_minima_use_exact_fractions_and_count_unmeasured_descendants] - Kind:
fn src/execution_coverage/book.rs:1466–1642
// {test}`requirements.test-coverage.index.file_map.minimum`
// {test}`requirements.test-coverage.index.file_map.minimum.statuses`
// {test}`requirements.test-coverage.index.file_map.minimum.descendants`
// {test}`requirements.test-coverage.index.file_map.directories`
// {test}`requirements.test-coverage.index.file_map.directories.data`
#[test]
fn directory_minima_use_exact_fractions_and_count_unmeasured_descendants() {
let render = |files: &[(&str, usize, usize)]| {
let mut policy = super::super::check::PolicyReport {
report: super::super::check::CheckReport {
passed: false,
text: String::new(),
},
files: files
.iter()
.map(|&(file, covered, total)| super::super::check::FilePolicy {
file: file.into(),
covered,
total,
obligations: vec![super::super::check::Obligation {
selector: String::new(),
line: 1,
measurement: "below target".into(),
exception: None,
}],
})
.collect(),
counts_complete: true,
measured: true,
findings: vec![],
};
// Unlisted files with no obligations or accepted exceptions must
// not inflate the directory's not-measured count.
for (file, accepted) in [
("src/nested/hidden-empty.rs", false),
("src/nested/hidden-accepted.rs", true),
] {
policy.files.push(super::super::check::FilePolicy {
file: file.into(),
covered: 0,
total: 0,
obligations: if accepted {
vec![super::super::check::Obligation {
selector: String::new(),
line: 1,
measurement: "not measured".into(),
exception: Some(super::super::check::Exception {
accepted: true,
review_missing: false,
justification: "No instrumented obligations.".into(),
findings: vec![],
}),
}]
} else {
vec![]
},
});
}
gaps_map(&policy, Path::new("coverage.md"), 1)
};
let map = render(&[("src/higher.rs", 501, 1000), ("src/lower.rs", 1001, 2000)]);
assert!(
directory_summary(&map, "src")
.contains("data-min-covered=\"1001\" data-min-instrumented=\"2000\"")
);
let map = render(&[
("src/a.rs", 1, 2),
("src/nested/b.rs", 1, 4),
("src/nested/c.rs", 0, 0),
]);
for directory in ["src", "src/nested"] {
let summary = directory_summary(&map, directory);
assert!(summary.contains("Minimum measured file coverage:"));
assert!(summary.contains("25.0%"));
assert!(summary.contains("1 not measured"));
assert!(!summary.contains("0 unavailable"));
assert!(!summary.contains("2 not measured"));
}
assert_directory_contents(&map, "src", &["src/nested"], &["src/a.rs"]);
assert_directory_contents(
&map,
"src/nested",
&[],
&["src/nested/b.rs", "src/nested/c.rs"],
);
// Changing one native details control only changes its open attribute;
// all file identities, measurements, summaries and sibling state remain.
let opening = "<details class=\"gap-directory\" data-directory=\"src/nested\" open>";
let closed_opening = opening.replace(" open>", ">");
let closed = map.replace(opening, &closed_opening);
assert_ne!(closed, map);
assert!(closed.contains("data-directory=\"src\" open>"));
assert!(closed.contains("data-directory=\"src/nested\">"));
assert_eq!(
directory_group(&closed, "src/nested")
.split_once('>')
.unwrap()
.1,
directory_group(&map, "src/nested")
.split_once('>')
.unwrap()
.1
);
for file in ["src/a.rs", "src/nested/b.rs", "src/nested/c.rs"] {
assert_eq!(file_card(&map, file), file_card(&closed, file));
}
assert_eq!(closed.replace(&closed_opening, opening), map);
let map = render(&[("src/unknown.rs", 0, 0)]);
let summary = directory_summary(&map, "src");
assert!(summary.contains("No measured files"));
assert!(summary.contains("1 not measured"));
assert!(!summary.contains('%'));
let map = render(&[
("src/measured-zero.rs", 0, 4),
("src/nested/unmeasured.rs", 0, 0),
]);
let summary = directory_summary(&map, "src");
assert!(summary.contains("Minimum measured file coverage:"));
assert!(summary.contains("0.0%"));
assert!(summary.contains("1 not measured"));
assert!(!summary.contains("2 not measured"));
let zero = file_card(&map, "src/measured-zero.rs");
assert!(zero.contains("data-status=\"measured\""));
assert!(zero.contains("0.0%"));
assert!(zero.contains("0/4 instrumented lines covered"));
assert!(!zero.contains("not measured"));
let nested = directory_summary(&map, "src/nested");
assert!(nested.contains("No measured files"));
assert!(nested.contains("1 not measured"));
assert!(!nested.contains('%'));
let map = render(&[
("src/direct.rs", 0, 0),
("src/nested/a.rs", 0, 0),
("src/nested/deep/b.rs", 0, 0),
("src/nested/deep/c.rs", 0, 0),
("src/sibling/d.rs", 0, 0),
("src/measured-zero.rs", 0, 4),
("src/positive.rs", 1, 4),
("src-other/outside.rs", 0, 0),
]);
for (directory, count) in [
("src", 5),
("src/nested", 3),
("src/nested/deep", 2),
("src/sibling", 1),
("src-other", 1),
] {
let summary = directory_summary(&map, directory);
assert!(
summary.contains(&format!(" · {count} not measured")),
"{summary}"
);
}
assert!(directory_summary(&map, "src").contains("0.0%"));
let closed = map.replace(
"<details class=\"gap-directory\" data-directory=\"src/nested\" open>",
"<details class=\"gap-directory\" data-directory=\"src/nested\">",
);
for directory in [
"src",
"src/nested",
"src/nested/deep",
"src/sibling",
"src-other",
] {
assert_eq!(
directory_summary(&closed, directory)
.split_once('>')
.unwrap()
.1,
directory_summary(&map, directory)
.split_once('>')
.unwrap()
.1
);
}
}
Other sources
Input 1: requirements selection requirements.test-coverage.index.file_map.minimum.descendants
requirements.test-coverage.index.file_map.minimum.descendants:md/requirements/test-coverage.md:303–310
:::{example} index.file_map.minimum.descendants
A map lists `src/a.rs` with 1 of 2 instrumented lines covered,
`src/nested/b.rs` with 1 of 4 covered, and `src/nested/c.rs` as not measured.
Both the `src` and `src/nested` groups show a minimum measured file coverage
of 25% and one not-measured file, including while collapsed.
{test}`requirements.test-coverage.index.file_map.minimum`
{test}`requirements.test-coverage.index.file_map.minimum.statuses`
:::
Input 3: outline src/execution_coverage/book.rs mod[tests]/fn[file_card]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[file_card] - Kind:
fn src/execution_coverage/book.rs:820–830
fn file_card<'a>(content: &'a str, file: &str) -> &'a str {
let row = content
.split(&format!("data-file=\"{}\"", escaped(file)))
.nth(1)
.unwrap();
if row.contains("gap-file-button") {
row.split("</tbody></table></td></tr>").next().unwrap()
} else {
row.split("</tr>").next().unwrap()
}
}
Input 4: outline src/execution_coverage/book.rs mod[tests]/fn[directory_group]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[directory_group] - Kind:
fn src/execution_coverage/book.rs:832–854
// Return a complete native details group, accounting for nested groups and
// explanation controls rather than stopping at the first closing tag.
fn directory_group<'a>(html: &'a str, directory: &str) -> &'a str {
let start = html
.find(&format!(
"<details class=\"gap-directory\" data-directory=\"{directory}\""
))
.unwrap();
let rest = &html[start..];
let tags = regex::Regex::new(r"<details(?:\s[^>]*|)>|</details>").unwrap();
let mut depth = 0;
for tag in tags.find_iter(rest) {
if tag.as_str() == "</details>" {
depth -= 1;
if depth == 0 {
return &rest[..tag.end()];
}
} else {
depth += 1;
}
}
panic!("unclosed directory {directory}");
}
Input 5: outline src/execution_coverage/book.rs mod[tests]/fn[assert_directory_contents]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[assert_directory_contents] - Kind:
fn src/execution_coverage/book.rs:856–868
fn assert_directory_contents(html: &str, directory: &str, children: &[&str], files: &[&str]) {
let group = directory_group(html, directory);
let (summary, body) = group.split_once("</summary>").unwrap();
assert!(summary.contains(&format!("<code>{directory}/</code>")));
assert!(!summary.contains("data-file="));
assert!(!summary.contains("<table"));
for child in children {
assert!(body.contains(directory_group(html, child)));
}
for file in files {
assert!(body.contains(&format!("data-file=\"{file}\"")));
}
}
Input 6: outline src/execution_coverage/book.rs mod[tests]/fn[directory_summary]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[directory_summary] - Kind:
fn src/execution_coverage/book.rs:1457–1464
fn directory_summary<'a>(map: &'a str, directory: &str) -> &'a str {
map.split(&format!("data-directory=\"{directory}\""))
.nth(1)
.unwrap()
.split("</summary>")
.next()
.unwrap()
}