2019-07-26 21:54:25 +00:00
|
|
|
//@ run-pass
|
2024-03-06 20:44:54 +00:00
|
|
|
//@ ignore-wasm32 spawning processes is not supported
|
2019-04-24 16:26:33 +00:00
|
|
|
//@ ignore-sgx no processes
|
2016-08-08 23:39:37 +00:00
|
|
|
|
2016-05-24 21:24:44 +00:00
|
|
|
#![feature(start)]
|
2015-01-16 18:55:24 +00:00
|
|
|
|
2015-03-30 18:00:05 +00:00
|
|
|
use std::ffi::CStr;
|
2015-04-10 18:12:43 +00:00
|
|
|
use std::process::{Command, Output};
|
2015-08-31 15:51:53 +00:00
|
|
|
use std::panic;
|
2014-12-22 17:04:23 +00:00
|
|
|
use std::str;
|
2014-11-14 22:38:41 +00:00
|
|
|
|
2014-06-04 17:54:35 +00:00
|
|
|
#[start]
|
2015-03-26 00:06:52 +00:00
|
|
|
fn start(argc: isize, argv: *const *const u8) -> isize {
|
2014-06-04 17:54:35 +00:00
|
|
|
if argc > 1 {
|
|
|
|
unsafe {
|
2015-04-10 18:12:43 +00:00
|
|
|
match **argv.offset(1) as char {
|
|
|
|
'1' => {}
|
|
|
|
'2' => println!("foo"),
|
2016-05-24 21:24:44 +00:00
|
|
|
'3' => assert!(panic::catch_unwind(|| {}).is_ok()),
|
|
|
|
'4' => assert!(panic::catch_unwind(|| panic!()).is_err()),
|
2015-04-10 18:12:43 +00:00
|
|
|
'5' => assert!(Command::new("test").spawn().is_err()),
|
2014-10-09 19:17:22 +00:00
|
|
|
_ => panic!()
|
2014-06-04 17:54:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2014-12-14 08:05:32 +00:00
|
|
|
let args = unsafe {
|
2015-03-26 00:06:52 +00:00
|
|
|
(0..argc as usize).map(|i| {
|
2018-08-20 02:16:22 +00:00
|
|
|
let ptr = *argv.add(i) as *const _;
|
2015-03-30 18:00:05 +00:00
|
|
|
CStr::from_ptr(ptr).to_bytes().to_vec()
|
2015-01-02 07:53:35 +00:00
|
|
|
}).collect::<Vec<_>>()
|
2014-12-14 08:05:32 +00:00
|
|
|
};
|
2015-04-10 18:12:43 +00:00
|
|
|
let me = String::from_utf8(args[0].to_vec()).unwrap();
|
2014-06-04 17:54:35 +00:00
|
|
|
|
2015-04-10 18:12:43 +00: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 08:05:32 +00:00
|
|
|
|
|
|
|
0
|
2014-06-04 17:54:35 +00:00
|
|
|
}
|
|
|
|
|
2015-04-10 18:12:43 +00:00
|
|
|
fn pass(output: Output) {
|
2014-06-04 17:54:35 +00:00
|
|
|
if !output.status.success() {
|
2015-04-10 18:12:43 +00:00
|
|
|
println!("{:?}", str::from_utf8(&output.stdout));
|
|
|
|
println!("{:?}", str::from_utf8(&output.stderr));
|
2014-06-04 17:54:35 +00:00
|
|
|
}
|
|
|
|
}
|