Skip to content

Commit 39a78f0

Browse files
committed
make sure assertions and debug-assertions also panic (and can be caught)
1 parent ded5a52 commit 39a78f0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

tests/run-pass/panic/catch_panic.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ fn main() {
6161
test(|_old_val| { let _val = [0, 1, 2][4]; loop {} });
6262
test(|_old_val| { let _val = 1/0; loop {} });
6363

64+
// Assertion and debug assertion
65+
test(|_old_val| { assert!(false); loop {} });
66+
test(|_old_val| { debug_assert!(false); loop {} });
67+
6468
// Cleanup: reset to default hook.
6569
drop(std::panic::take_hook());
6670

tests/run-pass/panic/catch_panic.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 4'
1616
Caught panic message (String): index out of bounds: the len is 3 but the index is 4
1717
thread 'main' panicked at 'attempt to divide by zero', $DIR/catch_panic.rs:62:34
1818
Caught panic message (String): attempt to divide by zero
19+
thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:65:23
20+
Caught panic message (&str): assertion failed: false
21+
thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:66:23
22+
Caught panic message (&str): assertion failed: false
1923
Success!

0 commit comments

Comments
 (0)