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