Skip to content

Commit 9b2c58d

Browse files
committedJul 8, 2024
coverage: Test for handling of nested item spans
1 parent 7fdefb8 commit 9b2c58d

File tree

3 files changed

+179
-0
lines changed

3 files changed

+179
-0
lines changed
 

‎tests/coverage/holes.cov-map

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Function name: <holes::main::MyStruct>::_method (unused)
2+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 25, 09, 00, 1d]
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(Zero) at (prev + 37, 9) to (start + 0, 29)
8+
9+
Function name: holes::main
10+
Raw bytes (19): 0x[01, 01, 00, 03, 01, 08, 01, 06, 11, 01, 0f, 05, 24, 0f, 01, 2b, 05, 01, 02]
11+
Number of files: 1
12+
- file 0 => global file 1
13+
Number of expressions: 0
14+
Number of file 0 mappings: 3
15+
- Code(Counter(0)) at (prev + 8, 1) to (start + 6, 17)
16+
- Code(Counter(0)) at (prev + 15, 5) to (start + 36, 15)
17+
- Code(Counter(0)) at (prev + 43, 5) to (start + 1, 2)
18+
19+
Function name: holes::main::_unused_fn (unused)
20+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 19, 05, 00, 17]
21+
Number of files: 1
22+
- file 0 => global file 1
23+
Number of expressions: 0
24+
Number of file 0 mappings: 1
25+
- Code(Zero) at (prev + 25, 5) to (start + 0, 23)
26+
27+
Function name: holes::main::{closure#0} (unused)
28+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 12, 09, 02, 0a]
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 + 18, 9) to (start + 2, 10)
34+
35+
Function name: holes::main::{closure#1} (unused)
36+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 3d, 09, 02, 0a]
37+
Number of files: 1
38+
- file 0 => global file 1
39+
Number of expressions: 0
40+
Number of file 0 mappings: 1
41+
- Code(Zero) at (prev + 61, 9) to (start + 2, 10)
42+

‎tests/coverage/holes.coverage

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
LL| |//@ edition: 2021
2+
LL| |
3+
LL| |// Nested items/closures should be treated as "holes", so that their spans are
4+
LL| |// not displayed as executable code in the enclosing function.
5+
LL| |
6+
LL| |use core::hint::black_box;
7+
LL| |
8+
LL| 1|fn main() {
9+
LL| 1| black_box(());
10+
LL| 1|
11+
LL| 1| // Splitting this across multiple lines makes it easier to see where the
12+
LL| 1| // coverage mapping regions begin and end.
13+
LL| 1| #[rustfmt::skip]
14+
LL| 1| let _closure =
15+
LL| | |
16+
LL| | _arg: (),
17+
LL| | |
18+
LL| 0| {
19+
LL| 0| black_box(());
20+
LL| 0| }
21+
LL| | ;
22+
LL| |
23+
LL| 1| black_box(());
24+
LL| 1|
25+
LL| 1| fn _unused_fn() {}
26+
^0
27+
LL| 1|
28+
LL| 1| black_box(());
29+
LL| 1|
30+
LL| 1| struct MyStruct {
31+
LL| 1| _x: u32,
32+
LL| 1| _y: u32,
33+
LL| 1| }
34+
LL| 1|
35+
LL| 1| black_box(());
36+
LL| 1|
37+
LL| 1| impl MyStruct {
38+
LL| 1| fn _method(&self) {}
39+
^0
40+
LL| 1| }
41+
LL| 1|
42+
LL| 1| black_box(());
43+
LL| 1|
44+
LL| 1| macro_rules! _my_macro {
45+
LL| 1| () => {};
46+
LL| 1| }
47+
LL| 1|
48+
LL| 1| black_box(());
49+
LL| 1|
50+
LL| 1| #[rustfmt::skip]
51+
LL| 1| let _const =
52+
LL| 1| const
53+
LL| 1| {
54+
LL| 1| 7 + 4
55+
LL| 1| }
56+
LL| 1| ;
57+
LL| 1|
58+
LL| 1| black_box(());
59+
LL| 1|
60+
LL| 1| #[rustfmt::skip]
61+
LL| 1| let _async =
62+
LL| | async
63+
LL| 0| {
64+
LL| 0| 7 + 4
65+
LL| 0| }
66+
LL| | ;
67+
LL| |
68+
LL| 1| black_box(());
69+
LL| 1|}
70+

‎tests/coverage/holes.rs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//@ edition: 2021
2+
3+
// Nested items/closures should be treated as "holes", so that their spans are
4+
// not displayed as executable code in the enclosing function.
5+
6+
use core::hint::black_box;
7+
8+
fn main() {
9+
black_box(());
10+
11+
// Splitting this across multiple lines makes it easier to see where the
12+
// coverage mapping regions begin and end.
13+
#[rustfmt::skip]
14+
let _closure =
15+
|
16+
_arg: (),
17+
|
18+
{
19+
black_box(());
20+
}
21+
;
22+
23+
black_box(());
24+
25+
fn _unused_fn() {}
26+
27+
black_box(());
28+
29+
struct MyStruct {
30+
_x: u32,
31+
_y: u32,
32+
}
33+
34+
black_box(());
35+
36+
impl MyStruct {
37+
fn _method(&self) {}
38+
}
39+
40+
black_box(());
41+
42+
macro_rules! _my_macro {
43+
() => {};
44+
}
45+
46+
black_box(());
47+
48+
#[rustfmt::skip]
49+
let _const =
50+
const
51+
{
52+
7 + 4
53+
}
54+
;
55+
56+
black_box(());
57+
58+
#[rustfmt::skip]
59+
let _async =
60+
async
61+
{
62+
7 + 4
63+
}
64+
;
65+
66+
black_box(());
67+
}

0 commit comments

Comments
 (0)
Please sign in to comment.