Skip to content

Commit

Permalink
fix: restore previously set local thread panic hook after running test (
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed May 31, 2024
1 parent 4eb3e5d commit f5d15b6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ impl TestResult {

let panic_message = Arc::new(Mutex::new(Vec::<u8>::new()));

LOCAL_PANIC_HOOK.with(|hook| {
let previous_panic_hook = LOCAL_PANIC_HOOK.with(|hook| {
let panic_message = panic_message.clone();
*hook.borrow_mut() = Some(Box::new(move |info| {
hook.borrow_mut().replace(Box::new(move |info| {
let backtrace = capture_backtrace();
panic_message.lock().extend(
format!(
Expand All @@ -119,12 +119,17 @@ impl TestResult {
)
.into_bytes(),
);
}));
}))
});

let result = std::panic::catch_unwind(func);

// decrement the panic hook
// restore or clear the local panic hook
LOCAL_PANIC_HOOK.with(|hook| {
*hook.borrow_mut() = previous_panic_hook;
});

// decrement the global panic hook
{
let mut hook_count = GLOBAL_PANIC_HOOK_COUNT.lock();
*hook_count -= 1;
Expand Down

0 comments on commit f5d15b6

Please sign in to comment.