]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/running-with-no-runtime.rs
ed4c20c80943ab58ca9a98ef0683e8dfc7a3e54a
[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 extern crate rustrt;
12
13 use std::io::process::{Command, ProcessOutput};
14 use std::os;
15 use std::str;
16 use std::rt;
17
18 use rustrt::unwind::try;
19
20 local_data_key!(foo: int)
21
22 #[start]
23 fn start(argc: int, argv: *const *const u8) -> int {
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!(try(|| spawn(proc() {})).is_err()),
32                 6 => assert!(Command::new("test").spawn().is_err()),
33                 7 => assert!(foo.get().is_none()),
34                 8 => assert!(try(|| { foo.replace(Some(3)); }).is_err()),
35                 _ => panic!()
36             }
37         }
38         return 0
39     }
40
41     rt::start(argc, argv, main)
42 }
43
44 fn main() {
45     let args = os::args();
46     let me = args[0].as_slice();
47
48     let x: &[u8] = &[1u8];
49     pass(Command::new(me).arg(x).output().unwrap());
50     let x: &[u8] = &[2u8];
51     pass(Command::new(me).arg(x).output().unwrap());
52     let x: &[u8] = &[3u8];
53     pass(Command::new(me).arg(x).output().unwrap());
54     let x: &[u8] = &[4u8];
55     pass(Command::new(me).arg(x).output().unwrap());
56     let x: &[u8] = &[5u8];
57     pass(Command::new(me).arg(x).output().unwrap());
58     let x: &[u8] = &[6u8];
59     pass(Command::new(me).arg(x).output().unwrap());
60     let x: &[u8] = &[7u8];
61     pass(Command::new(me).arg(x).output().unwrap());
62     let x: &[u8] = &[8u8];
63     pass(Command::new(me).arg(x).output().unwrap());
64 }
65
66 fn pass(output: ProcessOutput) {
67     if !output.status.success() {
68         println!("{}", str::from_utf8(output.output.as_slice()));
69         println!("{}", str::from_utf8(output.error.as_slice()));
70     }
71 }