requirements.test-coverage.check.functions
Requirements index · View definition
Requirement
Every function under
without recorded execution attributable to it MUST have current accepted exception evidence under
, even when its containing file meets the target of
.
Execution attributable only to another function, including a nested function or closure, MUST NOT establish coverage of the enclosing function merely because their source locations overlap. Having no recorded lines alone MUST NOT establish that a function has no executable coverage obligations.
Rationale
I judged this from the supplied test sources only. I did not request implementation source or run searches.
Obligations derived from requirements.test-coverage.check.functions:
- An in-scope function with no recorded execution attributable to it must have accepted exception evidence, even when its file meets the threshold.
- Execution attributable only to another function must not cover the enclosing function. This covers nested functions and closures, and overlapping source locations do not change it.
- Having no recorded lines alone must not establish that a function has no executable obligations.
Mapping to tests:
- Obligation 1, an unexecuted function fails despite a passing file.
src/execution_coverage/check.rs#mod[tests]/fn[overlapping_nested_functions_and_closures_do_not_cover_the_parent]records the file’s only line as executed, so the file is fully covered. It still asserts failure with#fn[outer]: zero execution.methods_tests_and_helpers_are_included_and_discovery_failures_are_reportedassertszero executionfor the method, the test function and the helper.default_trait_bodies_and_cfg_exclusions_are_obligations_but_declarations_are_notasserts#trait[T]/fn[body]: zero executionand#fn[excluded]: not measured.tests/execution_coverage.rs#fn[full_test_flow_checks_real_function_counters_after_all_tests]runs the real counters end to end. It expects failure with#fn[outer]/fn[hidden]: zero executionwhile the tests themselves succeed.
- Obligation 1, exception evidence.
accepted_file_and_function_explanations_remain_separate_from_executioncovers four cases:- A file-level exception does not excuse the function, and the check fails.
- A function-level accepted citation lets the check pass, and the exception is listed separately.
- The same citation covers a not-measured function.
- A review determination of false or
FIXMErejects the exception.
- Obligation 2, nested functions and closures.
overlapping_nested_functions_and_closures_do_not_cover_the_parentruns two scenarios. In the first, the inner function and a closure execute butouterstays zero, and the check fails forouteronly. In the second,outerexecutes whileinneris zero, and the failure names onlyinner.expanded_async_entries_match_the_fn_keyword_without_borrowing_closure_executionshows that closure-only execution is reported as#fn[work]: not measured. It also shows that an entry located at thefnkeyword afterasyncis matched.- The end-to-end test confirms that
#fn[outer]: zero executionis absent when only the nested function is unexecuted.
- Obligation 3, no recorded lines.
unmeasured_executable_files_and_parse_failures_do_not_disappearhasfn missing()with no recorded lines and no function entry. It asserts#fn[missing]: not measuredandcode.rs: not measured — FAIL. A file with only a declaration and a struct is reported as “no executable obligations”.default_trait_bodies_and_cfg_exclusions_are_obligations_but_declarations_are_notshows that a bodiless declaration, a macro call and a derive do not create obligations.
- Execution counted as union.
children_and_filtered_runs_contribute_to_the_same_unionshows that executions from child processes and filtered runs combine, and that a later all-zero run does not erase an earlier execution.
The assertions check specific outcomes: pass or fail, and the selector-specific messages. Both the positive and negative cases for each clause are covered, so I found no gaps.
Inputs
Tests
Input 5: outline src/execution_coverage/check.rs mod[tests]/fn[expanded_async_entries_match_the_fn_keyword_without_borrowing_closure_execution]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[expanded_async_entries_match_the_fn_keyword_without_borrowing_closure_execution] - Kind:
fn src/execution_coverage/check.rs:1110–1128
// {test}`requirements.test-coverage.check.functions`
#[test]
fn expanded_async_entries_match_the_fn_keyword_without_borrowing_closure_execution() {
let source = "#[tokio::test]\nasync fn work() { let callback = || {}; callback(); }\n";
let temp = fixture(source);
let root = temp.path();
let mut p = process(root, &[(2, 1)], 1);
p.functions.as_mut().unwrap()[0].column = 7; // fn after async
record(root, "work", 1, "same", vec![p.clone()]);
let result = report(root);
assert!(result.passed, "{}", result.text);
// Executing only the closure must not count as entering this function.
p.functions.as_mut().unwrap()[0].column =
source.lines().nth(1).unwrap().find("||").unwrap() as u32 + 1;
record(root, "work", 2, "same", vec![p]);
let result = report(root);
assert!(!result.passed);
assert!(result.text.contains("#fn[work]: not measured"));
}
Input 6: outline src/execution_coverage/check.rs mod[tests]/fn[children_and_filtered_runs_contribute_to_the_same_union]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[children_and_filtered_runs_contribute_to_the_same_union] - Kind:
fn src/execution_coverage/check.rs:1210–1232
// {test}`requirements.test-coverage.check.threshold`
// {test}`requirements.test-coverage.check.functions`
#[test]
fn children_and_filtered_runs_contribute_to_the_same_union() {
let temp = fixture("fn a() {\n let x=1;\n let y=2;\n let z=3;\n}\n");
let root = temp.path();
let first = process(root, &[(1, 1), (2, 1), (3, 0), (4, 0), (5, 1)], 0);
let mut child = process(root, &[(1, 0), (2, 0), (3, 1), (4, 1), (5, 0)], 1);
child.pid = 2;
record(root, "filtered-first", 1, "same", vec![first, child]);
assert!(report(root).passed);
record(
root,
"filtered-second",
2,
"same",
vec![process(root, &[(1, 0), (2, 0), (3, 0), (4, 0), (5, 0)], 0)],
);
assert!(
report(root).passed,
"a zero second test does not erase the first test's execution"
);
}
Input 7: outline src/execution_coverage/check.rs mod[tests]/fn[overlapping_nested_functions_and_closures_do_not_cover_the_parent]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[overlapping_nested_functions_and_closures_do_not_cover_the_parent] - Kind:
fn src/execution_coverage/check.rs:1234–1260
// {test}`requirements.test-coverage.check.functions`
// {test}`requirements.test-coverage.check.scope`
#[test]
fn overlapping_nested_functions_and_closures_do_not_cover_the_parent() {
let source = "fn outer() { fn inner() {} let f = || {}; }\n";
let temp = fixture(source);
let root = temp.path();
let mut p = process(root, &[(1, 1)], 0);
p.functions.as_mut().unwrap()[1].count = 1;
p.functions.as_mut().unwrap().push(FunctionExecution {
file: "code.rs".into(),
line: 1,
column: (source.find("||").unwrap() + 3) as u32,
count: 1,
});
record(root, "nested", 1, "same", vec![p]);
let result = report(root);
assert!(!result.passed);
assert!(result.text.contains("#fn[outer]: zero execution"));
assert!(!result.text.contains("#fn[outer]/fn[inner]:"));
let mut p = process(root, &[(1, 1)], 1);
p.functions.as_mut().unwrap()[1].count = 0;
record(root, "nested", 2, "same", vec![p]);
let result = report(root);
assert!(result.text.contains("#fn[outer]/fn[inner]: zero execution"));
assert!(!result.text.contains("#fn[outer]:"));
}
Input 8: outline src/execution_coverage/check.rs mod[tests]/fn[default_trait_bodies_and_cfg_exclusions_are_obligations_but_declarations_are_not]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[default_trait_bodies_and_cfg_exclusions_are_obligations_but_declarations_are_not] - Kind:
fn src/execution_coverage/check.rs:1262–1300
// {test}`requirements.test-coverage.check.scope`
// {test}`requirements.test-coverage.check.threshold`
// {test}`requirements.test-coverage.check.functions`
#[test]
fn default_trait_bodies_and_cfg_exclusions_are_obligations_but_declarations_are_not() {
let temp =
fixture("trait T { fn declaration(); fn body() {} }\n#[cfg(any())] fn excluded() {}\n");
let root = temp.path();
let mut p = process(root, &[(1, 1)], 0);
p.functions.as_mut().unwrap().retain(|f| f.line == 1);
record(root, "traits", 1, "same", vec![p]);
let result = report(root);
assert!(!result.passed);
assert!(result.text.contains("#fn[excluded]: not measured"));
assert!(
result.text.contains("#trait[T]/fn[body]: zero execution"),
"{}",
result.text
);
assert!(!result.text.contains("fn[declaration]"));
let parsed = crate::outline::parse_with(
&crate::outline::RUST_PROFILE,
"struct S;\ntrait T { fn declaration(); }\n",
)
.unwrap();
assert!(
inventory("struct S;\ntrait T { fn declaration(); }\n", &parsed)
.unwrap()
.1
);
let parsed =
crate::outline::parse_with(&crate::outline::RUST_PROFILE, "make_functions!();")
.unwrap();
assert!(!inventory("make_functions!();", &parsed).unwrap().1);
let parsed =
crate::outline::parse_with(&crate::outline::RUST_PROFILE, "#[derive(Clone)] struct S;")
.unwrap();
assert!(!inventory("#[derive(Clone)] struct S;", &parsed).unwrap().1);
}
Input 9: outline src/execution_coverage/check.rs mod[tests]/fn[accepted_file_and_function_explanations_remain_separate_from_execution]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[accepted_file_and_function_explanations_remain_separate_from_execution] - Kind:
fn src/execution_coverage/check.rs:1339–1419
// {test}`requirements.test-coverage.check.exceptions`
// {test}`requirements.test-coverage.check.exceptions.reviews`
// {test}`requirements.test-coverage.check.exceptions.binding`
// {test}`requirements.test-coverage.check.report`
// {test}`requirements.test-coverage.check.functions`
// {test}`requirements.test-coverage.check.measurement`
// {test}`requirements.test-coverage.check.threshold`
#[test]
fn accepted_file_and_function_explanations_remain_separate_from_execution() {
let temp = fixture(
"//! :::{cite} habeas:coverage\n//! Generated platform glue lacks a harness.\n//! :::\n\nfn a() {}\n",
);
let root = temp.path();
reviews(root, json!(true));
record(root, "a", 1, "same", vec![process(root, &[(5, 0)], 0)]);
let result = report(root);
assert!(!result.passed, "file exception cannot waive its function");
assert!(
result
.text
.contains("code.rs: 0/1 (0.0%) — accepted exception")
);
assert!(result.text.contains("#fn[a]: zero execution"));
fs::write(root.join("code.rs"),"//! :::{cite} habeas:coverage\n//! File rationale.\n//! :::\n\n// :::{cite} habeas:coverage\n// Function rationale, describing only a Linux condition.\n// :::\nfn a() {}\n").unwrap();
reviews(root, json!(true));
record(root, "a", 2, "linux", vec![process(root, &[(8, 0)], 0)]);
let result = report(root);
assert!(result.passed, "{}", result.text);
assert!(result.text.contains("0/1 (0.0%)"));
let exceptions = result
.text
.split_once("\nAccepted exceptions (do not increase execution coverage):\n")
.unwrap()
.1;
assert!(exceptions.contains("- code.rs: file threshold (0/1 (0.0%))"));
assert!(exceptions.contains("- code.rs#fn[a]: zero execution"));
let mut absent = process(root, &[(8, 0)], 0);
absent.functions = Some(vec![]);
record(root, "a", 3, "windows", vec![absent]);
let result = report(root);
assert!(
result.passed,
"same accepted citation covers unmeasured functions without conditional matching"
);
let exceptions = result
.text
.split_once("\nAccepted exceptions (do not increase execution coverage):\n")
.unwrap()
.1;
assert!(exceptions.contains("- code.rs#fn[a]: not measured"));
record(root, "a", 4, "covered", vec![process(root, &[(8, 1)], 1)]);
assert!(
report(root).passed,
"citation may remain when no exception is needed"
);
fs::write(root.join("driver.rs"), "fn driver() {}").unwrap();
let mut p = process(root, &[], 0);
p.lines.insert("driver.rs".into(), BTreeMap::from([(1, 1)]));
p.functions.as_mut().unwrap().push(FunctionExecution {
file: "driver.rs".into(),
line: 1,
column: 1,
count: 1,
});
record(root, "a", 5, "unmeasured-file", vec![p]);
let result = report(root);
assert!(result.passed, "{}", result.text);
assert!(
result
.text
.contains("code.rs: not measured — accepted exception"),
"{}",
result.text
);
assert!(!result.text.contains("code.rs: 0/"), "{}", result.text);
reviews(root, json!(false));
assert!(!report(root).passed);
assert!(report(root).text.contains("determination is false"));
reviews(root, json!({"FIXME":["acknowledgment"]}));
assert!(report(root).text.contains("cannot accept a {fixme}"));
}
Input 10: outline src/execution_coverage/check.rs mod[tests]/fn[unmeasured_executable_files_and_parse_failures_do_not_disappear]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[unmeasured_executable_files_and_parse_failures_do_not_disappear] - Kind:
fn src/execution_coverage/check.rs:1484–1538
// {test}`requirements.test-coverage.check.measurement`
// {test}`requirements.test-coverage.check.scope`
// {test}`requirements.test-coverage.check.threshold`
// {test}`requirements.test-coverage.check.report`
// {test}`requirements.test-coverage.check.functions`
#[test]
fn unmeasured_executable_files_and_parse_failures_do_not_disappear() {
let temp = fixture("struct S; trait T { fn declaration(); }");
let root = temp.path();
fs::write(root.join("driver.rs"), "fn driver() {}").unwrap();
let mut p = process(root, &[], 1);
p.lines.insert("driver.rs".into(), BTreeMap::from([(1, 1)]));
p.functions.as_mut().unwrap().push(FunctionExecution {
file: "driver.rs".into(),
line: 1,
column: 1,
count: 1,
});
record(root, "driver", 1, "same", vec![p]);
let result = report(root);
assert!(result.passed, "{}", result.text);
assert!(
result
.text
.contains("code.rs: no executable obligations — pass"),
"{}",
result.text
);
fs::write(root.join("code.rs"), "fn missing() {}").unwrap();
let mut p = process(root, &[], 1);
p.functions = Some(vec![]);
p.lines.insert("driver.rs".into(), BTreeMap::from([(1, 1)]));
p.functions.as_mut().unwrap().push(FunctionExecution {
file: "driver.rs".into(),
line: 1,
column: 1,
count: 1,
});
record(root, "driver", 2, "same", vec![p.clone()]);
let result = report(root);
assert!(result.text.contains("code.rs: not measured — FAIL"));
assert!(result.text.contains("#fn[missing]: not measured"));
fs::write(root.join("code.rs"), "fn malformed(").unwrap();
record(root, "driver", 3, "same", vec![p]);
let result = report(root);
assert!(!result.passed);
assert!(
result
.text
.to_lowercase()
.contains("cannot parse rust source"),
"{}",
result.text
);
}
Input 11: outline src/execution_coverage/check.rs mod[tests]/fn[methods_tests_and_helpers_are_included_and_discovery_failures_are_reported]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[methods_tests_and_helpers_are_included_and_discovery_failures_are_reported] - Kind:
fn src/execution_coverage/check.rs:1776–1807
// {test}`requirements.test-coverage.check.scope`
// {test}`requirements.test-coverage.check.functions`
#[test]
fn methods_tests_and_helpers_are_included_and_discovery_failures_are_reported() {
let source = "struct S;\nimpl S { fn method(&self) {} }\n#[cfg(test)] mod tests {\n #[test] fn case() {}\n fn helper() {}\n}\n";
let temp = fixture(source);
let root = temp.path();
record(root, "a", 1, "same", vec![process(root, &[(1, 1)], 0)]);
let result = report(root);
for selector in [
"impl[S]/fn[method]",
"mod[tests]/fn[case]",
"mod[tests]/fn[helper]",
] {
assert!(
result
.text
.contains(&format!("#{selector}: zero execution")),
"{}",
result.text
);
}
git2::Repository::init(root).unwrap();
fs::write(root.join(".git/index"), "corrupt Git index").unwrap();
let result = report(root);
assert!(!result.passed);
assert!(
result.text.contains("cannot discover reference sources"),
"{}",
result.text
);
}
Input 12: outline tests/execution_coverage.rs fn[full_test_flow_checks_real_function_counters_after_all_tests]
- File:
tests/execution_coverage.rs - Selector:
fn[full_test_flow_checks_real_function_counters_after_all_tests] - Kind:
fn tests/execution_coverage.rs:364–444
// {test}`requirements.test-coverage.test`
// {test}`requirements.test-coverage.check`
// {test}`requirements.test-coverage.check.functions`
// {test}`requirements.test-coverage.check.guidance`
#[test]
fn full_test_flow_checks_real_function_counters_after_all_tests() {
let temp = fixture();
let root = temp.path();
let (requests, stop, server) = model_tripwire(root);
fs::create_dir(root.join("evidence")).unwrap();
fs::write(root.join("evidence/sentinel.txt"), "existing evidence").unwrap();
let original_evidence = retained_files(&root.join("evidence"));
let nextest = root.join(".config/nextest.toml");
let mut configuration = fs::read_to_string(&nextest)
.unwrap()
.parse::<toml_edit::DocumentMut>()
.unwrap();
configuration["profile"]["default"]["default-filter"] = toml_edit::value("kind(lib)");
fs::write(nextest, configuration.to_string()).unwrap();
let manifest = fs::read_to_string(root.join("Cargo.toml")).unwrap();
fs::write(
root.join("Cargo.toml"),
format!("{manifest}\n[dev-dependencies]\ntokio = {{ version = '1', features = ['macros', 'rt'] }}\n"),
)
.unwrap();
fs::write(root.join("src/lib.rs"), "pub fn value(flag: bool) -> u32 {\n if flag { 10 } else { 20 }\n}\n#[cfg(test)] #[test] fn a() { assert_eq!(value(true), 10); }\n#[cfg(test)] #[test] fn b() { assert_eq!(value(false), 20); }\n#[cfg(test)] #[tokio::test] async fn asynchronous() { assert_eq!(value(true), 10); }\n").unwrap();
fs::write(
root.join("tests/processes.rs"),
"#[test] fn integration() { assert_eq!(coverage_fixture::value(true),10); }\n",
)
.unwrap();
let output = full_flow(root);
assert_success(&output);
assert!(String::from_utf8_lossy(&output.stdout).contains("Coverage check passed"));
let checked = saved_check(root);
assert_success(&checked);
assert!(String::from_utf8_lossy(&checked.stdout).contains("Coverage check passed"));
assert_eq!(retained_files(&root.join("evidence")), original_evidence);
let saved = runs(root);
assert_eq!(saved.len(), 1);
assert_eq!(
attempts(&saved[0].0).len(),
4,
"the full workspace includes sync and async unit tests AND integration targets"
);
for attempt in attempts(&saved[0].0) {
for process in attempt["processes"].as_array().unwrap() {
assert!(
process["functions"]
.as_array()
.is_some_and(|functions| !functions.is_empty())
);
}
}
fs::write(root.join("src/lib.rs"), "pub fn value(flag: bool) -> u32 { if flag { 10 } else { 20 } }\npub fn outer() { fn hidden() {} let f = || {}; f(); }\n#[cfg(test)] #[test] fn a() { value(true); outer(); }\n#[cfg(test)] #[test] fn b() { value(false); }\n#[cfg(test)] #[tokio::test] async fn asynchronous() { assert_eq!(value(true), 10); }\n").unwrap();
let output = full_flow(root);
assert!(!output.status.success());
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
stdout.contains("#fn[outer]/fn[hidden]: zero execution"),
"{stdout}\n{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(!stdout.contains("#fn[outer]: zero execution"), "{stdout}");
assert_eq!(
runs(root).last().unwrap().1["outcome"],
"success",
"tests succeeded; the policy caused failure"
);
let checked = saved_check(root);
assert!(!checked.status.success());
assert!(String::from_utf8_lossy(&checked.stdout).contains("Coverage check failed"));
assert_eq!(retained_files(&root.join("evidence")), original_evidence);
stop.send(()).unwrap();
server.join().unwrap();
assert_eq!(
requests.load(std::sync::atomic::Ordering::SeqCst),
0,
"verification must never call a model"
);
}
Referenced definitions
Input 2: requirements selection requirements.test-coverage.check.scope
requirements.test-coverage.check.scope:md/requirements/test-coverage.md:568–580
:::{req} check.scope
The coverage check MUST consider every explicitly declared function or method
with a body in the first-party Rust sources of
{cite}`requirements.references.rust_item_coverage`, including test functions,
test helpers, and default trait methods. Declarations without bodies MUST NOT
create execution-coverage obligations. Source discovery or parsing failures
MUST cause the check to fail rather than silently omit functions.
A function whose measurement cannot be established MUST be reported as not
measured rather than silently excluded. Functions excluded by the selected
build configuration require exception evidence under
{cite}`requirements.test-coverage.check.exceptions`.
:::
Input 3: requirements selection requirements.test-coverage.check.exceptions
requirements.test-coverage.check.exceptions:md/requirements/test-coverage.md:635–651
:::{req} check.exceptions
An unmet file threshold or an unexecuted or not-measured function MAY satisfy
the coverage policy only
through current, accepted, independently assessed evidence explaining why its
coverage is incomplete. An exception MUST be attached to the source file or
function whose incomplete coverage it justifies. A file-threshold exception
MUST NOT automatically excuse untested functions.
An exception MUST NOT excuse another source item's incomplete coverage.
Changes to the source item, justification, or other inputs
of its citation review MUST invalidate the affected exception under
{cite}`requirements.references.citation_review`.
A source comment or unassessed justification alone MUST NOT count as accepted
exception evidence. Function and gap identities MUST remain portable between
equivalent local and CI checkouts rather than depend on checkout paths,
run identifiers, timestamps, or process identifiers.
:::
Input 4: requirements selection requirements.test-coverage.check.threshold
requirements.test-coverage.check.threshold:md/requirements/test-coverage.md:582–603
:::{req} check.threshold
Each first-party Rust file under
{cite}`requirements.references.rust_item_coverage` MUST have at least 80%
execution coverage of its instrumented lines, or current accepted exception
evidence explaining why the file falls below that target under
{cite}`requirements.test-coverage.check.exceptions`. Counts MUST use the
file-and-line union rule of {cite}`requirements.test-coverage.index.summary`;
a line counts as executed when any eligible test process or its associated
child processes has a positive execution count for it.
The check MUST use the combined selection and freshness rules of
{cite}`requirements.test-coverage.index.selection` and
{cite}`requirements.test-coverage.index.freshness`, restricted to the active
build configuration. It MUST compare exact counts rather than rounded displayed
percentages, average file percentages, or impose an 80% target within each
function. A file whose executable code is not measured MUST require exception
evidence rather than pass with a fabricated percentage. A file established to
contain no executable coverage obligations MUST be reported as such and MUST
NOT require a threshold exception.
Absence of recorded instrumented lines alone MUST NOT establish that a file
contains no executable coverage obligations.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.check.functions
requirements.test-coverage.check.functions:md/requirements/test-coverage.md:605–616
:::{req} check.functions
Every function under {cite}`requirements.test-coverage.check.scope` without
recorded execution attributable to it MUST have current accepted exception
evidence under {cite}`requirements.test-coverage.check.exceptions`, even when
its containing file meets the target of
{cite}`requirements.test-coverage.check.threshold`.
Execution attributable only to another function, including a nested function
or closure, MUST NOT establish coverage of the enclosing function merely
because their source locations overlap. Having no recorded lines alone MUST
NOT establish that a function has no executable coverage obligations.
:::