Skip to content

Commit 062312d

Browse files
committed
Add more thorough coverage tests for #[coverage(..)] in nested functions
These tests reflect the current implementation behaviour, which is not necessarily the desired behaviour.
1 parent 8e07a9f commit 062312d

File tree

6 files changed

+448
-0
lines changed

6 files changed

+448
-0
lines changed

tests/coverage/attr/nested.cov-map

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
Function name: <<<nested::MyOuter as nested::MyTrait>::trait_method::MyMiddle as nested::MyTrait>::trait_method::MyInner as nested::MyTrait>::trait_method (unused)
2+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 34, 15, 02, 16]
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 + 52, 21) to (start + 2, 22)
8+
9+
Function name: <<<nested::MyOuter>::outer_method::MyMiddle>::middle_method::MyInner>::inner_method (unused)
10+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 1e, 15, 02, 16]
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 + 30, 21) to (start + 2, 22)
16+
17+
Function name: <<nested::MyOuter as nested::MyTrait>::trait_method::MyMiddle as nested::MyTrait>::trait_method (unused)
18+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 31, 0d, 08, 0e]
19+
Number of files: 1
20+
- file 0 => global file 1
21+
Number of expressions: 0
22+
Number of file 0 mappings: 1
23+
- Code(Zero) at (prev + 49, 13) to (start + 8, 14)
24+
25+
Function name: <<nested::MyOuter>::outer_method::MyMiddle>::middle_method (unused)
26+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 1b, 0d, 08, 0e]
27+
Number of files: 1
28+
- file 0 => global file 1
29+
Number of expressions: 0
30+
Number of file 0 mappings: 1
31+
- Code(Zero) at (prev + 27, 13) to (start + 8, 14)
32+
33+
Function name: nested::closure_expr
34+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 3f, 01, 01, 0f, 01, 0b, 05, 01, 02]
35+
Number of files: 1
36+
- file 0 => global file 1
37+
Number of expressions: 0
38+
Number of file 0 mappings: 2
39+
- Code(Counter(0)) at (prev + 63, 1) to (start + 1, 15)
40+
- Code(Counter(0)) at (prev + 11, 5) to (start + 1, 2)
41+
42+
Function name: nested::closure_expr::{closure#0}::{closure#0} (unused)
43+
Raw bytes (14): 0x[01, 01, 00, 02, 00, 42, 1a, 01, 17, 00, 04, 0d, 01, 0a]
44+
Number of files: 1
45+
- file 0 => global file 1
46+
Number of expressions: 0
47+
Number of file 0 mappings: 2
48+
- Code(Zero) at (prev + 66, 26) to (start + 1, 23)
49+
- Code(Zero) at (prev + 4, 13) to (start + 1, 10)
50+
51+
Function name: nested::closure_expr::{closure#0}::{closure#0}::{closure#0} (unused)
52+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 43, 1d, 02, 0e]
53+
Number of files: 1
54+
- file 0 => global file 1
55+
Number of expressions: 0
56+
Number of file 0 mappings: 1
57+
- Code(Zero) at (prev + 67, 29) to (start + 2, 14)
58+
59+
Function name: nested::closure_tail
60+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 4e, 01, 01, 0f, 01, 11, 05, 01, 02]
61+
Number of files: 1
62+
- file 0 => global file 1
63+
Number of expressions: 0
64+
Number of file 0 mappings: 2
65+
- Code(Counter(0)) at (prev + 78, 1) to (start + 1, 15)
66+
- Code(Counter(0)) at (prev + 17, 5) to (start + 1, 2)
67+
68+
Function name: nested::closure_tail::{closure#0}::{closure#0} (unused)
69+
Raw bytes (14): 0x[01, 01, 00, 02, 00, 53, 14, 01, 1f, 00, 06, 15, 01, 12]
70+
Number of files: 1
71+
- file 0 => global file 1
72+
Number of expressions: 0
73+
Number of file 0 mappings: 2
74+
- Code(Zero) at (prev + 83, 20) to (start + 1, 31)
75+
- Code(Zero) at (prev + 6, 21) to (start + 1, 18)
76+
77+
Function name: nested::closure_tail::{closure#0}::{closure#0}::{closure#0} (unused)
78+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 55, 1c, 02, 1a]
79+
Number of files: 1
80+
- file 0 => global file 1
81+
Number of expressions: 0
82+
Number of file 0 mappings: 1
83+
- Code(Zero) at (prev + 85, 28) to (start + 2, 26)
84+
85+
Function name: nested::outer_fn::middle_fn (unused)
86+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 0c, 05, 05, 06]
87+
Number of files: 1
88+
- file 0 => global file 1
89+
Number of expressions: 0
90+
Number of file 0 mappings: 1
91+
- Code(Zero) at (prev + 12, 5) to (start + 5, 6)
92+
93+
Function name: nested::outer_fn::middle_fn::inner_fn (unused)
94+
Raw bytes (9): 0x[01, 01, 00, 01, 00, 0d, 09, 02, 0a]
95+
Number of files: 1
96+
- file 0 => global file 1
97+
Number of expressions: 0
98+
Number of file 0 mappings: 1
99+
- Code(Zero) at (prev + 13, 9) to (start + 2, 10)
100+

tests/coverage/attr/nested.coverage

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
LL| |#![feature(coverage_attribute, stmt_expr_attributes)]
2+
LL| |//@ edition: 2021
3+
LL| |
4+
LL| |// Demonstrates the interaction between #[coverage(off)] and various kinds of
5+
LL| |// nested function.
6+
LL| |
7+
LL| |#[coverage(off)]
8+
LL| |fn do_stuff() {}
9+
LL| |
10+
LL| |#[coverage(off)]
11+
LL| |fn outer_fn() {
12+
LL| 0| fn middle_fn() {
13+
LL| 0| fn inner_fn() {
14+
LL| 0| do_stuff();
15+
LL| 0| }
16+
LL| 0| do_stuff();
17+
LL| 0| }
18+
LL| | do_stuff();
19+
LL| |}
20+
LL| |
21+
LL| |struct MyOuter;
22+
LL| |impl MyOuter {
23+
LL| | #[coverage(off)]
24+
LL| | fn outer_method(&self) {
25+
LL| | struct MyMiddle;
26+
LL| | impl MyMiddle {
27+
LL| 0| fn middle_method(&self) {
28+
LL| 0| struct MyInner;
29+
LL| 0| impl MyInner {
30+
LL| 0| fn inner_method(&self) {
31+
LL| 0| do_stuff();
32+
LL| 0| }
33+
LL| 0| }
34+
LL| 0| do_stuff();
35+
LL| 0| }
36+
LL| | }
37+
LL| | do_stuff();
38+
LL| | }
39+
LL| |}
40+
LL| |
41+
LL| |trait MyTrait {
42+
LL| | fn trait_method(&self);
43+
LL| |}
44+
LL| |impl MyTrait for MyOuter {
45+
LL| | #[coverage(off)]
46+
LL| | fn trait_method(&self) {
47+
LL| | struct MyMiddle;
48+
LL| | impl MyTrait for MyMiddle {
49+
LL| 0| fn trait_method(&self) {
50+
LL| 0| struct MyInner;
51+
LL| 0| impl MyTrait for MyInner {
52+
LL| 0| fn trait_method(&self) {
53+
LL| 0| do_stuff();
54+
LL| 0| }
55+
LL| 0| }
56+
LL| 0| do_stuff();
57+
LL| 0| }
58+
LL| | }
59+
LL| | do_stuff();
60+
LL| | }
61+
LL| |}
62+
LL| |
63+
LL| 1|fn closure_expr() {
64+
LL| 1| let _outer = #[coverage(off)]
65+
LL| | || {
66+
LL| 0| let _middle = || {
67+
LL| 0| let _inner = || {
68+
LL| 0| do_stuff();
69+
LL| 0| };
70+
LL| 0| do_stuff();
71+
LL| 0| };
72+
LL| | do_stuff();
73+
LL| | };
74+
LL| 1| do_stuff();
75+
LL| 1|}
76+
LL| |
77+
LL| |// This syntax is allowed, even without #![feature(stmt_expr_attributes)].
78+
LL| 1|fn closure_tail() {
79+
LL| 1| let _outer = {
80+
LL| | #[coverage(off)]
81+
LL| | || {
82+
LL| | let _middle = {
83+
LL| 0| || {
84+
LL| 0| let _inner = {
85+
LL| 0| || {
86+
LL| 0| do_stuff();
87+
LL| 0| }
88+
LL| | };
89+
LL| 0| do_stuff();
90+
LL| 0| }
91+
LL| | };
92+
LL| | do_stuff();
93+
LL| | }
94+
LL| | };
95+
LL| 1| do_stuff();
96+
LL| 1|}
97+
LL| |
98+
LL| |#[coverage(off)]
99+
LL| |fn main() {
100+
LL| | outer_fn();
101+
LL| | MyOuter.outer_method();
102+
LL| | MyOuter.trait_method();
103+
LL| | closure_expr();
104+
LL| | closure_tail();
105+
LL| |}
106+

tests/coverage/attr/nested.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#![feature(coverage_attribute, stmt_expr_attributes)]
2+
//@ edition: 2021
3+
4+
// Demonstrates the interaction between #[coverage(off)] and various kinds of
5+
// nested function.
6+
7+
#[coverage(off)]
8+
fn do_stuff() {}
9+
10+
#[coverage(off)]
11+
fn outer_fn() {
12+
fn middle_fn() {
13+
fn inner_fn() {
14+
do_stuff();
15+
}
16+
do_stuff();
17+
}
18+
do_stuff();
19+
}
20+
21+
struct MyOuter;
22+
impl MyOuter {
23+
#[coverage(off)]
24+
fn outer_method(&self) {
25+
struct MyMiddle;
26+
impl MyMiddle {
27+
fn middle_method(&self) {
28+
struct MyInner;
29+
impl MyInner {
30+
fn inner_method(&self) {
31+
do_stuff();
32+
}
33+
}
34+
do_stuff();
35+
}
36+
}
37+
do_stuff();
38+
}
39+
}
40+
41+
trait MyTrait {
42+
fn trait_method(&self);
43+
}
44+
impl MyTrait for MyOuter {
45+
#[coverage(off)]
46+
fn trait_method(&self) {
47+
struct MyMiddle;
48+
impl MyTrait for MyMiddle {
49+
fn trait_method(&self) {
50+
struct MyInner;
51+
impl MyTrait for MyInner {
52+
fn trait_method(&self) {
53+
do_stuff();
54+
}
55+
}
56+
do_stuff();
57+
}
58+
}
59+
do_stuff();
60+
}
61+
}
62+
63+
fn closure_expr() {
64+
let _outer = #[coverage(off)]
65+
|| {
66+
let _middle = || {
67+
let _inner = || {
68+
do_stuff();
69+
};
70+
do_stuff();
71+
};
72+
do_stuff();
73+
};
74+
do_stuff();
75+
}
76+
77+
// This syntax is allowed, even without #![feature(stmt_expr_attributes)].
78+
fn closure_tail() {
79+
let _outer = {
80+
#[coverage(off)]
81+
|| {
82+
let _middle = {
83+
|| {
84+
let _inner = {
85+
|| {
86+
do_stuff();
87+
}
88+
};
89+
do_stuff();
90+
}
91+
};
92+
do_stuff();
93+
}
94+
};
95+
do_stuff();
96+
}
97+
98+
#[coverage(off)]
99+
fn main() {
100+
outer_fn();
101+
MyOuter.outer_method();
102+
MyOuter.trait_method();
103+
closure_expr();
104+
closure_tail();
105+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Function name: off_on_sandwich::dense_a::dense_b
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0f, 05, 07, 06]
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 + 15, 5) to (start + 7, 6)
8+
9+
Function name: off_on_sandwich::sparse_a::sparse_b
10+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 1d, 05, 10, 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(Counter(0)) at (prev + 29, 5) to (start + 16, 6)
16+
17+
Function name: off_on_sandwich::sparse_a::sparse_b::sparse_c
18+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 21, 09, 0b, 0a]
19+
Number of files: 1
20+
- file 0 => global file 1
21+
Number of expressions: 0
22+
Number of file 0 mappings: 1
23+
- Code(Counter(0)) at (prev + 33, 9) to (start + 11, 10)
24+
25+
Function name: off_on_sandwich::sparse_a::sparse_b::sparse_c::sparse_d
26+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 24, 0d, 07, 0e]
27+
Number of files: 1
28+
- file 0 => global file 1
29+
Number of expressions: 0
30+
Number of file 0 mappings: 1
31+
- Code(Counter(0)) at (prev + 36, 13) to (start + 7, 14)
32+

0 commit comments

Comments
 (0)