rust/tests/coverage/attr/nested.coverage
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

112 lines
3.9 KiB
Plaintext

LL| |#![feature(coverage_attribute, stmt_expr_attributes)]
LL| |//@ edition: 2021
LL| |
LL| |// Demonstrates the interaction between #[coverage(off)] and various kinds of
LL| |// nested function.
LL| |
LL| |// FIXME(#126625): Coverage attributes should apply recursively to nested functions.
LL| |// FIXME(#126626): When an inner (non-closure) function has `#[coverage(off)]`,
LL| |// its lines can still be marked with misleading execution counts from its enclosing
LL| |// function.
LL| |
LL| |#[coverage(off)]
LL| |fn do_stuff() {}
LL| |
LL| |#[coverage(off)]
LL| |fn outer_fn() {
LL| 0| fn middle_fn() {
LL| 0| fn inner_fn() {
LL| 0| do_stuff();
LL| 0| }
LL| 0| do_stuff();
LL| 0| }
LL| | do_stuff();
LL| |}
LL| |
LL| |struct MyOuter;
LL| |impl MyOuter {
LL| | #[coverage(off)]
LL| | fn outer_method(&self) {
LL| | struct MyMiddle;
LL| | impl MyMiddle {
LL| 0| fn middle_method(&self) {
LL| 0| struct MyInner;
LL| 0| impl MyInner {
LL| 0| fn inner_method(&self) {
LL| 0| do_stuff();
LL| 0| }
LL| 0| }
LL| 0| do_stuff();
LL| 0| }
LL| | }
LL| | do_stuff();
LL| | }
LL| |}
LL| |
LL| |trait MyTrait {
LL| | fn trait_method(&self);
LL| |}
LL| |impl MyTrait for MyOuter {
LL| | #[coverage(off)]
LL| | fn trait_method(&self) {
LL| | struct MyMiddle;
LL| | impl MyTrait for MyMiddle {
LL| 0| fn trait_method(&self) {
LL| 0| struct MyInner;
LL| 0| impl MyTrait for MyInner {
LL| 0| fn trait_method(&self) {
LL| 0| do_stuff();
LL| 0| }
LL| 0| }
LL| 0| do_stuff();
LL| 0| }
LL| | }
LL| | do_stuff();
LL| | }
LL| |}
LL| |
LL| 1|fn closure_expr() {
LL| 1| let _outer = #[coverage(off)]
LL| | || {
LL| 0| let _middle = || {
LL| 0| let _inner = || {
LL| 0| do_stuff();
LL| 0| };
LL| 0| do_stuff();
LL| 0| };
LL| | do_stuff();
LL| | };
LL| 1| do_stuff();
LL| 1|}
LL| |
LL| |// This syntax is allowed, even without #![feature(stmt_expr_attributes)].
LL| 1|fn closure_tail() {
LL| 1| let _outer = {
LL| | #[coverage(off)]
LL| | || {
LL| | let _middle = {
LL| 0| || {
LL| 0| let _inner = {
LL| 0| || {
LL| 0| do_stuff();
LL| 0| }
LL| | };
LL| 0| do_stuff();
LL| 0| }
LL| | };
LL| | do_stuff();
LL| | }
LL| | };
LL| 1| do_stuff();
LL| 1|}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | outer_fn();
LL| | MyOuter.outer_method();
LL| | MyOuter.trait_method();
LL| | closure_expr();
LL| | closure_tail();
LL| |}