1 // ignore-windows: Unwind panicking does not currently work on Windows
2 use std::panic::catch_unwind;
6 static MY_COUNTER: Cell<usize> = Cell::new(0);
7 static DROPPED: Cell<bool> = Cell::new(false);
8 static HOOK_CALLED: Cell<bool> = Cell::new(false);
13 impl Drop for DropTester {
21 fn do_panic_counter() {
22 // If this gets leaked, it will be easy to spot
23 // in Miri's leak report
24 let _string = "LEAKED FROM do_panic_counter".to_string();
26 // When we panic, this should get dropped during unwinding
27 let _drop_tester = DropTester;
29 // Check for bugs in Miri's panic implementation.
30 // If do_panic_counter() somehow gets called more than once,
31 // we'll generate a different panic message
32 let old_val = MY_COUNTER.with(|c| {
37 panic!(format!("Hello from panic: {:?}", old_val));
41 std::panic::set_hook(Box::new(|_panic_info| {
42 HOOK_CALLED.with(|h| h.set(true));
44 let res = catch_unwind(|| {
45 let _string = "LEAKED FROM CLOSURE".to_string();
48 let expected: Box<String> = Box::new("Hello from panic: 0".to_string());
49 let actual = res.expect_err("do_panic() did not panic!")
50 .downcast::<String>().expect("Failed to cast to string!");
52 assert_eq!(expected, actual);
54 // This should have been set to 'true' by DropTester
58 HOOK_CALLED.with(|h| {