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,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)

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| |}

View File

@ -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();
}