]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/running-with-no-runtime.rs
Rollup merge of #58306 - GuillaumeGomez:crate-browser-history, r=QuietMisdreavus
[rust.git] / src / test / run-pass / running-with-no-runtime.rs
1 // ignore-cloudabi spawning processes is not supported
2 // ignore-emscripten spawning processes is not supported
3
4 #![feature(start)]
5
6 use std::ffi::CStr;
7 use std::process::{Command, Output};
8 use std::panic;
9 use std::str;
10
11 #[start]
12 fn start(argc: isize, argv: *const *const u8) -> isize {
13     if argc > 1 {
14         unsafe {
15             match **argv.offset(1) as char {
16                 '1' => {}
17                 '2' => println!("foo"),
18                 '3' => assert!(panic::catch_unwind(|| {}).is_ok()),
19                 '4' => assert!(panic::catch_unwind(|| panic!()).is_err()),
20                 '5' => assert!(Command::new("test").spawn().is_err()),
21                 _ => panic!()
22             }
23         }
24         return 0
25     }
26
27     let args = unsafe {
28         (0..argc as usize).map(|i| {
29             let ptr = *argv.add(i) as *const _;
30             CStr::from_ptr(ptr).to_bytes().to_vec()
31         }).collect::<Vec<_>>()
32     };
33     let me = String::from_utf8(args[0].to_vec()).unwrap();
34
35     pass(Command::new(&me).arg("1").output().unwrap());
36     pass(Command::new(&me).arg("2").output().unwrap());
37     pass(Command::new(&me).arg("3").output().unwrap());
38     pass(Command::new(&me).arg("4").output().unwrap());
39     pass(Command::new(&me).arg("5").output().unwrap());
40
41     0
42 }
43
44 fn pass(output: Output) {
45     if !output.status.success() {
46         println!("{:?}", str::from_utf8(&output.stdout));
47         println!("{:?}", str::from_utf8(&output.stderr));
48     }
49 }