Skip to content

Commit af29a26

Browse files
committed
add tests for both kinds of unwind-terminate messages
1 parent 114fde6 commit af29a26

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

tests/ui/backtrace.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,17 @@ fn runtest(me: &str) {
100100
let s = str::from_utf8(&out.stderr).unwrap();
101101
// loosened the following from double::h to double:: due to
102102
// spurious failures on mac, 32bit, optimized
103-
assert!(s.contains("stack backtrace") && contains_verbose_expected(s, "double"),
104-
"bad output3: {}", s);
103+
assert!(
104+
s.contains("stack backtrace") &&
105+
s.contains("panic in a destructor during cleanup") &&
106+
contains_verbose_expected(s, "double"),
107+
"bad output3: {}", s
108+
);
105109

106110
// Make sure a stack trace isn't printed too many times
107111
//
108-
// Currently it is printed 3 times ("once", "twice" and "panic in a
109-
// function that cannot unwind") but in the future the last one may be
110-
// removed.
112+
// Currently it is printed 3 times ("once", "twice" and "panic in a destructor during
113+
// cleanup") but in the future the last one may be removed.
111114
let p = template(me).arg("double-fail")
112115
.env("RUST_BACKTRACE", "1").spawn().unwrap();
113116
let out = p.wait_with_output().unwrap();

tests/ui/panics/panic-in-cleanup.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-fail
2+
// check-run-results
3+
// error-pattern: panic in a destructor during cleanup
4+
// normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
5+
// normalize-stderr-test: "\n +at [^\n]+" -> ""
6+
// ignore-emscripten no processes
7+
8+
struct Bomb;
9+
10+
impl Drop for Bomb {
11+
fn drop(&mut self) {
12+
panic!("BOOM");
13+
}
14+
}
15+
16+
fn main() {
17+
let _b = Bomb;
18+
panic!();
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
thread 'main' panicked at $DIR/panic-in-cleanup.rs:18:5:
2+
explicit panic
3+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4+
thread 'main' panicked at $DIR/panic-in-cleanup.rs:12:9:
5+
BOOM
6+
stack backtrace:
7+
thread 'main' panicked at library/core/src/panicking.rs:126:5:
8+
panic in a destructor during cleanup
9+
stack backtrace:
10+
thread caused non-unwinding panic. aborting.

tests/ui/panics/panic-in-ffi.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-fail
2+
// check-run-results
3+
// error-pattern: panic in a function that cannot unwind
4+
// normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
5+
// normalize-stderr-test: "\n +at [^\n]+" -> ""
6+
// ignore-emscripten no processes
7+
#![feature(c_unwind)]
8+
9+
extern "C" fn panic_in_ffi() {
10+
panic!("Test");
11+
}
12+
13+
fn main() {
14+
panic_in_ffi();
15+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
thread 'main' panicked at $DIR/panic-in-ffi.rs:10:5:
2+
Test
3+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4+
thread 'main' panicked at library/core/src/panicking.rs:126:5:
5+
panic in a function that cannot unwind
6+
stack backtrace:
7+
thread caused non-unwinding panic. aborting.

0 commit comments

Comments
 (0)