Skip to content

Commit

Permalink
fix: restore previously set local thread panic hook
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed May 31, 2024
1 parent 4eb3e5d commit 329856f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 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,11 +119,16 @@ impl TestResult {
)
.into_bytes(),
);
}));
}))
});

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

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

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

0 comments on commit 329856f

Please sign in to comment.