]> git.proxmox.com Git - rustc.git/blob - src/test/ui/panics/abort-on-panic.rs
New upstream version 1.50.0+dfsg1
[rustc.git] / src / test / ui / panics / abort-on-panic.rs
1 // run-pass
2
3 #![allow(unused_must_use)]
4 #![feature(unwind_attributes)]
5 // Since we mark some ABIs as "nounwind" to LLVM, we must make sure that
6 // we never unwind through them.
7
8 // ignore-emscripten no processes
9 // ignore-sgx no processes
10
11 use std::{env, panic};
12 use std::io::prelude::*;
13 use std::io;
14 use std::process::{Command, Stdio};
15
16 #[unwind(aborts)] // FIXME(#58794) should work even without the attribute
17 extern "C" fn panic_in_ffi() {
18 panic!("Test");
19 }
20
21 #[unwind(aborts)]
22 extern "Rust" fn panic_in_rust_abi() {
23 panic!("TestRust");
24 }
25
26 fn test() {
27 let _ = panic::catch_unwind(|| { panic_in_ffi(); });
28 // The process should have aborted by now.
29 io::stdout().write(b"This should never be printed.\n");
30 let _ = io::stdout().flush();
31 }
32
33 fn testrust() {
34 let _ = panic::catch_unwind(|| { panic_in_rust_abi(); });
35 // The process should have aborted by now.
36 io::stdout().write(b"This should never be printed.\n");
37 let _ = io::stdout().flush();
38 }
39
40 fn main() {
41 let args: Vec<String> = env::args().collect();
42 if args.len() > 1 {
43 // This is inside the self-executed command.
44 match &*args[1] {
45 "test" => return test(),
46 "testrust" => return testrust(),
47 _ => panic!("bad test"),
48 }
49 }
50
51 // These end up calling the self-execution branches above.
52 let mut p = Command::new(&args[0])
53 .stdout(Stdio::piped())
54 .stdin(Stdio::piped())
55 .arg("test").spawn().unwrap();
56 assert!(!p.wait().unwrap().success());
57
58 let mut p = Command::new(&args[0])
59 .stdout(Stdio::piped())
60 .stdin(Stdio::piped())
61 .arg("testrust").spawn().unwrap();
62 assert!(!p.wait().unwrap().success());
63 }