Skip to content

Commit

Permalink
coverage: Add a test for #[coverage(..)] on closures
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Feb 2, 2024
1 parent c9c049b commit f95e730
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/coverage/coverage_attr_closure.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Function name: coverage_attr_closure::GLOBAL_CLOSURE_ON::{closure#0}
Raw bytes (9): 0x[01, 01, 00, 01, 01, 06, 0f, 02, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 6, 15) to (start + 2, 2)

Function name: coverage_attr_closure::contains_closures_off::{closure#0} (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 1d, 13, 02, 06]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 29, 19) to (start + 2, 6)

Function name: coverage_attr_closure::contains_closures_on
Raw bytes (19): 0x[01, 01, 00, 03, 01, 0f, 01, 02, 05, 01, 04, 06, 02, 05, 01, 04, 06, 01, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 3
- Code(Counter(0)) at (prev + 15, 1) to (start + 2, 5)
- Code(Counter(0)) at (prev + 4, 6) to (start + 2, 5)
- Code(Counter(0)) at (prev + 4, 6) to (start + 1, 2)

Function name: coverage_attr_closure::contains_closures_on::{closure#0} (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 11, 13, 02, 06]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 17, 19) to (start + 2, 6)

43 changes: 43 additions & 0 deletions tests/coverage/coverage_attr_closure.coverage
Original file line number Diff line number Diff line change
@@ -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| |}

42 changes: 42 additions & 0 deletions tests/coverage/coverage_attr_closure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#![feature(coverage_attribute, stmt_expr_attributes)]
#![allow(dead_code)]
// edition: 2021

static GLOBAL_CLOSURE_ON: fn(&str) = #[coverage(on)]
|input: &str| {
println!("{input}");
};
static GLOBAL_CLOSURE_OFF: fn(&str) = #[coverage(off)]
|input: &str| {
println!("{input}");
};

#[coverage(on)]
fn contains_closures_on() {
let _local_closure_on = #[coverage(on)]
|input: &str| {
println!("{input}");
};
let _local_closure_off = #[coverage(off)]
|input: &str| {
println!("{input}");
};
}

#[coverage(off)]
fn contains_closures_off() {
let _local_closure_on = #[coverage(on)]
|input: &str| {
println!("{input}");
};
let _local_closure_off = #[coverage(off)]
|input: &str| {
println!("{input}");
};
}

#[coverage(off)]
fn main() {
contains_closures_on();
contains_closures_off();
}

0 comments on commit f95e730

Please sign in to comment.