2014-06-04 17:54:35 +00:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2016-05-24 21:24:44 +00:00
|
|
|
#![feature(start)]
|
2015-01-16 18:55:24 +00:00
|
|
|
|
2015-03-30 18:00:05 +00:00
|
|
|
use std::ffi::CStr;
|
2015-04-10 18:12:43 +00:00
|
|
|
use std::process::{Command, Output};
|
2015-08-31 15:51:53 +00:00
|
|
|
use std::panic;
|
2014-12-22 17:04:23 +00:00
|
|
|
use std::str;
|
2014-11-14 22:38:41 +00:00
|
|
|
|
2014-06-04 17:54:35 +00:00
|
|
|
#[start]
|
2015-03-26 00:06:52 +00:00
|
|
|
fn start(argc: isize, argv: *const *const u8) -> isize {
|
2014-06-04 17:54:35 +00:00
|
|
|
if argc > 1 {
|
|
|
|
unsafe {
|
2015-04-10 18:12:43 +00:00
|
|
|
match **argv.offset(1) as char {
|
|
|
|
'1' => {}
|
|
|
|
'2' => println!("foo"),
|
2016-05-24 21:24:44 +00:00
|
|
|
'3' => assert!(panic::catch_unwind(|| {}).is_ok()),
|
|
|
|
'4' => assert!(panic::catch_unwind(|| panic!()).is_err()),
|
2015-04-10 18:12:43 +00:00
|
|
|
'5' => assert!(Command::new("test").spawn().is_err()),
|
2014-10-09 19:17:22 +00:00
|
|
|
_ => panic!()
|
2014-06-04 17:54:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2014-12-14 08:05:32 +00:00
|
|
|
let args = unsafe {
|
2015-03-26 00:06:52 +00:00
|
|
|
(0..argc as usize).map(|i| {
|
|
|
|
let ptr = *argv.offset(i as isize) as *const _;
|
2015-03-30 18:00:05 +00:00
|
|
|
CStr::from_ptr(ptr).to_bytes().to_vec()
|
2015-01-02 07:53:35 +00:00
|
|
|
}).collect::<Vec<_>>()
|
2014-12-14 08:05:32 +00:00
|
|
|
};
|
2015-04-10 18:12:43 +00:00
|
|
|
let me = String::from_utf8(args[0].to_vec()).unwrap();
|
2014-06-04 17:54:35 +00:00
|
|
|
|
2015-04-10 18:12:43 +00:00
|
|
|
pass(Command::new(&me).arg("1").output().unwrap());
|
|
|
|
pass(Command::new(&me).arg("2").output().unwrap());
|
|
|
|
pass(Command::new(&me).arg("3").output().unwrap());
|
|
|
|
pass(Command::new(&me).arg("4").output().unwrap());
|
|
|
|
pass(Command::new(&me).arg("5").output().unwrap());
|
2014-12-14 08:05:32 +00:00
|
|
|
|
|
|
|
0
|
2014-06-04 17:54:35 +00:00
|
|
|
}
|
|
|
|
|
2015-04-10 18:12:43 +00:00
|
|
|
fn pass(output: Output) {
|
2014-06-04 17:54:35 +00:00
|
|
|
if !output.status.success() {
|
2015-04-10 18:12:43 +00:00
|
|
|
println!("{:?}", str::from_utf8(&output.stdout));
|
|
|
|
println!("{:?}", str::from_utf8(&output.stderr));
|
2014-06-04 17:54:35 +00:00
|
|
|
}
|
|
|
|
}
|