Skip to content

Commit f95e730

Browse files
committed
coverage: Add a test for #[coverage(..)] on closures
1 parent c9c049b commit f95e730

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Function name: coverage_attr_closure::GLOBAL_CLOSURE_ON::{closure#0}
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 06, 0f, 02, 02]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 0
6+
Number of file 0 mappings: 1
7+
- Code(Counter(0)) at (prev + 6, 15) to (start + 2, 2)
8+
9+
Function name: coverage_attr_closure::contains_closures_off::{closure#0} (unused)
10+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 1d, 13, 02, 06]
11+
Number of files: 1
12+
- file 0 => global file 1
13+
Number of expressions: 0
14+
Number of file 0 mappings: 1
15+
- Code(Zero) at (prev + 29, 19) to (start + 2, 6)
16+
17+
Function name: coverage_attr_closure::contains_closures_on
18+
Raw bytes (19): 0x[01, 01, 00, 03, 01, 0f, 01, 02, 05, 01, 04, 06, 02, 05, 01, 04, 06, 01, 02]
19+
Number of files: 1
20+
- file 0 => global file 1
21+
Number of expressions: 0
22+
Number of file 0 mappings: 3
23+
- Code(Counter(0)) at (prev + 15, 1) to (start + 2, 5)
24+
- Code(Counter(0)) at (prev + 4, 6) to (start + 2, 5)
25+
- Code(Counter(0)) at (prev + 4, 6) to (start + 1, 2)
26+
27+
Function name: coverage_attr_closure::contains_closures_on::{closure#0} (unused)
28+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 11, 13, 02, 06]
29+
Number of files: 1
30+
- file 0 => global file 1
31+
Number of expressions: 0
32+
Number of file 0 mappings: 1
33+
- Code(Zero) at (prev + 17, 19) to (start + 2, 6)
34+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
LL| |#![feature(coverage_attribute, stmt_expr_attributes)]
2+
LL| |#![allow(dead_code)]
3+
LL| |// edition: 2021
4+
LL| |
5+
LL| |static GLOBAL_CLOSURE_ON: fn(&str) = #[coverage(on)]
6+
LL| 0||input: &str| {
7+
LL| 0| println!("{input}");
8+
LL| 0|};
9+
LL| |static GLOBAL_CLOSURE_OFF: fn(&str) = #[coverage(off)]
10+
LL| ||input: &str| {
11+
LL| | println!("{input}");
12+
LL| |};
13+
LL| |
14+
LL| |#[coverage(on)]
15+
LL| 1|fn contains_closures_on() {
16+
LL| 1| let _local_closure_on = #[coverage(on)]
17+
LL| 1| |input: &str| {
18+
LL| 0| println!("{input}");
19+
LL| 1| };
20+
LL| 1| let _local_closure_off = #[coverage(off)]
21+
LL| 1| |input: &str| {
22+
LL| | println!("{input}");
23+
LL| 1| };
24+
LL| 1|}
25+
LL| |
26+
LL| |#[coverage(off)]
27+
LL| |fn contains_closures_off() {
28+
LL| | let _local_closure_on = #[coverage(on)]
29+
LL| 0| |input: &str| {
30+
LL| 0| println!("{input}");
31+
LL| 0| };
32+
LL| | let _local_closure_off = #[coverage(off)]
33+
LL| | |input: &str| {
34+
LL| | println!("{input}");
35+
LL| | };
36+
LL| |}
37+
LL| |
38+
LL| |#[coverage(off)]
39+
LL| |fn main() {
40+
LL| | contains_closures_on();
41+
LL| | contains_closures_off();
42+
LL| |}
43+
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![feature(coverage_attribute, stmt_expr_attributes)]
2+
#![allow(dead_code)]
3+
// edition: 2021
4+
5+
static GLOBAL_CLOSURE_ON: fn(&str) = #[coverage(on)]
6+
|input: &str| {
7+
println!("{input}");
8+
};
9+
static GLOBAL_CLOSURE_OFF: fn(&str) = #[coverage(off)]
10+
|input: &str| {
11+
println!("{input}");
12+
};
13+
14+
#[coverage(on)]
15+
fn contains_closures_on() {
16+
let _local_closure_on = #[coverage(on)]
17+
|input: &str| {
18+
println!("{input}");
19+
};
20+
let _local_closure_off = #[coverage(off)]
21+
|input: &str| {
22+
println!("{input}");
23+
};
24+
}
25+
26+
#[coverage(off)]
27+
fn contains_closures_off() {
28+
let _local_closure_on = #[coverage(on)]
29+
|input: &str| {
30+
println!("{input}");
31+
};
32+
let _local_closure_off = #[coverage(off)]
33+
|input: &str| {
34+
println!("{input}");
35+
};
36+
}
37+
38+
#[coverage(off)]
39+
fn main() {
40+
contains_closures_on();
41+
contains_closures_off();
42+
}

0 commit comments

Comments
 (0)