From 19429ce132d8cc9526ab4fe46d6287f2ad89ef1c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 22 Apr 2021 15:05:23 +0100 Subject: [PATCH] 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 --- src/test/ui/panics/abort-on-panic.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/test/ui/panics/abort-on-panic.rs b/src/test/ui/panics/abort-on-panic.rs index 3ef6d5d18744..7cf60ae96021 100644 --- a/src/test/ui/panics/abort-on-panic.rs +++ b/src/test/ui/panics/abort-on-panic.rs @@ -28,6 +28,11 @@ fn should_have_aborted() { let _ = io::stdout().flush(); } +fn bomb_out_but_not_abort(msg: &str) { + eprintln!("bombing out: {}", msg); + exit(1); +} + fn test() { let _ = panic::catch_unwind(|| { panic_in_ffi(); }); should_have_aborted(); @@ -50,7 +55,7 @@ fn main() { for (a,f) in tests { if &args[1] == a { return f() } } - panic!("bad test"); + bomb_out_but_not_abort("bad test"); } let execute_self_expecting_abort = |arg| { @@ -58,7 +63,11 @@ fn main() { .stdout(Stdio::piped()) .stdin(Stdio::piped()) .arg(arg).spawn().unwrap(); - assert!(!p.wait().unwrap().success()); + let status = p.wait().unwrap(); + assert!(!status.success()); + // Any reasonable platform can distinguish a process which + // called exit(1) from one which panicked. + assert_ne!(status.code(), Some(1)); }; for (a,_f) in tests {