Skip to content

Commit 7b8a6b8

Browse files
committed
Add some simple coverage tests for common constructs
1 parent 9825586 commit 7b8a6b8

34 files changed

Lines changed: 1391 additions & 0 deletions

tests/coverage/assert.cov-map

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
Function name: assert::assert_a_plain
2+
Raw bytes (54): 0x[01, 01, 00, 0a, 01, 06, 01, 00, 25, 01, 01, 05, 00, 0c, 01, 00, 0d, 00, 10, 01, 00, 11, 00, 18, 05, 01, 05, 00, 0f, 09, 01, 05, 00, 0f, 15, 01, 05, 00, 14, 0d, 00, 15, 00, 18, 11, 00, 1f, 00, 25, 15, 01, 01, 00, 02]
3+
Number of files: 1
4+
- file 0 => $DIR/assert.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 10
7+
- Code(Counter(0)) at (prev + 6, 1) to (start + 0, 37)
8+
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 12)
9+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 16)
10+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 24)
11+
- Code(Counter(1)) at (prev + 1, 5) to (start + 0, 15)
12+
- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 15)
13+
- Code(Counter(5)) at (prev + 1, 5) to (start + 0, 20)
14+
- Code(Counter(3)) at (prev + 0, 21) to (start + 0, 24)
15+
- Code(Counter(4)) at (prev + 0, 31) to (start + 0, 37)
16+
- Code(Counter(5)) at (prev + 1, 1) to (start + 0, 2)
17+
Highest counter ID seen: c5
18+
19+
Function name: assert::assert_b_message
20+
Raw bytes (54): 0x[01, 01, 00, 0a, 01, 0d, 01, 00, 27, 01, 01, 05, 00, 0c, 01, 00, 0d, 00, 10, 01, 00, 11, 00, 18, 05, 01, 05, 00, 0f, 09, 01, 05, 00, 0f, 15, 01, 05, 00, 14, 0d, 00, 15, 00, 18, 11, 00, 1f, 00, 25, 15, 01, 01, 00, 02]
21+
Number of files: 1
22+
- file 0 => $DIR/assert.rs
23+
Number of expressions: 0
24+
Number of file 0 mappings: 10
25+
- Code(Counter(0)) at (prev + 13, 1) to (start + 0, 39)
26+
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 12)
27+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 16)
28+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 24)
29+
- Code(Counter(1)) at (prev + 1, 5) to (start + 0, 15)
30+
- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 15)
31+
- Code(Counter(5)) at (prev + 1, 5) to (start + 0, 20)
32+
- Code(Counter(3)) at (prev + 0, 21) to (start + 0, 24)
33+
- Code(Counter(4)) at (prev + 0, 31) to (start + 0, 37)
34+
- Code(Counter(5)) at (prev + 1, 1) to (start + 0, 2)
35+
Highest counter ID seen: c5
36+
37+
Function name: assert::assert_c_format_inline
38+
Raw bytes (54): 0x[01, 01, 00, 0a, 01, 14, 01, 00, 38, 01, 01, 05, 00, 0c, 01, 00, 0d, 00, 10, 01, 00, 11, 00, 18, 05, 01, 05, 00, 0f, 09, 01, 05, 00, 0f, 15, 01, 05, 00, 14, 0d, 00, 15, 00, 18, 11, 00, 1f, 00, 25, 15, 01, 01, 00, 02]
39+
Number of files: 1
40+
- file 0 => $DIR/assert.rs
41+
Number of expressions: 0
42+
Number of file 0 mappings: 10
43+
- Code(Counter(0)) at (prev + 20, 1) to (start + 0, 56)
44+
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 12)
45+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 16)
46+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 24)
47+
- Code(Counter(1)) at (prev + 1, 5) to (start + 0, 15)
48+
- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 15)
49+
- Code(Counter(5)) at (prev + 1, 5) to (start + 0, 20)
50+
- Code(Counter(3)) at (prev + 0, 21) to (start + 0, 24)
51+
- Code(Counter(4)) at (prev + 0, 31) to (start + 0, 37)
52+
- Code(Counter(5)) at (prev + 1, 1) to (start + 0, 2)
53+
Highest counter ID seen: c5
54+
55+
Function name: assert::assert_d_format_arg
56+
Raw bytes (54): 0x[01, 01, 00, 0a, 01, 1b, 01, 00, 35, 01, 01, 05, 00, 0c, 01, 00, 0d, 00, 10, 01, 00, 11, 00, 18, 05, 01, 05, 00, 0f, 09, 01, 05, 00, 0f, 15, 01, 05, 00, 14, 0d, 00, 15, 00, 18, 11, 00, 1f, 00, 25, 15, 01, 01, 00, 02]
57+
Number of files: 1
58+
- file 0 => $DIR/assert.rs
59+
Number of expressions: 0
60+
Number of file 0 mappings: 10
61+
- Code(Counter(0)) at (prev + 27, 1) to (start + 0, 53)
62+
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 12)
63+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 16)
64+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 24)
65+
- Code(Counter(1)) at (prev + 1, 5) to (start + 0, 15)
66+
- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 15)
67+
- Code(Counter(5)) at (prev + 1, 5) to (start + 0, 20)
68+
- Code(Counter(3)) at (prev + 0, 21) to (start + 0, 24)
69+
- Code(Counter(4)) at (prev + 0, 31) to (start + 0, 37)
70+
- Code(Counter(5)) at (prev + 1, 1) to (start + 0, 2)
71+
Highest counter ID seen: c5
72+

tests/coverage/assert.coverage

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2024
3+
LL| |
4+
LL| |use core::assert_matches;
5+
LL| |
6+
LL| 1|fn assert_a_plain(opt: Option<&str>) {
7+
LL| 1| assert!(opt.is_some());
8+
LL| 1| assert_eq!(opt, Some("true"));
9+
LL| 1| assert_ne!(opt, None);
10+
LL| 1| assert_matches!(opt, Some("true"));
11+
LL| 1|}
12+
LL| |
13+
LL| 1|fn assert_b_message(opt: Option<&str>) {
14+
LL| 1| assert!(opt.is_some(), "message");
15+
LL| 1| assert_eq!(opt, Some("true"), "message");
16+
LL| 1| assert_ne!(opt, None, "message");
17+
LL| 1| assert_matches!(opt, Some("true"), "message");
18+
LL| 1|}
19+
LL| |
20+
LL| 1|fn assert_c_format_inline(opt: Option<&str>, msg: &str) {
21+
LL| 1| assert!(opt.is_some(), "message: {msg}");
22+
LL| 1| assert_eq!(opt, Some("true"), "message: {msg}");
23+
LL| 1| assert_ne!(opt, None, "message: {msg}");
24+
LL| 1| assert_matches!(opt, Some("true"), "message: {msg}");
25+
LL| 1|}
26+
LL| |
27+
LL| 1|fn assert_d_format_arg(opt: Option<&str>, msg: &str) {
28+
LL| 1| assert!(opt.is_some(), "message: {}", msg);
29+
LL| 1| assert_eq!(opt, Some("true"), "message: {}", msg);
30+
LL| 1| assert_ne!(opt, None, "message: {}", msg);
31+
LL| 1| assert_matches!(opt, Some("true"), "message: {}", msg);
32+
LL| 1|}
33+
LL| |
34+
LL| |#[coverage(off)]
35+
LL| |fn main() {
36+
LL| | let opt = core::hint::black_box(Some("true"));
37+
LL| | assert_a_plain(opt);
38+
LL| | assert_b_message(opt);
39+
LL| | assert_c_format_inline(opt, "message");
40+
LL| | assert_d_format_arg(opt, "message");
41+
LL| |}
42+

tests/coverage/assert.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2024
3+
4+
use core::assert_matches;
5+
6+
fn assert_a_plain(opt: Option<&str>) {
7+
assert!(opt.is_some());
8+
assert_eq!(opt, Some("true"));
9+
assert_ne!(opt, None);
10+
assert_matches!(opt, Some("true"));
11+
}
12+
13+
fn assert_b_message(opt: Option<&str>) {
14+
assert!(opt.is_some(), "message");
15+
assert_eq!(opt, Some("true"), "message");
16+
assert_ne!(opt, None, "message");
17+
assert_matches!(opt, Some("true"), "message");
18+
}
19+
20+
fn assert_c_format_inline(opt: Option<&str>, msg: &str) {
21+
assert!(opt.is_some(), "message: {msg}");
22+
assert_eq!(opt, Some("true"), "message: {msg}");
23+
assert_ne!(opt, None, "message: {msg}");
24+
assert_matches!(opt, Some("true"), "message: {msg}");
25+
}
26+
27+
fn assert_d_format_arg(opt: Option<&str>, msg: &str) {
28+
assert!(opt.is_some(), "message: {}", msg);
29+
assert_eq!(opt, Some("true"), "message: {}", msg);
30+
assert_ne!(opt, None, "message: {}", msg);
31+
assert_matches!(opt, Some("true"), "message: {}", msg);
32+
}
33+
34+
#[coverage(off)]
35+
fn main() {
36+
let opt = core::hint::black_box(Some("true"));
37+
assert_a_plain(opt);
38+
assert_b_message(opt);
39+
assert_c_format_inline(opt, "message");
40+
assert_d_format_arg(opt, "message");
41+
}

tests/coverage/call-method.cov-map

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Function name: call_method::call_method
2+
Raw bytes (59): 0x[01, 01, 00, 0b, 01, 07, 01, 00, 11, 01, 01, 09, 00, 0e, 01, 00, 11, 00, 16, 01, 02, 05, 00, 0a, 01, 02, 09, 00, 0f, 01, 02, 0d, 00, 12, 01, 04, 05, 05, 0a, 01, 00, 05, 00, 0a, 01, 07, 09, 00, 0f, 01, 02, 0d, 00, 12, 01, 03, 01, 00, 02]
3+
Number of files: 1
4+
- file 0 => $DIR/call-method.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 11
7+
- Code(Counter(0)) at (prev + 7, 1) to (start + 0, 17)
8+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 14)
9+
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 22)
10+
- Code(Counter(0)) at (prev + 2, 5) to (start + 0, 10)
11+
- Code(Counter(0)) at (prev + 2, 9) to (start + 0, 15)
12+
- Code(Counter(0)) at (prev + 2, 13) to (start + 0, 18)
13+
- Code(Counter(0)) at (prev + 4, 5) to (start + 5, 10)
14+
- Code(Counter(0)) at (prev + 0, 5) to (start + 0, 10)
15+
- Code(Counter(0)) at (prev + 7, 9) to (start + 0, 15)
16+
- Code(Counter(0)) at (prev + 2, 13) to (start + 0, 18)
17+
- Code(Counter(0)) at (prev + 3, 1) to (start + 0, 2)
18+
Highest counter ID seen: c0
19+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2024
3+
LL| |
4+
LL| |// Basic test for method calls and chained method calls.
5+
LL| |
6+
LL| |#[rustfmt::skip]
7+
LL| 1|fn call_method() {
8+
LL| 1| let thing = Thing;
9+
LL| |
10+
LL| 1| thing
11+
LL| | .
12+
LL| 1| method
13+
LL| | (
14+
LL| 1| "arg"
15+
LL| | )
16+
LL| | ;
17+
LL| |
18+
LL| 1| thing
19+
LL| 1| .
20+
LL| 1| method
21+
LL| 1| (
22+
LL| 1| "arg"
23+
LL| 1| )
24+
LL| | .
25+
LL| 1| method
26+
LL| | (
27+
LL| 1| "arg"
28+
LL| | )
29+
LL| | ;
30+
LL| 1|}
31+
LL| |
32+
LL| |struct Thing;
33+
LL| |
34+
LL| |#[coverage(off)]
35+
LL| |impl Thing {
36+
LL| | fn method(&self, _arg: &str) -> &Self {
37+
LL| | self
38+
LL| | }
39+
LL| |}
40+
LL| |
41+
LL| |#[coverage(off)]
42+
LL| |fn main() {
43+
LL| | call_method();
44+
LL| |}
45+

tests/coverage/call-method.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2024
3+
4+
// Basic test for method calls and chained method calls.
5+
6+
#[rustfmt::skip]
7+
fn call_method() {
8+
let thing = Thing;
9+
10+
thing
11+
.
12+
method
13+
(
14+
"arg"
15+
)
16+
;
17+
18+
thing
19+
.
20+
method
21+
(
22+
"arg"
23+
)
24+
.
25+
method
26+
(
27+
"arg"
28+
)
29+
;
30+
}
31+
32+
struct Thing;
33+
34+
#[coverage(off)]
35+
impl Thing {
36+
fn method(&self, _arg: &str) -> &Self {
37+
self
38+
}
39+
}
40+
41+
#[coverage(off)]
42+
fn main() {
43+
call_method();
44+
}

tests/coverage/for.many.coverage

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2024
3+
LL| |//@ revisions: zero one many
4+
LL| |//@[one] ignore-coverage-map
5+
LL| |//@[many] ignore-coverage-map
6+
LL| |
7+
LL| |// Basic test of `for` loops.
8+
LL| |
9+
LL| 1|fn for_loop(items: &[&str]) {
10+
LL| 1| say("hello");
11+
LL| |
12+
LL| 3| for item in items {
13+
^1
14+
LL| 3| say(item);
15+
LL| 3| }
16+
LL| |
17+
LL| 3| for item in items {
18+
^1
19+
LL| 3| say(item)
20+
LL| | }
21+
LL| |
22+
LL| 1| say("goodbye");
23+
LL| 1|}
24+
LL| |
25+
LL| |#[coverage(off)]
26+
LL| |fn main() {
27+
LL| | let items = cfg_select!(
28+
LL| | zero => &[],
29+
LL| | one => &["one"],
30+
LL| | many => &["one", "two", "three"],
31+
LL| | );
32+
LL| | for_loop(items);
33+
LL| |}
34+
LL| |
35+
LL| |#[coverage(off)]
36+
LL| |fn say(msg: &str) {
37+
LL| | println!("{msg}");
38+
LL| |}
39+

tests/coverage/for.one.coverage

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2024
3+
LL| |//@ revisions: zero one many
4+
LL| |//@[one] ignore-coverage-map
5+
LL| |//@[many] ignore-coverage-map
6+
LL| |
7+
LL| |// Basic test of `for` loops.
8+
LL| |
9+
LL| 1|fn for_loop(items: &[&str]) {
10+
LL| 1| say("hello");
11+
LL| |
12+
LL| 1| for item in items {
13+
LL| 1| say(item);
14+
LL| 1| }
15+
LL| |
16+
LL| 1| for item in items {
17+
LL| 1| say(item)
18+
LL| | }
19+
LL| |
20+
LL| 1| say("goodbye");
21+
LL| 1|}
22+
LL| |
23+
LL| |#[coverage(off)]
24+
LL| |fn main() {
25+
LL| | let items = cfg_select!(
26+
LL| | zero => &[],
27+
LL| | one => &["one"],
28+
LL| | many => &["one", "two", "three"],
29+
LL| | );
30+
LL| | for_loop(items);
31+
LL| |}
32+
LL| |
33+
LL| |#[coverage(off)]
34+
LL| |fn say(msg: &str) {
35+
LL| | println!("{msg}");
36+
LL| |}
37+

tests/coverage/for.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2024
3+
//@ revisions: zero one many
4+
//@[one] ignore-coverage-map
5+
//@[many] ignore-coverage-map
6+
7+
// Basic test of `for` loops.
8+
9+
fn for_loop(items: &[&str]) {
10+
say("hello");
11+
12+
for item in items {
13+
say(item);
14+
}
15+
16+
for item in items {
17+
say(item)
18+
}
19+
20+
say("goodbye");
21+
}
22+
23+
#[coverage(off)]
24+
fn main() {
25+
let items = cfg_select!(
26+
zero => &[],
27+
one => &["one"],
28+
many => &["one", "two", "three"],
29+
);
30+
for_loop(items);
31+
}
32+
33+
#[coverage(off)]
34+
fn say(msg: &str) {
35+
println!("{msg}");
36+
}

0 commit comments

Comments
 (0)