mirror of
https://github.com/rust-lang/rust
synced 2024-09-05 00:24:52 +00:00
coverage: Branch coverage test for if-let and let-chains
This commit is contained in:
parent
4f7a47798e
commit
7f432dfb23
41
tests/coverage/branch/if-let.cov-map
Normal file
41
tests/coverage/branch/if-let.cov-map
Normal file
|
@ -0,0 +1,41 @@
|
|||
Function name: if_let::if_let
|
||||
Raw bytes (38): 0x[01, 01, 02, 05, 09, 09, 02, 06, 01, 0c, 01, 01, 10, 02, 03, 11, 00, 12, 05, 00, 16, 00, 1b, 02, 00, 1c, 02, 06, 09, 02, 0c, 02, 06, 07, 03, 05, 01, 02]
|
||||
Number of files: 1
|
||||
- file 0 => global file 1
|
||||
Number of expressions: 2
|
||||
- expression 0 operands: lhs = Counter(1), rhs = Counter(2)
|
||||
- expression 1 operands: lhs = Counter(2), rhs = Expression(0, Sub)
|
||||
Number of file 0 mappings: 6
|
||||
- Code(Counter(0)) at (prev + 12, 1) to (start + 1, 16)
|
||||
- Code(Expression(0, Sub)) at (prev + 3, 17) to (start + 0, 18)
|
||||
= (c1 - c2)
|
||||
- Code(Counter(1)) at (prev + 0, 22) to (start + 0, 27)
|
||||
- Code(Expression(0, Sub)) at (prev + 0, 28) to (start + 2, 6)
|
||||
= (c1 - c2)
|
||||
- Code(Counter(2)) at (prev + 2, 12) to (start + 2, 6)
|
||||
- Code(Expression(1, Add)) at (prev + 3, 5) to (start + 1, 2)
|
||||
= (c2 + (c1 - c2))
|
||||
|
||||
Function name: if_let::if_let_chain
|
||||
Raw bytes (52): 0x[01, 01, 04, 01, 05, 05, 09, 0f, 0d, 05, 09, 08, 01, 17, 01, 00, 33, 02, 01, 11, 00, 12, 01, 00, 16, 00, 17, 0d, 01, 15, 00, 16, 02, 00, 1a, 00, 1b, 0d, 01, 05, 03, 06, 0f, 03, 0c, 02, 06, 0b, 03, 05, 01, 02]
|
||||
Number of files: 1
|
||||
- file 0 => global file 1
|
||||
Number of expressions: 4
|
||||
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
|
||||
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
|
||||
- expression 2 operands: lhs = Expression(3, Add), rhs = Counter(3)
|
||||
- expression 3 operands: lhs = Counter(1), rhs = Counter(2)
|
||||
Number of file 0 mappings: 8
|
||||
- Code(Counter(0)) at (prev + 23, 1) to (start + 0, 51)
|
||||
- Code(Expression(0, Sub)) at (prev + 1, 17) to (start + 0, 18)
|
||||
= (c0 - c1)
|
||||
- Code(Counter(0)) at (prev + 0, 22) to (start + 0, 23)
|
||||
- Code(Counter(3)) at (prev + 1, 21) to (start + 0, 22)
|
||||
- Code(Expression(0, Sub)) at (prev + 0, 26) to (start + 0, 27)
|
||||
= (c0 - c1)
|
||||
- Code(Counter(3)) at (prev + 1, 5) to (start + 3, 6)
|
||||
- Code(Expression(3, Add)) at (prev + 3, 12) to (start + 2, 6)
|
||||
= (c1 + c2)
|
||||
- Code(Expression(2, Add)) at (prev + 3, 5) to (start + 1, 2)
|
||||
= ((c1 + c2) + c3)
|
||||
|
62
tests/coverage/branch/if-let.coverage
Normal file
62
tests/coverage/branch/if-let.coverage
Normal file
|
@ -0,0 +1,62 @@
|
|||
LL| |#![feature(coverage_attribute, let_chains)]
|
||||
LL| |//@ edition: 2021
|
||||
LL| |//@ compile-flags: -Zcoverage-options=branch
|
||||
LL| |//@ llvm-cov-flags: --show-branches=count
|
||||
LL| |
|
||||
LL| |macro_rules! no_merge {
|
||||
LL| | () => {
|
||||
LL| | for _ in 0..1 {}
|
||||
LL| | };
|
||||
LL| |}
|
||||
LL| |
|
||||
LL| 3|fn if_let(input: Option<&str>) {
|
||||
LL| 3| no_merge!();
|
||||
LL| |
|
||||
LL| 3| if let Some(x) = input {
|
||||
^2
|
||||
LL| 2| say(x);
|
||||
LL| 2| } else {
|
||||
LL| 1| say("none");
|
||||
LL| 1| }
|
||||
LL| 3| say("done");
|
||||
LL| 3|}
|
||||
LL| |
|
||||
LL| 15|fn if_let_chain(a: Option<&str>, b: Option<&str>) {
|
||||
LL| 15| if let Some(x) = a
|
||||
^12
|
||||
LL| 12| && let Some(y) = b
|
||||
^8
|
||||
LL| 8| {
|
||||
LL| 8| say(x);
|
||||
LL| 8| say(y);
|
||||
LL| 8| } else {
|
||||
LL| 7| say("not both");
|
||||
LL| 7| }
|
||||
LL| 15| say("done");
|
||||
LL| 15|}
|
||||
LL| |
|
||||
LL| |#[coverage(off)]
|
||||
LL| |fn say(message: &str) {
|
||||
LL| | core::hint::black_box(message);
|
||||
LL| |}
|
||||
LL| |
|
||||
LL| |#[coverage(off)]
|
||||
LL| |fn main() {
|
||||
LL| | if_let(Some("x"));
|
||||
LL| | if_let(Some("x"));
|
||||
LL| | if_let(None);
|
||||
LL| |
|
||||
LL| | for _ in 0..8 {
|
||||
LL| | if_let_chain(Some("a"), Some("b"));
|
||||
LL| | }
|
||||
LL| | for _ in 0..4 {
|
||||
LL| | if_let_chain(Some("a"), None);
|
||||
LL| | }
|
||||
LL| | for _ in 0..2 {
|
||||
LL| | if_let_chain(None, Some("b"));
|
||||
LL| | }
|
||||
LL| | if_let_chain(None, None);
|
||||
LL| |}
|
||||
LL| |
|
||||
LL| |// FIXME(#124118) Actually instrument if-let and let-chains for branch coverage.
|
||||
|
58
tests/coverage/branch/if-let.rs
Normal file
58
tests/coverage/branch/if-let.rs
Normal file
|
@ -0,0 +1,58 @@
|
|||
#![feature(coverage_attribute, let_chains)]
|
||||
//@ edition: 2021
|
||||
//@ compile-flags: -Zcoverage-options=branch
|
||||
//@ llvm-cov-flags: --show-branches=count
|
||||
|
||||
macro_rules! no_merge {
|
||||
() => {
|
||||
for _ in 0..1 {}
|
||||
};
|
||||
}
|
||||
|
||||
fn if_let(input: Option<&str>) {
|
||||
no_merge!();
|
||||
|
||||
if let Some(x) = input {
|
||||
say(x);
|
||||
} else {
|
||||
say("none");
|
||||
}
|
||||
say("done");
|
||||
}
|
||||
|
||||
fn if_let_chain(a: Option<&str>, b: Option<&str>) {
|
||||
if let Some(x) = a
|
||||
&& let Some(y) = b
|
||||
{
|
||||
say(x);
|
||||
say(y);
|
||||
} else {
|
||||
say("not both");
|
||||
}
|
||||
say("done");
|
||||
}
|
||||
|
||||
#[coverage(off)]
|
||||
fn say(message: &str) {
|
||||
core::hint::black_box(message);
|
||||
}
|
||||
|
||||
#[coverage(off)]
|
||||
fn main() {
|
||||
if_let(Some("x"));
|
||||
if_let(Some("x"));
|
||||
if_let(None);
|
||||
|
||||
for _ in 0..8 {
|
||||
if_let_chain(Some("a"), Some("b"));
|
||||
}
|
||||
for _ in 0..4 {
|
||||
if_let_chain(Some("a"), None);
|
||||
}
|
||||
for _ in 0..2 {
|
||||
if_let_chain(None, Some("b"));
|
||||
}
|
||||
if_let_chain(None, None);
|
||||
}
|
||||
|
||||
// FIXME(#124118) Actually instrument if-let and let-chains for branch coverage.
|
Loading…
Reference in a new issue