1
Fork 0

coverage: Add a test for #[coverage(..)] on closures

This commit is contained in:
Zalathar 2024-01-20 18:23:49 +11:00
parent fe420dc46e
commit 8dd2b37462
3 changed files with 119 additions and 0 deletions

View file

@ -0,0 +1,43 @@
LL| |#![feature(coverage_attribute, stmt_expr_attributes)]
LL| |#![allow(dead_code)]
LL| |// edition: 2021
LL| |
LL| |static GLOBAL_CLOSURE_ON: fn(&str) = #[coverage(on)]
LL| 0||input: &str| {
LL| 0| println!("{input}");
LL| 0|};
LL| |static GLOBAL_CLOSURE_OFF: fn(&str) = #[coverage(off)]
LL| ||input: &str| {
LL| | println!("{input}");
LL| |};
LL| |
LL| |#[coverage(on)]
LL| 1|fn contains_closures_on() {
LL| 1| let _local_closure_on = #[coverage(on)]
LL| 1| |input: &str| {
LL| 0| println!("{input}");
LL| 1| };
LL| 1| let _local_closure_off = #[coverage(off)]
LL| 1| |input: &str| {
LL| | println!("{input}");
LL| 1| };
LL| 1|}
LL| |
LL| |#[coverage(off)]
LL| |fn contains_closures_off() {
LL| | let _local_closure_on = #[coverage(on)]
LL| 0| |input: &str| {
LL| 0| println!("{input}");
LL| 0| };
LL| | let _local_closure_off = #[coverage(off)]
LL| | |input: &str| {
LL| | println!("{input}");
LL| | };
LL| |}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | contains_closures_on();
LL| | contains_closures_off();
LL| |}