requirements.test-coverage.index.file_map.minimum.statuses
Requirements index · View definition
Requirement
Each directory group under
MUST display the number of its listed files, including descendants, that are not measured whenever that count is nonzero. The status MUST follow
. The count MUST describe only files listed by the map, regardless of which groups are expanded.
Rationale
The reviewed tests adequately check requirements.test-coverage.index.file_map.minimum.statuses.
Obligations derived from the text
- Each directory group shows the count of its listed files, descendants included, that are not measured. This applies whenever the count is nonzero.
- The status follows
requirements.test-coverage.index.file_map. “Not measured” means no recorded instrumented lines in usable coverage. Unavailable coverage is labeled unavailable, never “not measured” or 0%. - The count covers only files the map lists, and it does not change with which groups are expanded.
Coverage in src/execution_coverage/book.rs#mod[tests]/fn[directory_minima_use_exact_fractions_and_count_unmeasured_descendants]
- Descendants and nesting. The example
src/a.rs(1/2),src/nested/b.rs(1/4) andsrc/nested/c.rs(0/0) is rendered. Bothsrcandsrc/nestedsummaries are asserted to contain “1 not measured” and 25.0%. They must not contain “2 not measured” or “0 unavailable”. - Deeper hierarchy. A larger map with nested, deep, sibling and prefix-lookalike directories asserts exact counts per directory:
src5,src/nested3,src/nested/deep2,src/sibling1,src-other1. This checks descendant inclusion. It also checks that a lookalikesrc-otheris not folded intosrc. - Measured zero versus not measured. A file at 0/4 is
data-status="measured"and shows 0.0%. It is not counted as not measured, and the summary shows 1 not measured. - Only not-measured files appear. A directory with only unmeasured files shows “No measured files” and “1 not measured”, with no percentage.
- Listed files only. Unlisted policy entries (
hidden-empty.rs, andhidden-accepted.rswith an accepted exception) are added to the policy but must not inflate the count. - Expansion state. The map is re-rendered with
src/nestedclosed. The summaries of every directory are asserted identical between the open and closed versions. Thedirectory_summaryhelper takes the text up to</summary>, so it checks what a collapsed group shows.
Unavailable status in src/execution_coverage/book.rs#mod[tests]/fn[incomplete_attempts_do_not_label_their_files_as_unmeasured_in_a_partial_map]
- With an incomplete attempt and with a stale selected attempt, the page shows “Coverage unavailable”.
- The map contains no
data-file=, nogap-directorygroup and no “not measured” text. - This is the case where the status must not be “not measured”.
Zero count. The text only requires display when the count is nonzero, so there is nothing further to test.
All obligations have tests with assertions that would catch plausible violations. Both tests carry {test} references to the subject. I found no marking gap or assertion gap.
Inputs
Tests
Input 4: 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 5: outline src/execution_coverage/book.rs mod[tests]/fn[incomplete_attempts_do_not_label_their_files_as_unmeasured_in_a_partial_map]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[incomplete_attempts_do_not_label_their_files_as_unmeasured_in_a_partial_map] - Kind:
fn src/execution_coverage/book.rs:1328–1380
// {test}`requirements.test-coverage.index.file_map`
// {test}`requirements.test-coverage.index.file_map.table`
// {test}`requirements.test-coverage.index.file_map.combined`
// {test}`requirements.test-coverage.index.file_map.combined.measurement`
// {test}`requirements.test-coverage.index.freshness`
// {test}`requirements.test-coverage.index.file_map.minimum`
// {test}`requirements.test-coverage.index.file_map.minimum.statuses`
#[test]
fn incomplete_attempts_do_not_label_their_files_as_unmeasured_in_a_partial_map() {
let (temp, book) = fixture();
let root = temp.path();
fs::create_dir_all(root.join("src/nested")).unwrap();
fs::write(root.join("src/nested/other.rs"), "fn other() {}\n").unwrap();
let good = record(root, "good", 1, "a", &[(1, 1)]);
let bad = record(root, "bad", 2, "a", &[]);
let mut attempt: Attempt = load(&bad.join("attempt.json")).unwrap();
attempt.processes[0].lines =
BTreeMap::from([("src/nested/other.rs".into(), BTreeMap::from([(1, 1)]))]);
save(&bad.join("attempt.json"), &attempt).unwrap();
for path in [&good, &bad] {
let run_path = path.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&run_path).unwrap();
run.sources
.insert("src/nested/other.rs".into(), "fn other() {}\n".into());
save(&run_path, &run).unwrap();
}
fs::remove_file(bad.join("1-1.profraw")).unwrap();
let mut partial = book.clone();
populate(&mut partial, root).unwrap();
let index = &partial.chapters().next().unwrap().content;
assert!(index.contains("Coverage unavailable"));
assert!(!map_html(index).contains("data-file="));
assert!(!map_html(index).contains("not measured"));
assert!(!map_html(index).contains("class=\"gap-directory\""));
assert!(!map_html(index).contains("data-min-covered="));
assert!(!map_html(index).contains("gap-coverage-bar\""));
assert!(index.contains("1 unavailable test attempts"));
// A stale selected attempt leaves the same unknown per-file state.
let run_path = bad.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&run_path).unwrap();
run.inputs
.insert("missing-build-input".into(), "old-hash".into());
save(&run_path, &run).unwrap();
let mut stale = book;
populate(&mut stale, root).unwrap();
let index = &stale.chapters().next().unwrap().content;
assert!(index.contains("Coverage unavailable"));
assert!(!map_html(index).contains("data-file="));
assert!(!map_html(index).contains("class=\"gap-directory\""));
assert!(!map_html(index).contains("data-min-covered="));
assert!(!map_html(index).contains("not measured"));
assert!(index.contains("1 stale test attempts"));
}
Input 6: 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
);
}
}
Referenced definitions
Input 2: requirements selection requirements.test-coverage.index.file_map.directories
requirements.test-coverage.index.file_map.directories:md/requirements/test-coverage.md:252–262
:::{req} index.file_map.directories
The table of {cite}`requirements.test-coverage.index.file_map.table` MUST group
its listed files by their directory hierarchy. Each non-root directory
containing a listed file, directly or through descendants, MUST have a group.
Each group MUST be independently expandable and collapsible.
A collapsed group MUST show its workspace-relative path and the summaries
required by {cite}`requirements.test-coverage.index.file_map.minimum` and
{cite}`requirements.test-coverage.index.file_map.minimum.statuses`, while
hiding its file rows and descendant groups.
:::
Input 3: requirements selection requirements.test-coverage.index.file_map
requirements.test-coverage.index.file_map:md/requirements/test-coverage.md:227–241
:::{req} index.file_map
A file coverage map MUST identify each file by its workspace-relative path and
show its covered and instrumented line counts and percentage. These counts MUST
use the union rule of {cite}`requirements.test-coverage.index.summary`,
restricted to the file and the records represented by that map, including
associated child processes. The map MUST visually distinguish coverage levels
while also displaying percentages as text. The percentage MUST describe the
map's recorded instrumented lines, rather than all physical source lines.
A listed file with instrumented lines but no positive execution counts MUST
show 0%. A listed file with no recorded instrumented lines in otherwise usable
coverage MUST show "not measured" without a percentage. Coverage whose
completeness cannot be established MUST be identified as unavailable rather
than as 0% or "not measured".
:::
Other sources
Input 1: requirements selection requirements.test-coverage.index.file_map.minimum.statuses
requirements.test-coverage.index.file_map.minimum.statuses:md/requirements/test-coverage.md:294–301
:::{req} index.file_map.minimum.statuses
Each directory group under
{cite}`requirements.test-coverage.index.file_map.directories` MUST display
the number of its listed files, including descendants, that are not measured
whenever that count is nonzero. The status MUST follow
{cite}`requirements.test-coverage.index.file_map`. The count MUST describe
only files listed by the map, regardless of which groups are expanded.
:::
Input 7: 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()
}