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.directories.initial

Requirements index · View definition

evidence Valid

Requirement

Directory groups under cite requirements.test-coverage.index.file_map.directories MUST be expanded initially in the combined gaps overview. File rows at the workspace root MUST remain visible.

Rationale

The subject has two obligations. The test is src/execution_coverage/book.rs#mod[tests]/fn[combined_directory_minimum_includes_hidden_passing_files], and it covers both.

  1. Directory groups expanded initially. The test builds a three-level hierarchy: src, src/nested and src/nested/deep. It renders the combined overview through populate and isolates the map with map_html. It then asserts that data-directory="src" open appears. It also loops over all three directories and asserts that each data-directory="…" open is present. That covers nested descendant groups as well as the top-level one. assert_directory_contents confirms the groups really nest and hold the expected files and child groups.

  2. Root file rows remain visible. The fixture’s root code.rs has an uncovered line from record(..., &[(1,0),(2,1)]), so it appears in the map. The test asserts data-file="code.rs" is present. It also asserts that this row comes before the first <details class="gap-directory", so the row is not inside any directory group. assert_eq!(map.matches("data-file=").count(), 3) checks the row count.

An implementation that rendered groups collapsed, left only the top group open, or hid or nested the root file rows would fail these assertions.

The collapse behaviour and the summaries in the parent requirement requirements.test-coverage.index.file_map.directories are cited context. They are not assessed here.

Inputs

Tests

Input 3: outline src/execution_coverage/book.rs mod[tests]/fn[combined_directory_minimum_includes_hidden_passing_files]
    // {test}`requirements.test-coverage.index.file_map.combined`
    // {test}`requirements.test-coverage.index.file_map.directories.initial`
    // {test}`requirements.test-coverage.index.file_map.directories.data`
    // {test}`requirements.test-coverage.index.file_map.minimum`
    // {test}`requirements.test-coverage.index.gaps.summary`
    // {test}`requirements.test-coverage.index.file_map.directories`
    #[test]
    fn combined_directory_minimum_includes_hidden_passing_files() {
        let (temp, mut book) = fixture();
        let root = temp.path();
        fs::create_dir_all(root.join("src/nested/deep")).unwrap();
        fs::write(
            root.join("src/gap.rs"),
            format!("fn gap() {{\n{}}}\n", " let value = 1;\n".repeat(18)),
        )
        .unwrap();
        fs::write(
            root.join("src/nested/passing.rs"),
            "fn passing() {\n let a = 1;\n let b = 2;\n let c = 3;\n}\n",
        )
        .unwrap();
        fs::write(root.join("src/nested/deep/gap.rs"), "fn nested_gap() {}\n").unwrap();
        let path = record(root, "all", 1, "same", &[(1, 0), (2, 1)]);
        let run_path = path.parent().unwrap().parent().unwrap().join("run.json");
        let mut run: Run = load(&run_path).unwrap();
        let mut attempt: Attempt = load(&path.join("attempt.json")).unwrap();
        for (file, total, covered, count) in [
            ("src/gap.rs", 20, 19, 0),
            ("src/nested/passing.rs", 5, 4, 1),
            ("src/nested/deep/gap.rs", 1, 1, 0),
        ] {
            run.sources
                .insert(file.into(), fs::read_to_string(root.join(file)).unwrap());
            attempt.processes[0].lines.insert(
                file.into(),
                (1..=total)
                    .map(|line| (line, u64::from(line <= covered)))
                    .collect(),
            );
            attempt.processes[0].functions.as_mut().unwrap().push(
                super::super::FunctionExecution {
                    file: file.into(),
                    line: 1,
                    column: 1,
                    count,
                },
            );
        }
        save(&run_path, &run).unwrap();
        save(&path.join("attempt.json"), &attempt).unwrap();
        populate(&mut book, root).unwrap();
        let overview = &book.chapters().next().unwrap().content;
        let map = map_html(overview);
        assert!(map.contains("data-directory=\"src\" open"));
        assert!(map.contains("data-min-covered=\"4\" data-min-instrumented=\"5\">80.0%"));
        assert!(map.contains("2 uncovered obligations"));
        for (directory, expected) in [("src", 2), ("src/nested", 1), ("src/nested/deep", 1)] {
            let summary = directory_summary(map, directory);
            assert!(summary.contains(&format!("{expected} uncovered obligations")));
            assert!(summary.contains("Minimum measured file coverage:"));
        }
        assert_directory_contents(map, "src", &["src/nested"], &["src/gap.rs"]);
        assert_directory_contents(map, "src/nested", &["src/nested/deep"], &[]);
        assert_directory_contents(map, "src/nested/deep", &[], &["src/nested/deep/gap.rs"]);
        for directory in ["src", "src/nested", "src/nested/deep"] {
            assert!(map.contains(&format!("data-directory=\"{directory}\" open")));
        }
        assert!(map.contains("data-file=\"code.rs\""));
        assert!(
            map.find("data-file=\"code.rs\"").unwrap()
                < map.find("<details class=\"gap-directory\"").unwrap(),
            "root file rows are outside directory controls"
        );
        assert_eq!(map.matches("data-file=").count(), 3);
        assert!(map.contains("data-file=\"src/gap.rs\""));
        assert!(map.contains("95.0%"));
        assert!(file_card(map, "src/gap.rs").contains("<code>src/gap.rs</code>"));
        assert!(map.contains("zero execution"));
        assert!(!map.contains("data-file=\"src/nested/passing.rs\""));
        assert!(
            book.chapters()
                .all(|chapter| chapter.name != "File notes: src/nested/passing.rs")
        );
        assert!(overview.contains("1 file obligations · 3 function obligations"));
    }

Referenced definitions

Input 2: requirements selection requirements.test-coverage.index.file_map.directories
:::{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.
:::

Other sources

Input 1: requirements selection requirements.test-coverage.index.file_map.directories.initial
:::{req} index.file_map.directories.initial
Directory groups under
{cite}`requirements.test-coverage.index.file_map.directories` MUST be expanded
initially in the combined gaps overview. File rows at the workspace root MUST
remain visible.
:::
Input 4: outline src/execution_coverage/book.rs mod[tests]/fn[fixture]
    fn fixture() -> (tempfile::TempDir, Book) {
        let temp = tempfile::tempdir().unwrap();
        fs::write(temp.path().join("Cargo.toml"), "[workspace]\n").unwrap();
        fs::write(temp.path().join("code.rs"), "fn one() {}\nfn two() {}\n").unwrap();
        let mut book = Book::new();
        book.push_item(Chapter::new(
            "Coverage",
            ":::{coverage-index}\n:::\n".into(),
            "reports/coverage.md",
            vec![],
        ));
        (temp, book)
    }
Input 5: 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 6: outline src/execution_coverage/book.rs mod[tests]/fn[assert_directory_contents]
    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 7: outline src/execution_coverage/book.rs mod[tests]/fn[directory_summary]
    fn directory_summary<'a>(map: &'a str, directory: &str) -> &'a str {
        map.split(&format!("data-directory=\"{directory}\""))
            .nth(1)
            .unwrap()
            .split("</summary>")
            .next()
            .unwrap()
    }