]> git.proxmox.com Git - rustc.git/blob - src/test/ui/command/command-exec.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / test / ui / command / command-exec.rs
1 // run-pass
2
3 #![allow(stable_features)]
4 // ignore-windows - this is a unix-specific test
5 // ignore-pretty issue #37199
6 // ignore-cloudabi no processes
7 // ignore-emscripten no processes
8 // ignore-sgx no processes
9
10 #![feature(process_exec)]
11
12 use std::env;
13 use std::os::unix::process::CommandExt;
14 use std::process::Command;
15
16 fn main() {
17 let mut args = env::args();
18 let me = args.next().unwrap();
19
20 if let Some(arg) = args.next() {
21 match &arg[..] {
22 "test1" => println!("passed"),
23
24 "exec-test1" => {
25 let err = Command::new(&me).arg("test1").exec();
26 panic!("failed to spawn: {}", err);
27 }
28
29 "exec-test2" => {
30 Command::new("/path/to/nowhere").exec();
31 println!("passed");
32 }
33
34 "exec-test3" => {
35 Command::new(&me).arg("bad\0").exec();
36 println!("passed");
37 }
38
39 "exec-test4" => {
40 Command::new(&me).current_dir("/path/to/nowhere").exec();
41 println!("passed");
42 }
43
44 "exec-test5" => {
45 env::set_var("VARIABLE", "ABC");
46 Command::new("definitely-not-a-real-binary").env("VARIABLE", "XYZ").exec();
47 assert_eq!(env::var("VARIABLE").unwrap(), "ABC");
48 println!("passed");
49 }
50
51 "exec-test6" => {
52 let err = Command::new("echo").arg("passed").env_clear().exec();
53 panic!("failed to spawn: {}", err);
54 }
55
56 "exec-test7" => {
57 let err = Command::new("echo").arg("passed").env_remove("PATH").exec();
58 panic!("failed to spawn: {}", err);
59 }
60
61 _ => panic!("unknown argument: {}", arg),
62 }
63 return
64 }
65
66 let output = Command::new(&me).arg("exec-test1").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-test2").output().unwrap();
72 assert!(output.status.success());
73 assert!(output.stderr.is_empty());
74 assert_eq!(output.stdout, b"passed\n");
75
76 let output = Command::new(&me).arg("exec-test3").output().unwrap();
77 assert!(output.status.success());
78 assert!(output.stderr.is_empty());
79 assert_eq!(output.stdout, b"passed\n");
80
81 let output = Command::new(&me).arg("exec-test4").output().unwrap();
82 assert!(output.status.success());
83 assert!(output.stderr.is_empty());
84 assert_eq!(output.stdout, b"passed\n");
85
86 let output = Command::new(&me).arg("exec-test5").output().unwrap();
87 assert!(output.status.success());
88 assert!(output.stderr.is_empty());
89 assert_eq!(output.stdout, b"passed\n");
90
91 if cfg!(target_os = "linux") {
92 let output = Command::new(&me).arg("exec-test6").output().unwrap();
93 println!("{:?}", output);
94 assert!(output.status.success());
95 assert!(output.stderr.is_empty());
96 assert_eq!(output.stdout, b"passed\n");
97
98 let output = Command::new(&me).arg("exec-test7").output().unwrap();
99 println!("{:?}", output);
100 assert!(output.status.success());
101 assert!(output.stderr.is_empty());
102 assert_eq!(output.stdout, b"passed\n");
103 }
104 }