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