Skip to content

Commit 3af90ae

Browse files
committed
Added match or-pattern branch coverage test
1 parent f758844 commit 3af90ae

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Function name: match_or_pattern_simple::foo
2+
Raw bytes (50): 0x[01, 01, 06, 01, 07, 05, 09, 09, 05, 05, 02, 09, 17, 05, 02, 06, 01, 08, 01, 01, 17, 20, 02, 0b, 02, 09, 00, 0a, 20, 05, 09, 00, 0d, 00, 0e, 17, 00, 12, 02, 0a, 09, 03, 0e, 02, 0a, 13, 04, 01, 00, 02]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 6
6+
- expression 0 operands: lhs = Counter(0), rhs = Expression(1, Add)
7+
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
8+
- expression 2 operands: lhs = Counter(2), rhs = Counter(1)
9+
- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub)
10+
- expression 4 operands: lhs = Counter(2), rhs = Expression(5, Add)
11+
- expression 5 operands: lhs = Counter(1), rhs = Expression(0, Sub)
12+
Number of file 0 mappings: 6
13+
- Code(Counter(0)) at (prev + 8, 1) to (start + 1, 23)
14+
- Branch { true: Expression(0, Sub), false: Expression(2, Add) } at (prev + 2, 9) to (start + 0, 10)
15+
true = (c0 - (c1 + c2))
16+
false = (c2 + c1)
17+
- Branch { true: Counter(1), false: Counter(2) } at (prev + 0, 13) to (start + 0, 14)
18+
true = c1
19+
false = c2
20+
- Code(Expression(5, Add)) at (prev + 0, 18) to (start + 2, 10)
21+
= (c1 + (c0 - (c1 + c2)))
22+
- Code(Counter(2)) at (prev + 3, 14) to (start + 2, 10)
23+
- Code(Expression(4, Add)) at (prev + 4, 1) to (start + 0, 2)
24+
= (c2 + (c1 + (c0 - (c1 + c2))))
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2021
3+
LL| |//@ compile-flags: -Zcoverage-options=branch
4+
LL| |//@ llvm-cov-flags: --show-branches=count
5+
LL| |
6+
LL| |use core::hint::black_box;
7+
LL| |
8+
LL| 3|fn foo(a: i32) {
9+
LL| 3| match black_box(a) {
10+
LL| 1| 1 | 2 => {
11+
------------------
12+
| Branch (LL:9): [True: 1, False: 2]
13+
| Branch (LL:13): [True: 0, False: 2]
14+
------------------
15+
LL| 1| consume(1);
16+
LL| 1| }
17+
LL| 2| _ => {
18+
LL| 2| consume(2);
19+
LL| 2| }
20+
LL| | }
21+
LL| 3|}
22+
LL| |
23+
LL| |#[coverage(off)]
24+
LL| |fn consume<T>(x: T) {
25+
LL| | core::hint::black_box(x);
26+
LL| |}
27+
LL| |
28+
LL| |#[coverage(off)]
29+
LL| |fn main() {
30+
LL| | foo(1);
31+
LL| | foo(3);
32+
LL| | foo(4);
33+
LL| |}
34+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2021
3+
//@ compile-flags: -Zcoverage-options=branch
4+
//@ llvm-cov-flags: --show-branches=count
5+
6+
use core::hint::black_box;
7+
8+
fn foo(a: i32) {
9+
match black_box(a) {
10+
1 | 2 => {
11+
consume(1);
12+
}
13+
_ => {
14+
consume(2);
15+
}
16+
}
17+
}
18+
19+
#[coverage(off)]
20+
fn consume<T>(x: T) {
21+
core::hint::black_box(x);
22+
}
23+
24+
#[coverage(off)]
25+
fn main() {
26+
foo(1);
27+
foo(3);
28+
foo(4);
29+
}

0 commit comments

Comments
 (0)