]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/command/command-exec.rs
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
10 #![feature(process_exec)]
13 use std
::os
::unix
::process
::CommandExt
;
14 use std
::process
::Command
;
17 let mut args
= env
::args();
18 let me
= args
.next().unwrap();
20 if let Some(arg
) = args
.next() {
22 "test1" => println
!("passed"),
25 let err
= Command
::new(&me
).arg("test1").exec();
26 panic
!("failed to spawn: {}", err
);
30 Command
::new("/path/to/nowhere").exec();
35 Command
::new(&me
).arg("bad\0").exec();
40 Command
::new(&me
).current_dir("/path/to/nowhere").exec();
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");
52 let err
= Command
::new("echo").arg("passed").env_clear().exec();
53 panic
!("failed to spawn: {}", err
);
57 let err
= Command
::new("echo").arg("passed").env_remove("PATH").exec();
58 panic
!("failed to spawn: {}", err
);
61 _
=> panic
!("unknown argument: {}", arg
),
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");
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");
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");
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");
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");
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");
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");