]> git.lizzy.rs Git - rust.git/commitdiff
panic ui test: Improve error handling
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 22 Apr 2021 14:05:23 +0000 (15:05 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 7 May 2021 10:17:44 +0000 (11:17 +0100)
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>
src/test/ui/panics/abort-on-panic.rs

index 3ef6d5d187440b3734ea7b711574473d7ecd878b..7cf60ae96021255057f97e264fffd756817a72c1 100644 (file)
@@ -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 {