rust/tests/coverage/attr/off-on-sandwich.rs
Zalathar 5093658632 Add more thorough coverage tests for #[coverage(..)] in nested functions
These tests reflect the current implementation behaviour, which is not
necessarily the desired behaviour.
2024-06-18 21:27:34 +10:00

58 lines
1.2 KiB
Rust

#![feature(coverage_attribute)]
//@ edition: 2021
// Demonstrates the interaction of `#[coverage(off)]` and `#[coverage(on)]`
// in nested functions.
// FIXME(#126625): Coverage attributes should apply recursively to nested functions.
// FIXME(#126626): When an inner (non-closure) function has `#[coverage(off)]`,
// its lines can still be marked with misleading execution counts from its enclosing
// function.
#[coverage(off)]
fn do_stuff() {}
#[coverage(off)]
fn dense_a() {
dense_b();
dense_b();
#[coverage(on)]
fn dense_b() {
dense_c();
dense_c();
#[coverage(off)]
fn dense_c() {
do_stuff();
}
}
}
#[coverage(off)]
fn sparse_a() {
sparse_b();
sparse_b();
fn sparse_b() {
sparse_c();
sparse_c();
#[coverage(on)]
fn sparse_c() {
sparse_d();
sparse_d();
fn sparse_d() {
sparse_e();
sparse_e();
#[coverage(off)]
fn sparse_e() {
do_stuff();
}
}
}
}
}
#[coverage(off)]
fn main() {
dense_a();
sparse_a();
}