requirements.test-coverage.index.file_map.test
Requirements index · View definition
Requirement
The coverage index MUST NOT offer per-test file coverage maps or a test selector. Its file coverage map MUST focus on insufficient combined coverage under
.
Rationale
Obligations in requirements.test-coverage.index.file_map.test:
- The coverage index MUST NOT offer per-test file coverage maps.
- The coverage index MUST NOT offer a test selector.
- The file coverage map MUST focus on insufficient combined coverage. This is by reference to
requirements.test-coverage.index.file_map.combined, which is cited context, so I did not reassess it.
Mapping to tests:
src/execution_coverage/book.rs#mod[tests]/fn[gaps_union_process_locations_and_omit_per_test_reports]is marked{test}for the subject.- Its fixture has a recorded test “one” and a second process. It renders the index through
populate. - It asserts that the rendered HTML has no
habeas-coverage-testmarkup. A related test,gaps_omit_test_data_and_preserve_saved_profiles_and_sources, listshabeas-coverage-testamong the strings that must be absent. I read that as the per-test map and selector marker, but I did not confirm it against the implementation. - It asserts that the HTML has no
Test runs and provenancesection and nobinary / oneper-test label. Together these rule out per-test maps and a selector for the recorded test. - It asserts that every chapter after the index is a
File notes:chapter. This rules out per-test report chapters. - On the focus clause, it asserts that the index has an
Unresolved coverage gapsheading. Exactly three file rows are listed (code.rs,zero.rsandexecutable.rs), and each has the expected gap content. The non-executableunmeasured.rsis omitted.
- Its fixture has a recorded test “one” and a second process. It renders the index through
maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverageis also marked for the subject. It shows that when combined coverage is unavailable (no runs, stale, incomplete or unreadable), no per-file map rows (data-file=) are offered. It adds no per-test map or selector in those states.- The unmarked
gaps_omit_test_data_and_preserve_saved_profiles_and_sourcesalso checks that a passing file is absent from the gaps table and that test data is omitted. It supports the focus clause, but the subject’s own marked tests are enough without it.
Gaps: I found no obligation that lacks a test assertion, and no wrong expected result. The negative obligations (no per-test maps, no selector) are asserted directly by absence checks. The focus clause is covered by the gap-only row assertions here and by the file_map.combined tests. There are no acknowledgments, and none are needed.
Inputs
Tests
Input 3: outline src/execution_coverage/book.rs mod[tests]/fn[gaps_union_process_locations_and_omit_per_test_reports]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[gaps_union_process_locations_and_omit_per_test_reports] - Kind:
fn src/execution_coverage/book.rs:1116–1205
// {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.test`
// {test}`requirements.test-coverage.index.summary`
// {test}`requirements.test-coverage.index.file_map.combined.details`
// {test}`requirements.test-coverage.index.file_map.notes`
// {test}`requirements.test-coverage.index.details`
#[test]
fn gaps_union_process_locations_and_omit_per_test_reports() {
let (temp, mut book) = fixture();
let root = temp.path();
fs::write(
root.join("code.rs"),
"fn one() {}\nfn two() {}\nfn three() {}\n// not instrumented\n",
)
.unwrap();
fs::write(root.join("zero.rs"), "fn zero() {}\n").unwrap();
fs::write(root.join("unmeasured.rs"), "// no instrumentation\n").unwrap();
fs::write(root.join("executable.rs"), "fn unmeasured() {}\n").unwrap();
let path = record(root, "one", 1, "a", &[(1, 2), (2, 0)]);
let run_path = path.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&run_path).unwrap();
for file in ["zero.rs", "unmeasured.rs", "executable.rs"] {
run.sources
.insert(file.into(), fs::read_to_string(root.join(file)).unwrap());
}
save(&run_path, &run).unwrap();
let mut attempt: Attempt = load(&path.join("attempt.json")).unwrap();
attempt.processes[0]
.lines
.insert("zero.rs".into(), BTreeMap::from([(1, 0)]));
fs::write(path.join("2-child.profraw"), "child profile fixture").unwrap();
attempt.processes.push(Process {
functions: Some(vec![]),
pid: 2,
profiles: vec!["2-child.profraw".into()],
diagnostic: None,
lines: BTreeMap::from([("code.rs".into(), BTreeMap::from([(1, 0), (3, u64::MAX)]))]),
});
save(&path.join("attempt.json"), &attempt).unwrap();
populate(&mut book, root).unwrap();
let index = &book.chapters().next().unwrap().content;
assert!(index.contains("Line coverage: **2/4 (50.0%)**"));
let map = map_html(index);
assert!(file_card(map, "code.rs").contains("2/3 instrumented lines covered"));
assert!(file_card(map, "code.rs").contains("66.7%"));
assert!(file_card(map, "code.rs").contains("--gap-covered: 66.666667%"));
let notes_path = super::super::notes::path(Path::new("reports/coverage.md"), "code.rs");
let href = crate::chapter_href(Path::new("reports/coverage.md"), ¬es_path, None);
assert!(file_card(map, "code.rs").contains(&format!("href=\"{href}\"")));
let notes = book
.chapters()
.find(|chapter| chapter.path.as_ref() == Some(¬es_path))
.unwrap();
assert!(notes.content.contains("File: <code>code.rs</code>"));
assert!(file_card(map, "zero.rs").contains("0.0%"));
assert!(file_card(map, "zero.rs").contains("--gap-covered: 0.000000%"));
assert!(
!map.contains("data-file=\"unmeasured.rs\""),
"a non-executable file has no gap"
);
let unmeasured = file_card(map, "executable.rs")
.split("</tr>")
.next()
.unwrap();
assert!(unmeasured.contains("not measured"));
assert!(!unmeasured.contains('%'));
assert!(!unmeasured.contains("gap-coverage-bar"));
assert!(map.contains("<th>File</th><th>Coverage</th>"));
assert_eq!(
map.matches("class=\"gap-file-row habeas-coverage-file\"")
.count(),
3
);
let mut html = String::new();
pulldown_cmark::html::push_html(
&mut html,
pulldown_cmark::Parser::new_ext(index, pulldown_cmark::Options::all()),
);
assert!(html.contains("Unresolved coverage gaps"));
assert!(!html.contains("habeas-coverage-test"));
assert!(!html.contains("Test runs and provenance"));
assert!(!html.contains("binary / one"));
assert!(
book.chapters()
.skip(1)
.all(|chapter| chapter.name.starts_with("File notes:"))
);
}
Input 4: outline src/execution_coverage/book.rs mod[tests]/fn[maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverage]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverage] - Kind:
fn src/execution_coverage/book.rs:1207–1326
// {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.test`
// {test}`requirements.test-coverage.index.file_map.combined.measurement`
// {test}`requirements.test-coverage.index.summary`
#[test]
fn maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverage() {
let (temp, book) = fixture();
let root = temp.path();
let mut no_runs = book.clone();
populate(&mut no_runs, root).unwrap();
let index = &no_runs.chapters().next().unwrap().content;
assert!(index.contains("Coverage unavailable"));
assert!(index.contains("gap counts unavailable"));
assert!(!map_html(index).contains("data-file="));
assert!(index.contains("Run `habeas coverage`"));
let empty_path = record(root, "empty", 0, "empty", &[]);
let mut empty = book.clone();
populate(&mut empty, root).unwrap();
let empty_index = &empty.chapters().next().unwrap().content;
assert!(empty_index.contains("Coverage unavailable"));
assert!(!empty_index.contains("Line coverage:"));
assert!(!empty_index.contains("NaN"));
assert!(!map_html(empty_index).contains("data-file="));
assert!(empty_index.contains("No usable instrumented lines"));
fs::remove_dir_all(empty_path.parent().unwrap().parent().unwrap()).unwrap();
let path = record(root, "zero", 1, "a", &[(1, 0), (2, 0)]);
let mut zero = book.clone();
populate(&mut zero, root).unwrap();
assert!(
file_card(
map_html(&zero.chapters().next().unwrap().content),
"code.rs"
)
.contains("0.0%")
);
let mut attempt: Attempt = load(&path.join("attempt.json")).unwrap();
attempt.processes[0]
.lines
.get_mut("code.rs")
.unwrap()
.insert(1, 1);
for failure in [
"no processes",
"attempt diagnostic",
"process diagnostic",
"missing source",
"empty profile",
] {
let mut missing = attempt.clone();
match failure {
"no processes" => missing.processes.clear(),
"attempt diagnostic" => missing.diagnostics.push("export incomplete".into()),
"process diagnostic" => {
missing.processes[0].diagnostic = Some("unreadable profile".into());
}
"missing source" => {
missing.processes[0]
.lines
.insert("uncaptured.rs".into(), BTreeMap::from([(1, 1)]));
}
"empty profile" => fs::write(path.join("1-1.profraw"), "").unwrap(),
_ => unreachable!(),
}
save(&path.join("attempt.json"), &missing).unwrap();
let mut unavailable = book.clone();
populate(&mut unavailable, root).unwrap();
let index = &unavailable.chapters().next().unwrap().content;
assert!(index.contains("Coverage unavailable"), "{failure}");
assert!(!map_html(index).contains("data-file="), "{failure}");
assert!(
index.contains("missing or unreadable coverage"),
"{failure}"
);
fs::write(path.join("1-1.profraw"), "retained profile fixture").unwrap();
}
save(&path.join("attempt.json"), &attempt).unwrap();
fs::write(root.join("code.rs"), "changed source\n").unwrap();
fs::write(root.join("new.rs"), "fn newly_added() {}\n").unwrap();
let mut stale = book.clone();
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!(index.contains("1 stale test attempts"));
attempt.processes.push(Process {
functions: Some(vec![]),
pid: 2,
profiles: vec!["missing-child.profraw".into()],
diagnostic: None,
lines: BTreeMap::from([("code.rs".into(), BTreeMap::from([(2, 1)]))]),
});
save(&path.join("attempt.json"), &attempt).unwrap();
let mut incomplete = book.clone();
populate(&mut incomplete, root).unwrap();
let index = &incomplete.chapters().next().unwrap().content;
assert!(index.contains("Coverage unavailable"));
assert!(!map_html(index).contains("data-file="));
assert!(index.contains("missing or unreadable coverage"));
fs::write(root.join("code.rs"), "fn one() {}\nfn two() {}\n").unwrap();
fs::remove_file(root.join("new.rs")).unwrap();
let mut unreadable = book.clone();
populate(&mut unreadable, root).unwrap();
let index = &unreadable.chapters().next().unwrap().content;
assert!(index.contains("1 unavailable test attempts"));
assert!(index.contains("Coverage unavailable"));
assert!(!map_html(index).contains("data-file="));
// Unreadable metadata cannot establish latest-per-test selection.
fs::write(path.join("attempt.json"), "not JSON").unwrap();
let mut uncertain = book;
populate(&mut uncertain, root).unwrap();
let index = &uncertain.chapters().next().unwrap().content;
assert!(index.contains("Coverage history is incomplete"));
assert!(index.contains("gap counts unavailable"));
assert!(!map_html(index).contains("data-file="));
}
Referenced definitions
Input 2: requirements selection requirements.test-coverage.index.file_map.combined
requirements.test-coverage.index.file_map.combined:md/requirements/test-coverage.md:368–381
:::{req} index.file_map.combined
The coverage index MUST present a gaps-focused file coverage map representing
all current first-party Rust files under
{cite}`requirements.references.rust_item_coverage` as its primary overview.
Its primary file rows MUST list only files with unsatisfied coverage
obligations under {cite}`requirements.test-coverage.check.threshold` or
{cite}`requirements.test-coverage.check.functions`. A file meeting its line
target MUST still be listed when it contains an unsatisfied function obligation.
Its coverage counts MUST use only records eligible for the combined view under
{cite}`requirements.test-coverage.index.selection` and
{cite}`requirements.test-coverage.index.freshness`, following
{cite}`requirements.test-coverage.index.file_map`.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.index.file_map.test
requirements.test-coverage.index.file_map.test:md/requirements/test-coverage.md:468–472
:::{req} index.file_map.test
The coverage index MUST NOT offer per-test file coverage maps or a test
selector. Its file coverage map MUST focus on insufficient combined coverage
under {cite}`requirements.test-coverage.index.file_map.combined`.
:::
Input 5: outline src/execution_coverage/book.rs mod[tests]/fn[gaps_omit_test_data_and_preserve_saved_profiles_and_sources]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[gaps_omit_test_data_and_preserve_saved_profiles_and_sources] - Kind:
fn src/execution_coverage/book.rs:1987–2144
// {test}`requirements.test-coverage.index.summary`
// {test}`requirements.test-coverage.index.details`
// {test}`requirements.test-coverage.processes.reports`
#[test]
fn gaps_omit_test_data_and_preserve_saved_profiles_and_sources() {
let (temp, book) = fixture();
let root = temp.path();
fs::write(root.join("passing.rs"), "fn passing() {}\n").unwrap();
let first = record(root, "one", 100, "a", &[(1, 1), (2, 0)]);
fs::write(first.join("2-2.profraw"), "child profile fixture").unwrap();
let mut attempt: Attempt = load(&first.join("attempt.json")).unwrap();
attempt.processes.push(Process {
functions: Some(vec![]),
pid: 2,
profiles: vec!["2-2.profraw".into()],
lines: BTreeMap::from([("code.rs".into(), BTreeMap::from([(1, 0), (2, 7)]))]),
diagnostic: None,
});
// A passing file must not appear in the gaps table.
attempt.processes[0]
.lines
.insert("passing.rs".into(), BTreeMap::from([(1, 1)]));
attempt.processes[0]
.functions
.as_mut()
.unwrap()
.push(super::super::FunctionExecution {
file: "passing.rs".into(),
line: 1,
column: 1,
count: 1,
});
save(&first.join("attempt.json"), &attempt).unwrap();
let run_path = first.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&run_path).unwrap();
run.sources
.insert("passing.rs".into(), "fn passing() {}\n".into());
save(&run_path, &run).unwrap();
record(root, "two", 200, "a", &[(1, 1), (2, 0)]);
let captured_attempt = fs::read(first.join("attempt.json")).unwrap();
let captured_run = fs::read(&run_path).unwrap();
let mut combined = book.clone();
populate(&mut combined, root).unwrap();
let index = combined.chapters().next().unwrap();
assert!(index.content.contains("3/3 (100.0%)"));
assert!(
index
.content
.contains("not establish that all current tests were measured")
);
assert!(!map_html(&index.content).contains("data-file=\"passing.rs\""));
assert!(
combined
.chapters()
.all(|chapter| chapter.name != "File notes: passing.rs")
);
for chapter in combined.chapters() {
for omitted in [
"Test process coverage",
"Captured source",
"habeas-coverage-test",
"Test runs and provenance",
"application/json",
"habeasRenderCoverage",
"binary / one",
"binary / two",
"fn passing() {}",
] {
assert!(
!chapter.content.contains(omitted),
"report includes {omitted}"
);
}
assert!(!chapter.name.starts_with("binary /"));
assert!(
!chapter
.path
.as_ref()
.unwrap()
.to_string_lossy()
.ends_with("-source.md")
);
assert!(chapter.name == "Coverage gaps" || chapter.name.starts_with("File notes:"));
}
fs::write(root.join("code.rs"), "rebuilt source\n").unwrap();
let mut historical = book;
populate(&mut historical, root).unwrap();
assert!(
historical
.chapters()
.next()
.unwrap()
.content
.contains("Coverage unavailable")
);
assert_eq!(
fs::read(first.join("attempt.json")).unwrap(),
captured_attempt
);
assert_eq!(fs::read(&run_path).unwrap(), captured_run);
assert_eq!(
fs::read_to_string(first.join("1-1.profraw")).unwrap(),
"retained profile fixture"
);
assert_eq!(
fs::read_to_string(first.join("2-2.profraw")).unwrap(),
"child profile fixture"
);
// Archived reports use the saved source, even though freshness excludes
// these attempts from the current workspace's gaps report.
let saved = load_saved(root, Some(root.join("target")));
let archived = saved
.records
.iter()
.find(|record| record.attempt.test == "one")
.unwrap();
assert!(!archived.fresh);
let captured_lines = |locations: BTreeMap<(String, u32), u64>| {
locations
.into_iter()
.map(|((file, line), count)| {
let source_line = archived.run.sources[&file]
.lines()
.nth(line as usize - 1)
.unwrap();
((file, line), (source_line.to_owned(), count))
})
.collect::<BTreeMap<_, _>>()
};
let individual = |process: &Process| {
captured_lines(
process
.lines
.iter()
.flat_map(|(file, lines)| {
lines
.iter()
.map(move |(&line, &count)| ((file.clone(), line), count))
})
.collect(),
)
};
let parent = individual(&archived.attempt.processes[0]);
let child = individual(&archived.attempt.processes[1]);
let combined = captured_lines(union(std::iter::once(archived)));
assert_eq!(parent[&("code.rs".into(), 1)], ("fn one() {}".into(), 1));
assert_eq!(parent[&("code.rs".into(), 2)], ("fn two() {}".into(), 0));
assert_eq!(child[&("code.rs".into(), 1)], ("fn one() {}".into(), 0));
assert_eq!(child[&("code.rs".into(), 2)], ("fn two() {}".into(), 7));
assert_eq!(combined[&("code.rs".into(), 2)], ("fn two() {}".into(), 7));
assert_eq!(parent.values().filter(|(_, count)| *count > 0).count(), 2);
assert_eq!(combined.values().filter(|(_, count)| *count > 0).count(), 3);
assert!(
combined
.values()
.all(|(source, _)| !source.contains("rebuilt source"))
);
}