about summary refs log tree commit diff
path: root/tests/coverage/branch/if-let.coverage
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-04-17 11:41:40 +1000
committerZalathar <Zalathar@users.noreply.github.com>2024-04-22 21:55:33 +1000
commit7f432dfb23f264f5c368464f849663a518750a93 (patch)
treef0f2bece6892b691097f639627528914379b7fb3 /tests/coverage/branch/if-let.coverage
parent4f7a47798eb3455aed74fde5cd8e81927d2db07a (diff)
downloadrust-7f432dfb23f264f5c368464f849663a518750a93.tar.gz
rust-7f432dfb23f264f5c368464f849663a518750a93.zip
coverage: Branch coverage test for if-let and let-chains
Diffstat (limited to 'tests/coverage/branch/if-let.coverage')
-rw-r--r--tests/coverage/branch/if-let.coverage62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/coverage/branch/if-let.coverage b/tests/coverage/branch/if-let.coverage
new file mode 100644
index 00000000000..f30c5d34eca
--- /dev/null
+++ b/tests/coverage/branch/if-let.coverage
@@ -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.
+