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