Skip to content

Commit 19429ce

Browse files
committed
panic ui test: Improve error handling
Previoously, if somehow this program got a wrong argument, it would panic in the re-executed child. But that looks like a "success" for this program! We mustn't panic unless everything is great. Signed-off-by: Ian Jackson <[email protected]>
1 parent a17eab7 commit 19429ce

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/test/ui/panics/abort-on-panic.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ fn should_have_aborted() {
2828
let _ = io::stdout().flush();
2929
}
3030

31+
fn bomb_out_but_not_abort(msg: &str) {
32+
eprintln!("bombing out: {}", msg);
33+
exit(1);
34+
}
35+
3136
fn test() {
3237
let _ = panic::catch_unwind(|| { panic_in_ffi(); });
3338
should_have_aborted();
@@ -50,15 +55,19 @@ fn main() {
5055
for (a,f) in tests {
5156
if &args[1] == a { return f() }
5257
}
53-
panic!("bad test");
58+
bomb_out_but_not_abort("bad test");
5459
}
5560

5661
let execute_self_expecting_abort = |arg| {
5762
let mut p = Command::new(&args[0])
5863
.stdout(Stdio::piped())
5964
.stdin(Stdio::piped())
6065
.arg(arg).spawn().unwrap();
61-
assert!(!p.wait().unwrap().success());
66+
let status = p.wait().unwrap();
67+
assert!(!status.success());
68+
// Any reasonable platform can distinguish a process which
69+
// called exit(1) from one which panicked.
70+
assert_ne!(status.code(), Some(1));
6271
};
6372

6473
for (a,_f) in tests {

0 commit comments

Comments
 (0)