Skip to content

Commit e9b4323

Browse files
committed
also make sure the hook actually gets called
1 parent b1676a3 commit e9b4323

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tests/run-pass/panic/std-panic-locations.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#![feature(option_expect_none, option_unwrap_none)]
2-
32
//! Test that panic locations for `#[track_caller]` functions in std have the correct
43
//! location reported.
54
5+
use std::sync::atomic::{AtomicUsize, Ordering};
6+
7+
static HOOK_COUNT: AtomicUsize = AtomicUsize::new(0);
8+
69
fn main() {
710
// inspect the `PanicInfo` we receive to ensure the right file is the source
811
std::panic::set_hook(Box::new(|info| {
12+
HOOK_COUNT.fetch_add(1, Ordering::Relaxed);
913
let actual = info.location().unwrap();
1014
if actual.file() != file!() {
1115
eprintln!("expected a location in the test file, found {:?}", actual);
@@ -35,4 +39,6 @@ fn main() {
3539

3640
// Cleanup: reset to default hook.
3741
drop(std::panic::take_hook());
42+
43+
assert_eq!(HOOK_COUNT.load(Ordering::Relaxed), 8);
3844
}

0 commit comments

Comments
 (0)