2019-07-27 00:54:25 +03:00
|
|
|
//@ run-pass
|
2025-01-23 16:36:54 +08:00
|
|
|
//@ needs-subprocess
|
2016-08-09 01:39:37 +02:00
|
|
|
|
2024-12-14 09:13:12 +01:00
|
|
|
#![no_main]
|
2015-01-16 10:55:24 -08:00
|
|
|
|
2015-03-30 11:00:05 -07:00
|
|
|
use std::ffi::CStr;
|
2015-04-10 11:12:43 -07:00
|
|
|
use std::process::{Command, Output};
|
2015-08-31 08:51:53 -07:00
|
|
|
use std::panic;
|
2014-12-22 09:04:23 -08:00
|
|
|
use std::str;
|
2014-11-14 14:38:41 -08:00
|
|
|
|
2024-12-14 09:13:12 +01:00
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn main(argc: core::ffi::c_int, argv: *const *const u8) -> core::ffi::c_int {
|
2014-06-04 10:54:35 -07:00
|
|
|
if argc > 1 {
|
|
|
|
unsafe {
|
2015-04-10 11:12:43 -07:00
|
|
|
match **argv.offset(1) as char {
|
|
|
|
'1' => {}
|
|
|
|
'2' => println!("foo"),
|
2016-05-24 14:24:44 -07:00
|
|
|
'3' => assert!(panic::catch_unwind(|| {}).is_ok()),
|
|
|
|
'4' => assert!(panic::catch_unwind(|| panic!()).is_err()),
|
2015-04-10 11:12:43 -07:00
|
|
|
'5' => assert!(Command::new("test").spawn().is_err()),
|
2014-10-09 15:17:22 -04:00
|
|
|
_ => panic!()
|
2014-06-04 10:54:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2014-12-14 00:05:32 -08:00
|
|
|
let args = unsafe {
|
2015-03-25 17:06:52 -07:00
|
|
|
(0..argc as usize).map(|i| {
|
2018-08-19 22:16:22 -04:00
|
|
|
let ptr = *argv.add(i) as *const _;
|
2015-03-30 11:00:05 -07:00
|
|
|
CStr::from_ptr(ptr).to_bytes().to_vec()
|
2015-01-01 23:53:35 -08:00
|
|
|
}).collect::<Vec<_>>()
|
2014-12-14 00:05:32 -08:00
|
|
|
};
|
2015-04-10 11:12:43 -07:00
|
|
|
let me = String::from_utf8(args[0].to_vec()).unwrap();
|
2014-06-04 10:54:35 -07:00
|
|
|
|
2015-04-10 11:12:43 -07:00
|
|
|
pass(Command::new(&me).arg("1").output().unwrap());
|
|
|
|
pass(Command::new(&me).arg("2").output().unwrap());
|
|
|
|
pass(Command::new(&me).arg("3").output().unwrap());
|
|
|
|
pass(Command::new(&me).arg("4").output().unwrap());
|
|
|
|
pass(Command::new(&me).arg("5").output().unwrap());
|
2014-12-14 00:05:32 -08:00
|
|
|
|
|
|
|
0
|
2014-06-04 10:54:35 -07:00
|
|
|
}
|
|
|
|
|
2015-04-10 11:12:43 -07:00
|
|
|
fn pass(output: Output) {
|
2014-06-04 10:54:35 -07:00
|
|
|
if !output.status.success() {
|
2015-04-10 11:12:43 -07:00
|
|
|
println!("{:?}", str::from_utf8(&output.stdout));
|
|
|
|
println!("{:?}", str::from_utf8(&output.stderr));
|
2014-06-04 10:54:35 -07:00
|
|
|
}
|
|
|
|
}
|