]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
abe05a73 | 11 | // ignore-emscripten spawning processes is not supported |
5bcae85e | 12 | |
3157f602 | 13 | #![feature(start)] |
85aaf69f | 14 | |
c34b1796 | 15 | use std::ffi::CStr; |
9346a6ac | 16 | use std::process::{Command, Output}; |
9cc50fc6 | 17 | use std::panic; |
1a4d82fc | 18 | use std::str; |
1a4d82fc JJ |
19 | |
20 | #[start] | |
c34b1796 | 21 | fn start(argc: isize, argv: *const *const u8) -> isize { |
1a4d82fc JJ |
22 | if argc > 1 { |
23 | unsafe { | |
9346a6ac AL |
24 | match **argv.offset(1) as char { |
25 | '1' => {} | |
26 | '2' => println!("foo"), | |
3157f602 XL |
27 | '3' => assert!(panic::catch_unwind(|| {}).is_ok()), |
28 | '4' => assert!(panic::catch_unwind(|| panic!()).is_err()), | |
9346a6ac | 29 | '5' => assert!(Command::new("test").spawn().is_err()), |
1a4d82fc JJ |
30 | _ => panic!() |
31 | } | |
32 | } | |
33 | return 0 | |
34 | } | |
35 | ||
36 | let args = unsafe { | |
c34b1796 AL |
37 | (0..argc as usize).map(|i| { |
38 | let ptr = *argv.offset(i as isize) as *const _; | |
39 | CStr::from_ptr(ptr).to_bytes().to_vec() | |
1a4d82fc JJ |
40 | }).collect::<Vec<_>>() |
41 | }; | |
9346a6ac | 42 | let me = String::from_utf8(args[0].to_vec()).unwrap(); |
1a4d82fc | 43 | |
9346a6ac AL |
44 | pass(Command::new(&me).arg("1").output().unwrap()); |
45 | pass(Command::new(&me).arg("2").output().unwrap()); | |
46 | pass(Command::new(&me).arg("3").output().unwrap()); | |
47 | pass(Command::new(&me).arg("4").output().unwrap()); | |
48 | pass(Command::new(&me).arg("5").output().unwrap()); | |
1a4d82fc JJ |
49 | |
50 | 0 | |
51 | } | |
52 | ||
9346a6ac | 53 | fn pass(output: Output) { |
1a4d82fc | 54 | if !output.status.success() { |
9346a6ac AL |
55 | println!("{:?}", str::from_utf8(&output.stdout)); |
56 | println!("{:?}", str::from_utf8(&output.stderr)); | |
1a4d82fc JJ |
57 | } |
58 | } |