2019-07-27 00:54:25 +03:00
|
|
|
// run-pass
|
|
|
|
|
2018-09-14 12:20:28 +02:00
|
|
|
#![allow(unused_must_use)]
|
2019-02-27 17:21:31 -07:00
|
|
|
#![feature(unwind_attributes)]
|
2017-12-19 01:59:29 +01:00
|
|
|
// Since we mark some ABIs as "nounwind" to LLVM, we must make sure that
|
|
|
|
// we never unwind through them.
|
|
|
|
|
|
|
|
// ignore-emscripten no processes
|
2019-04-24 09:26:33 -07:00
|
|
|
// ignore-sgx no processes
|
2017-12-19 01:59:29 +01:00
|
|
|
|
|
|
|
use std::{env, panic};
|
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::io;
|
|
|
|
use std::process::{Command, Stdio};
|
|
|
|
|
2019-10-12 21:02:38 +02:00
|
|
|
#[unwind(aborts)] // FIXME(#58794) should work even without the attribute
|
2017-12-19 01:59:29 +01:00
|
|
|
extern "C" fn panic_in_ffi() {
|
|
|
|
panic!("Test");
|
|
|
|
}
|
|
|
|
|
2019-10-12 21:02:38 +02:00
|
|
|
#[unwind(aborts)]
|
|
|
|
extern "Rust" fn panic_in_rust_abi() {
|
|
|
|
panic!("TestRust");
|
|
|
|
}
|
|
|
|
|
2021-02-07 12:16:11 +00:00
|
|
|
fn should_have_aborted() {
|
2017-12-19 01:59:29 +01:00
|
|
|
io::stdout().write(b"This should never be printed.\n");
|
|
|
|
let _ = io::stdout().flush();
|
|
|
|
}
|
|
|
|
|
2021-02-07 12:16:11 +00:00
|
|
|
fn test() {
|
|
|
|
let _ = panic::catch_unwind(|| { panic_in_ffi(); });
|
|
|
|
should_have_aborted();
|
|
|
|
}
|
|
|
|
|
2019-10-12 21:02:38 +02:00
|
|
|
fn testrust() {
|
|
|
|
let _ = panic::catch_unwind(|| { panic_in_rust_abi(); });
|
2021-02-07 12:16:11 +00:00
|
|
|
should_have_aborted();
|
2019-10-12 21:02:38 +02:00
|
|
|
}
|
|
|
|
|
2017-12-19 01:59:29 +01:00
|
|
|
fn main() {
|
2021-02-07 12:16:11 +00:00
|
|
|
let tests: &[(_, fn())] = &[
|
|
|
|
("test", test),
|
|
|
|
("testrust", testrust),
|
|
|
|
];
|
|
|
|
|
2017-12-19 01:59:29 +01:00
|
|
|
let args: Vec<String> = env::args().collect();
|
2019-10-12 21:02:38 +02:00
|
|
|
if args.len() > 1 {
|
|
|
|
// This is inside the self-executed command.
|
2021-02-07 12:16:11 +00:00
|
|
|
for (a,f) in tests {
|
|
|
|
if &args[1] == a { return f() }
|
2019-10-12 21:02:38 +02:00
|
|
|
}
|
2021-02-07 12:16:11 +00:00
|
|
|
panic!("bad test");
|
2017-12-19 01:59:29 +01:00
|
|
|
}
|
|
|
|
|
2021-02-07 12:16:11 +00:00
|
|
|
let execute_self_expecting_abort = |arg| {
|
|
|
|
let mut p = Command::new(&args[0])
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.stdin(Stdio::piped())
|
|
|
|
.arg(arg).spawn().unwrap();
|
|
|
|
assert!(!p.wait().unwrap().success());
|
|
|
|
};
|
|
|
|
|
|
|
|
for (a,_f) in tests {
|
|
|
|
execute_self_expecting_abort(a);
|
|
|
|
}
|
2017-12-19 01:59:29 +01:00
|
|
|
}
|