about summary refs log tree commit diff
path: root/src/test/run-pass/panics/panic-handler-chain.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/run-pass/panics/panic-handler-chain.rs')
-rw-r--r--src/test/run-pass/panics/panic-handler-chain.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/run-pass/panics/panic-handler-chain.rs b/src/test/run-pass/panics/panic-handler-chain.rs
new file mode 100644
index 00000000000..c4c3dc1963e
--- /dev/null
+++ b/src/test/run-pass/panics/panic-handler-chain.rs
@@ -0,0 +1,39 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+#![allow(stable_features)]
+
+// ignore-emscripten no threads support
+
+#![feature(std_panic)]
+
+use std::sync::atomic::{AtomicUsize, Ordering};
+use std::panic;
+use std::thread;
+
+static A: AtomicUsize = AtomicUsize::new(0);
+static B: AtomicUsize = AtomicUsize::new(0);
+
+fn main() {
+    panic::set_hook(Box::new(|_| { A.fetch_add(1, Ordering::SeqCst); }));
+    let hook = panic::take_hook();
+    panic::set_hook(Box::new(move |info| {
+        B.fetch_add(1, Ordering::SeqCst);
+        hook(info);
+    }));
+
+    let _ = thread::spawn(|| {
+        panic!();
+    }).join();
+
+    assert_eq!(1, A.load(Ordering::SeqCst));
+    assert_eq!(1, B.load(Ordering::SeqCst));
+}