]>
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 | ||
62682a34 | 11 | #![feature(catch_panic, start)] |
85aaf69f | 12 | |
c34b1796 | 13 | use std::ffi::CStr; |
9346a6ac | 14 | use std::process::{Command, Output}; |
62682a34 | 15 | use std::thread; |
1a4d82fc | 16 | use std::str; |
1a4d82fc JJ |
17 | |
18 | #[start] | |
c34b1796 | 19 | fn start(argc: isize, argv: *const *const u8) -> isize { |
1a4d82fc JJ |
20 | if argc > 1 { |
21 | unsafe { | |
9346a6ac AL |
22 | match **argv.offset(1) as char { |
23 | '1' => {} | |
24 | '2' => println!("foo"), | |
62682a34 SL |
25 | '3' => assert!(thread::catch_panic(|| {}).is_ok()), |
26 | '4' => assert!(thread::catch_panic(|| panic!()).is_err()), | |
9346a6ac | 27 | '5' => assert!(Command::new("test").spawn().is_err()), |
1a4d82fc JJ |
28 | _ => panic!() |
29 | } | |
30 | } | |
31 | return 0 | |
32 | } | |
33 | ||
34 | let args = unsafe { | |
c34b1796 AL |
35 | (0..argc as usize).map(|i| { |
36 | let ptr = *argv.offset(i as isize) as *const _; | |
37 | CStr::from_ptr(ptr).to_bytes().to_vec() | |
1a4d82fc JJ |
38 | }).collect::<Vec<_>>() |
39 | }; | |
9346a6ac | 40 | let me = String::from_utf8(args[0].to_vec()).unwrap(); |
1a4d82fc | 41 | |
9346a6ac AL |
42 | pass(Command::new(&me).arg("1").output().unwrap()); |
43 | pass(Command::new(&me).arg("2").output().unwrap()); | |
44 | pass(Command::new(&me).arg("3").output().unwrap()); | |
45 | pass(Command::new(&me).arg("4").output().unwrap()); | |
46 | pass(Command::new(&me).arg("5").output().unwrap()); | |
1a4d82fc JJ |
47 | |
48 | 0 | |
49 | } | |
50 | ||
9346a6ac | 51 | fn pass(output: Output) { |
1a4d82fc | 52 | if !output.status.success() { |
9346a6ac AL |
53 | println!("{:?}", str::from_utf8(&output.stdout)); |
54 | println!("{:?}", str::from_utf8(&output.stderr)); | |
1a4d82fc JJ |
55 | } |
56 | } |