diff options
| author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2021-04-22 15:05:23 +0100 |
|---|---|---|
| committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2021-05-07 11:17:44 +0100 |
| commit | 19429ce132d8cc9526ab4fe46d6287f2ad89ef1c (patch) | |
| tree | 606d5f9ceadea41f9b9115ecbea6fac2c7da06e0 /src/test | |
| parent | a17eab7beddf87807d9d7fc71b7dfb90b5e2488a (diff) | |
| download | rust-19429ce132d8cc9526ab4fe46d6287f2ad89ef1c.tar.gz rust-19429ce132d8cc9526ab4fe46d6287f2ad89ef1c.zip | |
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 <ijackson@chiark.greenend.org.uk>
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/panics/abort-on-panic.rs | 13 |
1 files 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 3ef6d5d1874..7cf60ae9602 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 { |
