Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

requirements.test-coverage.index.file_map.table

Requirements index · View definition

evidence Valid

Requirement

Each file coverage map MUST present its listed files in a compact table, with one row per file and columns for its workspace-relative path and coverage percentage or measurement status. Covered and instrumented line counts MUST remain available in each measured file’s row or expanded details. The counts, statuses, and visual distinction of coverage levels MUST follow cite requirements.test-coverage.index.file_map.

Rationale

The reviewed tests adequately check requirements.test-coverage.index.file_map.table. The cited requirements.test-coverage.index.file_map is context only, so I did not reassess it.

Table with one row per file, and path and coverage columns

  • gaps_union_process_locations_and_omit_per_test_reports asserts the header <th>File</th><th>Coverage</th>.
  • The same test counts rows with class gap-file-row habeas-coverage-file and expects exactly 3 for the three listed files, code.rs, zero.rs and executable.rs. A non-executable file has no row.
  • coverage_bars_distinguish_measured_levels_alongside_percentage_text builds five files and asserts each appears exactly once through data-file="...". It also asserts each row contains <code>{file}</code>, the workspace-relative path.
  • gaps_escape_paths_and_do_not_round_positive_coverage_to_zero checks that a path containing special characters is rendered escaped in the table.

Percentage or measurement status

  • gaps_union_process_locations_and_omit_per_test_reports asserts 66.7% for code.rs and 0.0% for zero.rs.
  • The same test asserts that executable.rs shows “not measured”, with no % and no coverage bar in its row.
  • coverage_bars_distinguish_measured_levels_alongside_percentage_text asserts the percentage text for the levels 0, 1, 25, 75 and 100. It also asserts the bar’s --gap-covered value and the CSS bar rules.
  • gaps_escape_paths_and_do_not_round_positive_coverage_to_zero asserts that 1/2000 shows &lt;0.1% and not 0.0%.

Covered and instrumented counts remain available for measured files

  • gaps_union_process_locations_and_omit_per_test_reports asserts “2/3 instrumented lines covered” in the code.rs card.
  • gaps_escape_paths_and_do_not_round_positive_coverage_to_zero asserts “1/2000 instrumented lines covered”.
  • The file_card helper covers both a plain row and an expanded-details row. The assertions therefore check counts in either form.

Counts, statuses and visual distinction follow file_map

  • Counts are unioned across a child process: code.rs shows 2/3 and the headline shows 2/4.
  • The zero-hit and not-measured statuses are asserted as above.
  • Unavailable coverage never produces rows. maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverage and incomplete_attempts_do_not_label_their_files_as_unmeasured_in_a_partial_map assert no data-file= rows and no “not measured” in each unavailable case. Those cases are no runs, empty coverage, diagnostics, a missing source, an empty or missing profile, stale attempts and unreadable metadata.

“Compact” is a qualitative term. The single-row-per-file table with a bar is what the tests check, and the text names no further testable property for it.

All five tests carry {test} references to the subject. I found no unaddressed obligations.

Inputs

Tests

Input 3: outline src/execution_coverage/book.rs mod[tests]/fn[gaps_union_process_locations_and_omit_per_test_reports]
    // {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"), &notes_path, None);
        assert!(file_card(map, "code.rs").contains(&format!("href=\"{href}\"")));
        let notes = book
            .chapters()
            .find(|chapter| chapter.path.as_ref() == Some(&notes_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]
    // {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="));
    }
Input 5: outline src/execution_coverage/book.rs mod[tests]/fn[incomplete_attempts_do_not_label_their_files_as_unmeasured_in_a_partial_map]
    // {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[gaps_escape_paths_and_do_not_round_positive_coverage_to_zero]
    // {test}`requirements.test-coverage.index.file_map`
    // {test}`requirements.test-coverage.index.file_map.table`
    #[test]
    fn gaps_escape_paths_and_do_not_round_positive_coverage_to_zero() {
        let policy = super::super::check::PolicyReport {
            report: super::super::check::CheckReport {
                passed: false,
                text: String::new(),
            },
            files: vec![super::super::check::FilePolicy {
                file: "src/<unsafe>\".rs".into(),
                covered: 1,
                total: 2000,
                obligations: vec![super::super::check::Obligation {
                    selector: String::new(),
                    line: 1,
                    measurement: "below target".into(),
                    exception: None,
                }],
            }],
            counts_complete: true,
            measured: true,
            findings: vec![],
        };
        let map = gaps_map(&policy, Path::new("coverage.md"), 1);
        assert!(map.contains("src/&lt;unsafe&gt;&quot;.rs"));
        assert!(!map.contains("<unsafe>"));
        assert!(map.contains("&lt;0.1%"));
        assert!(map.contains("1/2000 instrumented lines covered"));
        assert!(!map.contains(">0.0%<"));
    }
Input 7: outline src/execution_coverage/book.rs mod[tests]/fn[coverage_bars_distinguish_measured_levels_alongside_percentage_text]
    // {test}`requirements.test-coverage.index.file_map`
    // {test}`requirements.test-coverage.index.file_map.table`
    #[test]
    fn coverage_bars_distinguish_measured_levels_alongside_percentage_text() {
        let mut policy = super::super::check::PolicyReport {
            report: super::super::check::CheckReport {
                passed: false,
                text: String::new(),
            },
            files: vec![],
            counts_complete: true,
            measured: true,
            findings: vec![],
        };
        for covered in [0, 1, 25, 75, 100] {
            policy.files.push(super::super::check::FilePolicy {
                file: format!("src/level-{covered}.rs"),
                covered,
                total: 100,
                obligations: vec![super::super::check::Obligation {
                    selector: "fn[unexecuted]".into(),
                    line: 1,
                    measurement: "zero execution".into(),
                    exception: None,
                }],
            });
        }
        let map = gaps_map(&policy, Path::new("coverage.md"), 1);
        for covered in [0, 1, 25, 75, 100] {
            let file = format!("src/level-{covered}.rs");
            let row = file_card(&map, &file).split("</tr>").next().unwrap();
            assert!(row.contains(&format!("<code>{file}</code>")));
            assert!(row.contains(&format!(">{covered}.0%")));
            assert!(row.contains(&format!("--gap-covered: {covered}.000000%")));
            assert!(row.contains("class=\"gap-coverage-bar\" aria-hidden=\"true\""));
            assert_eq!(map.matches(&format!("data-file=\"{file}\"")).count(), 1);
        }
        let css = include_str!("../../assets/coverage-gaps.css");
        assert!(css.contains(".gap-coverage-bar::before"));
        assert!(css.contains("width: var(--gap-covered)"));
        assert!(css.contains("background: var(--gap-link)"));
    }

Referenced definitions

Input 2: requirements selection requirements.test-coverage.index.file_map
:::{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.table
:::{req} index.file_map.table
Each file coverage map MUST present its listed files in a compact table, with
one row per file and columns for its workspace-relative path and coverage
percentage or measurement status. Covered and instrumented line counts MUST
remain available in each measured file's row or expanded details.
The counts, statuses, and visual distinction of coverage levels MUST follow
{cite}`requirements.test-coverage.index.file_map`.
:::
Input 8: outline src/execution_coverage/book.rs mod[tests]/fn[map_html]
    fn map_html(content: &str) -> &str {
        content
            .split("<section class=\"habeas-coverage-map")
            .nth(1)
            .unwrap()
            .split("</section>")
            .next()
            .unwrap()
    }
Input 9: outline src/execution_coverage/book.rs mod[tests]/fn[file_card]
    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()
        }
    }