rust/tests/ui/runtime/running-with-no-runtime.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.4 KiB
Rust
Raw Normal View History

//@ run-pass
//@ ignore-wasm32 spawning processes is not supported
2019-04-24 16:26:33 +00:00
//@ ignore-sgx no processes
#![feature(start)]
use std::ffi::CStr;
2015-04-10 18:12:43 +00:00
use std::process::{Command, Output};
use std::panic;
use std::str;
#[start]
fn start(argc: isize, argv: *const *const u8) -> isize {
if argc > 1 {
unsafe {
2015-04-10 18:12:43 +00:00
match **argv.offset(1) as char {
'1' => {}
'2' => println!("foo"),
'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()),
_ => panic!()
}
}
return 0
}
let args = unsafe {
(0..argc as usize).map(|i| {
let ptr = *argv.add(i) as *const _;
CStr::from_ptr(ptr).to_bytes().to_vec()
}).collect::<Vec<_>>()
};
2015-04-10 18:12:43 +00:00
let me = String::from_utf8(args[0].to_vec()).unwrap();
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());
0
}
2015-04-10 18:12:43 +00:00
fn pass(output: Output) {
if !output.status.success() {
2015-04-10 18:12:43 +00:00
println!("{:?}", str::from_utf8(&output.stdout));
println!("{:?}", str::from_utf8(&output.stderr));
}
}