about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-08-22 14:41:55 +0200
committerRalf Jung <post@ralfj.de>2023-08-24 13:28:26 +0200
commitaf29a26378cdd90d663c5a93d671e70184772266 (patch)
tree967626672f031137698744b5a6ed31d9082c35e3
parent114fde6ac74ffbaaca4d7241c3ee4e11303ae50d (diff)
downloadrust-af29a26378cdd90d663c5a93d671e70184772266.tar.gz
rust-af29a26378cdd90d663c5a93d671e70184772266.zip
add tests for both kinds of unwind-terminate messages
-rw-r--r--tests/ui/backtrace.rs13
-rw-r--r--tests/ui/panics/panic-in-cleanup.rs19
-rw-r--r--tests/ui/panics/panic-in-cleanup.run.stderr10
-rw-r--r--tests/ui/panics/panic-in-ffi.rs15
-rw-r--r--tests/ui/panics/panic-in-ffi.run.stderr7
5 files changed, 59 insertions, 5 deletions
diff --git a/tests/ui/backtrace.rs b/tests/ui/backtrace.rs
index 66b378f62d6..95783945529 100644
--- a/tests/ui/backtrace.rs
+++ b/tests/ui/backtrace.rs
@@ -100,14 +100,17 @@ fn runtest(me: &str) {
         let s = str::from_utf8(&out.stderr).unwrap();
         // loosened the following from double::h to double:: due to
         // spurious failures on mac, 32bit, optimized
-        assert!(s.contains("stack backtrace") && contains_verbose_expected(s, "double"),
-                "bad output3: {}", s);
+        assert!(
+            s.contains("stack backtrace") &&
+                s.contains("panic in a destructor during cleanup") &&
+                contains_verbose_expected(s, "double"),
+            "bad output3: {}", s
+        );
 
         // Make sure a stack trace isn't printed too many times
         //
-        // Currently it is printed 3 times ("once", "twice" and "panic in a
-        // function that cannot unwind") but in the future the last one may be
-        // removed.
+        // Currently it is printed 3 times ("once", "twice" and "panic in a destructor during
+        // cleanup") but in the future the last one may be removed.
         let p = template(me).arg("double-fail")
                                     .env("RUST_BACKTRACE", "1").spawn().unwrap();
         let out = p.wait_with_output().unwrap();
diff --git a/tests/ui/panics/panic-in-cleanup.rs b/tests/ui/panics/panic-in-cleanup.rs
new file mode 100644
index 00000000000..b4519da4e6a
--- /dev/null
+++ b/tests/ui/panics/panic-in-cleanup.rs
@@ -0,0 +1,19 @@
+// run-fail
+// check-run-results
+// error-pattern: panic in a destructor during cleanup
+// normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
+// normalize-stderr-test: "\n +at [^\n]+" -> ""
+// ignore-emscripten no processes
+
+struct Bomb;
+
+impl Drop for Bomb {
+    fn drop(&mut self) {
+        panic!("BOOM");
+    }
+}
+
+fn main() {
+    let _b = Bomb;
+    panic!();
+}
diff --git a/tests/ui/panics/panic-in-cleanup.run.stderr b/tests/ui/panics/panic-in-cleanup.run.stderr
new file mode 100644
index 00000000000..fa201b9667f
--- /dev/null
+++ b/tests/ui/panics/panic-in-cleanup.run.stderr
@@ -0,0 +1,10 @@
+thread 'main' panicked at $DIR/panic-in-cleanup.rs:18:5:
+explicit panic
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+thread 'main' panicked at $DIR/panic-in-cleanup.rs:12:9:
+BOOM
+stack backtrace:
+thread 'main' panicked at library/core/src/panicking.rs:126:5:
+panic in a destructor during cleanup
+stack backtrace:
+thread caused non-unwinding panic. aborting.
diff --git a/tests/ui/panics/panic-in-ffi.rs b/tests/ui/panics/panic-in-ffi.rs
new file mode 100644
index 00000000000..bb30398531f
--- /dev/null
+++ b/tests/ui/panics/panic-in-ffi.rs
@@ -0,0 +1,15 @@
+// run-fail
+// check-run-results
+// error-pattern: panic in a function that cannot unwind
+// normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
+// normalize-stderr-test: "\n +at [^\n]+" -> ""
+// ignore-emscripten no processes
+#![feature(c_unwind)]
+
+extern "C" fn panic_in_ffi() {
+    panic!("Test");
+}
+
+fn main() {
+    panic_in_ffi();
+}
diff --git a/tests/ui/panics/panic-in-ffi.run.stderr b/tests/ui/panics/panic-in-ffi.run.stderr
new file mode 100644
index 00000000000..a6de98c4913
--- /dev/null
+++ b/tests/ui/panics/panic-in-ffi.run.stderr
@@ -0,0 +1,7 @@
+thread 'main' panicked at $DIR/panic-in-ffi.rs:10:5:
+Test
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+thread 'main' panicked at library/core/src/panicking.rs:126:5:
+panic in a function that cannot unwind
+stack backtrace:
+thread caused non-unwinding panic. aborting.