about summary refs log tree commit diff
diff options
context:
space:
mode:
authorjyn <github@jyn.dev>2024-07-05 16:34:32 -0400
committerjyn <github@jyn.dev>2024-07-05 17:22:58 -0400
commitde14f1f932f4f11130be3fed5cd370bd0936032e (patch)
tree86fcb78fa973e8468c6f5ecdab0199966b1e545e
parent6e2780775f5cea9328d37f4b8d0ee79db0056267 (diff)
downloadrust-de14f1f932f4f11130be3fed5cd370bd0936032e.tar.gz
rust-de14f1f932f4f11130be3fed5cd370bd0936032e.zip
add test that multi-threaded panics aren't interleaved
-rw-r--r--tests/ui/backtrace/synchronized-panic-handler.rs15
-rw-r--r--tests/ui/backtrace/synchronized-panic-handler.run.stderr5
2 files changed, 20 insertions, 0 deletions
diff --git a/tests/ui/backtrace/synchronized-panic-handler.rs b/tests/ui/backtrace/synchronized-panic-handler.rs
new file mode 100644
index 00000000000..0ea285968d5
--- /dev/null
+++ b/tests/ui/backtrace/synchronized-panic-handler.rs
@@ -0,0 +1,15 @@
+//@ run-pass
+//@ check-run-results
+//@ edition:2021
+use std::thread;
+const PANIC_MESSAGE: &str = "oops oh no woe is me";
+
+fn entry() {
+    panic!("{PANIC_MESSAGE}")
+}
+
+fn main() {
+    let (a, b) = (thread::spawn(entry), thread::spawn(entry));
+    assert_eq!(&**a.join().unwrap_err().downcast::<String>().unwrap(), PANIC_MESSAGE);
+    assert_eq!(&**b.join().unwrap_err().downcast::<String>().unwrap(), PANIC_MESSAGE);
+}
diff --git a/tests/ui/backtrace/synchronized-panic-handler.run.stderr b/tests/ui/backtrace/synchronized-panic-handler.run.stderr
new file mode 100644
index 00000000000..06ef53836c2
--- /dev/null
+++ b/tests/ui/backtrace/synchronized-panic-handler.run.stderr
@@ -0,0 +1,5 @@
+thread '<unnamed>' panicked at $DIR/synchronized-panic-handler.rs:thread '8<unnamed>:5' panicked at :
+oops oh no woe is me$DIR/synchronized-panic-handler.rs
+:note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+8:5:
+oops oh no woe is me