]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/abort-on-c-abi.rs
Rollup merge of #61499 - varkor:issue-53457, r=oli-obk
[rust.git] / src / test / run-pass / abort-on-c-abi.rs
1 #![allow(unused_must_use)]
2 // Since we mark some ABIs as "nounwind" to LLVM, we must make sure that
3 // we never unwind through them.
4
5 // ignore-cloudabi no env and process
6 // ignore-emscripten no processes
7 // ignore-sgx no processes
8
9 use std::{env, panic};
10 use std::io::prelude::*;
11 use std::io;
12 use std::process::{Command, Stdio};
13
14 extern "C" fn panic_in_ffi() {
15     panic!("Test");
16 }
17
18 fn test() {
19     let _ = panic::catch_unwind(|| { panic_in_ffi(); });
20     // The process should have aborted by now.
21     io::stdout().write(b"This should never be printed.\n");
22     let _ = io::stdout().flush();
23 }
24
25 fn main() {
26     let args: Vec<String> = env::args().collect();
27     if args.len() > 1 && args[1] == "test" {
28         return test();
29     }
30
31     let mut p = Command::new(&args[0])
32                         .stdout(Stdio::piped())
33                         .stdin(Stdio::piped())
34                         .arg("test").spawn().unwrap();
35     assert!(!p.wait().unwrap().success());
36 }