Skip to content

Commit c639622

Browse files
committed
test built-in panic catching
1 parent 7c51acc commit c639622

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

tests/run-pass/catch_panic.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// ignore-windows: Unwind panicking does not currently work on Windows
2+
#![allow(const_err)]
3+
24
use std::panic::{catch_unwind, AssertUnwindSafe};
35
use std::cell::Cell;
46

@@ -48,11 +50,16 @@ fn main() {
4850
test(|old_val| panic!(format!("Hello from panic: {:?}", old_val)));
4951
test(|old_val| panic!("Hello from panic: {:?}", old_val));
5052
test(|_old_val| panic!(1337));
53+
5154
// FIXME https://github.com/rust-lang/miri/issues/1071
5255
//test(|_old_val| core::panic!("Hello from panic: core"));
5356
//test(|old_val| core::panic!(&format!("Hello from panic: {:?}", old_val)));
5457
//test(|old_val| core::panic!("Hello from panic: {:?}", old_val));
5558

59+
// Built-in panics
60+
test(|_old_val| { let _val = [0, 1, 2][4]; loop {} });
61+
test(|_old_val| { let _val = 1/0; loop {} });
62+
5663
// Cleanup: reset to default hook.
5764
drop(std::panic::take_hook());
5865

tests/run-pass/catch_panic.stderr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
thread 'main' panicked at 'Hello from panic: std', $DIR/catch_panic.rs:47:21
1+
thread 'main' panicked at 'Hello from panic: std', $DIR/catch_panic.rs:49:21
22
Caught panic message (&str): Hello from panic: std
3-
thread 'main' panicked at 'Hello from panic: 1', $DIR/catch_panic.rs:48:20
3+
thread 'main' panicked at 'Hello from panic: 1', $DIR/catch_panic.rs:50:20
44
Caught panic message (String): Hello from panic: 1
5-
thread 'main' panicked at 'Hello from panic: 2', $DIR/catch_panic.rs:49:20
5+
thread 'main' panicked at 'Hello from panic: 2', $DIR/catch_panic.rs:51:20
66
Caught panic message (String): Hello from panic: 2
7-
thread 'main' panicked at 'Box<Any>', $DIR/catch_panic.rs:50:21
7+
thread 'main' panicked at 'Box<Any>', $DIR/catch_panic.rs:52:21
88
Failed get caught panic message.
9+
thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 4', $DIR/catch_panic.rs:60:34
10+
Caught panic message (String): index out of bounds: the len is 3 but the index is 4
11+
thread 'main' panicked at 'attempt to divide by zero', $DIR/catch_panic.rs:61:34
12+
Caught panic message (String): attempt to divide by zero
913
Success!

0 commit comments

Comments
 (0)