]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/command-exec.rs
Imported Upstream version 1.11.0+dfsg1
[rustc.git] / src / test / run-pass / command-exec.rs
1 // Copyright 2016 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 // ignore-windows - this is a unix-specific test
12 // ignore-pretty
13
14 #![feature(process_exec)]
15
16 use std::env;
17 use std::os::unix::process::CommandExt;
18 use std::process::Command;
19
20 fn main() {
21 let mut args = env::args();
22 let me = args.next().unwrap();
23
24 if let Some(arg) = args.next() {
25 match &arg[..] {
26 "test1" => println!("passed"),
27
28 "exec-test1" => {
29 let err = Command::new(&me).arg("test1").exec();
30 panic!("failed to spawn: {}", err);
31 }
32
33 "exec-test2" => {
34 Command::new("/path/to/nowhere").exec();
35 println!("passed");
36 }
37
38 "exec-test3" => {
39 Command::new(&me).arg("bad\0").exec();
40 println!("passed");
41 }
42
43 "exec-test4" => {
44 Command::new(&me).current_dir("/path/to/nowhere").exec();
45 println!("passed");
46 }
47
48 _ => panic!("unknown argument: {}", arg),
49 }
50 return
51 }
52
53 let output = Command::new(&me).arg("exec-test1").output().unwrap();
54 assert!(output.status.success());
55 assert!(output.stderr.is_empty());
56 assert_eq!(output.stdout, b"passed\n");
57
58 let output = Command::new(&me).arg("exec-test2").output().unwrap();
59 assert!(output.status.success());
60 assert!(output.stderr.is_empty());
61 assert_eq!(output.stdout, b"passed\n");
62
63 let output = Command::new(&me).arg("exec-test3").output().unwrap();
64 assert!(output.status.success());
65 assert!(output.stderr.is_empty());
66 assert_eq!(output.stdout, b"passed\n");
67
68 let output = Command::new(&me).arg("exec-test4").output().unwrap();
69 assert!(output.status.success());
70 assert!(output.stderr.is_empty());
71 assert_eq!(output.stdout, b"passed\n");
72 }