]>
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; |
85aaf69f | 14 | use std::old_io::process::{Command, ProcessOutput}; |
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 { | |
26 | match **argv.offset(1) { | |
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()), | |
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 | }; | |
85aaf69f | 44 | let me = &*args[0]; |
1a4d82fc | 45 | |
c34b1796 | 46 | let x: &[u8] = &[1]; |
1a4d82fc | 47 | pass(Command::new(me).arg(x).output().unwrap()); |
c34b1796 | 48 | let x: &[u8] = &[2]; |
1a4d82fc | 49 | pass(Command::new(me).arg(x).output().unwrap()); |
c34b1796 | 50 | let x: &[u8] = &[3]; |
1a4d82fc | 51 | pass(Command::new(me).arg(x).output().unwrap()); |
c34b1796 | 52 | let x: &[u8] = &[4]; |
1a4d82fc | 53 | pass(Command::new(me).arg(x).output().unwrap()); |
c34b1796 | 54 | let x: &[u8] = &[5]; |
1a4d82fc JJ |
55 | pass(Command::new(me).arg(x).output().unwrap()); |
56 | ||
57 | 0 | |
58 | } | |
59 | ||
60 | fn pass(output: ProcessOutput) { | |
61 | if !output.status.success() { | |
85aaf69f SL |
62 | println!("{:?}", str::from_utf8(&output.output)); |
63 | println!("{:?}", str::from_utf8(&output.error)); | |
1a4d82fc JJ |
64 | } |
65 | } |