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