coverage: Branch coverage test for if-let and let-chains
This commit is contained in:
parent
4f7a47798e
commit
7f432dfb23
3 changed files with 161 additions and 0 deletions
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.
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue