]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/running-with-no-runtime.rs
Fix misspelled comments.
[rust.git] / src / test / run-pass / running-with-no-runtime.rs
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
11 use std::ffi;
12 use std::io::process::{Command, ProcessOutput};
13 use std::os;
14 use std::rt::unwind::try;
15 use std::rt;
16 use std::str;
17 use std::thread::Thread;
18 use std::thunk::Thunk;
19
20 #[start]
21 fn start(argc: int, argv: *const *const u8) -> int {
22     if argc > 1 {
23         unsafe {
24             match **argv.offset(1) {
25                 1 => {}
26                 2 => println!("foo"),
27                 3 => assert!(try(|| {}).is_ok()),
28                 4 => assert!(try(|| panic!()).is_err()),
29                 5 => assert!(Command::new("test").spawn().is_err()),
30                 _ => panic!()
31             }
32         }
33         return 0
34     }
35
36     let args = unsafe {
37         range(0, argc as uint).map(|i| {
38             let ptr = *argv.offset(i as int) as *const _;
39             ffi::c_str_to_bytes(&ptr).to_vec()
40         }).collect::<Vec<_>>()
41     };
42     let me = args[0].as_slice();
43
44     let x: &[u8] = &[1u8];
45     pass(Command::new(me).arg(x).output().unwrap());
46     let x: &[u8] = &[2u8];
47     pass(Command::new(me).arg(x).output().unwrap());
48     let x: &[u8] = &[3u8];
49     pass(Command::new(me).arg(x).output().unwrap());
50     let x: &[u8] = &[4u8];
51     pass(Command::new(me).arg(x).output().unwrap());
52     let x: &[u8] = &[5u8];
53     pass(Command::new(me).arg(x).output().unwrap());
54
55     0
56 }
57
58 fn pass(output: ProcessOutput) {
59     if !output.status.success() {
60         println!("{}", str::from_utf8(output.output.as_slice()));
61         println!("{}", str::from_utf8(output.error.as_slice()));
62     }
63 }