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