about summary refs log tree commit diff
path: root/tests/coverage/panic_unwind.coverage
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-11-01 21:26:53 +1100
committerZalathar <Zalathar@users.noreply.github.com>2023-11-07 11:15:19 +1100
commite9d04c5e2444526ffde83662f2d57fa35c772891 (patch)
tree6dbc04c3253992f8968d5914d7b1c631db528892 /tests/coverage/panic_unwind.coverage
parentaea7c27eae5e34b11c64ec6d11c75627ef24f8b1 (diff)
downloadrust-e9d04c5e2444526ffde83662f2d57fa35c772891.tar.gz
rust-e9d04c5e2444526ffde83662f2d57fa35c772891.zip
coverage: Migrate `tests/run-coverage` into `tests/coverage`
Diffstat (limited to 'tests/coverage/panic_unwind.coverage')
-rw-r--r--tests/coverage/panic_unwind.coverage32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/coverage/panic_unwind.coverage b/tests/coverage/panic_unwind.coverage
new file mode 100644
index 00000000000..2b0777ef215
--- /dev/null
+++ b/tests/coverage/panic_unwind.coverage
@@ -0,0 +1,32 @@
+   LL|       |#![allow(unused_assignments)]
+   LL|       |// failure-status: 101
+   LL|       |
+   LL|      4|fn might_panic(should_panic: bool) {
+   LL|      4|    if should_panic {
+   LL|      1|        println!("panicking...");
+   LL|      1|        panic!("panics");
+   LL|      3|    } else {
+   LL|      3|        println!("Don't Panic");
+   LL|      3|    }
+   LL|      3|}
+   LL|       |
+   LL|      1|fn main() -> Result<(), u8> {
+   LL|      1|    let mut countdown = 10;
+   LL|     11|    while countdown > 0 {
+   LL|     11|        if countdown == 1 {
+   LL|      1|            might_panic(true);
+   LL|     10|        } else if countdown < 5 {
+   LL|      3|            might_panic(false);
+   LL|      6|        }
+   LL|     10|        countdown -= 1;
+   LL|       |    }
+   LL|      0|    Ok(())
+   LL|      0|}
+   LL|       |
+   LL|       |// Notes:
+   LL|       |//   1. Compare this program and its coverage results to those of the similar tests `abort.rs` and
+   LL|       |//      `try_error_result.rs`.
+   LL|       |//   2. Since the `panic_unwind.rs` test is allowed to unwind, it is also allowed to execute the
+   LL|       |//      normal program exit cleanup, including writing out the current values of the coverage
+   LL|       |//      counters.
+