add tests for both kinds of unwind-terminate messages

This commit is contained in:
Ralf Jung 2023-08-22 14:41:55 +02:00
parent 114fde6ac7
commit af29a26378
5 changed files with 59 additions and 5 deletions

View File

@ -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();

View File

@ -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!();
}

View File

@ -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.

View File

@ -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();
}

View File

@ -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.