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