]> git.proxmox.com Git - rustc.git/blame - src/test/ui/process/process-remove-from-env.rs
New upstream version 1.65.0+dfsg1
[rustc.git] / src / test / ui / process / process-remove-from-env.rs
CommitLineData
b7449926 1// run-pass
abe05a73 2// ignore-emscripten no processes
48663c56 3// ignore-sgx no processes
416331ca 4// ignore-vxworks no 'env'
f2b60f7d 5// ignore-fuchsia no 'env'
c34b1796 6
9346a6ac 7use std::process::Command;
85aaf69f 8use std::env;
1a4d82fc
JJ
9
10#[cfg(all(unix, not(target_os="android")))]
11pub fn env_cmd() -> Command {
12 Command::new("env")
13}
14#[cfg(target_os="android")]
15pub fn env_cmd() -> Command {
16 let mut cmd = Command::new("/system/bin/sh");
17 cmd.arg("-c").arg("set");
18 cmd
19}
20
21#[cfg(windows)]
22pub fn env_cmd() -> Command {
23 let mut cmd = Command::new("cmd");
24 cmd.arg("/c").arg("set");
25 cmd
26}
27
28fn main() {
29 // save original environment
85aaf69f 30 let old_env = env::var_os("RUN_TEST_NEW_ENV");
1a4d82fc 31
85aaf69f 32 env::set_var("RUN_TEST_NEW_ENV", "123");
1a4d82fc
JJ
33
34 let mut cmd = env_cmd();
35 cmd.env_remove("RUN_TEST_NEW_ENV");
36
37 // restore original environment
38 match old_env {
85aaf69f
SL
39 None => env::remove_var("RUN_TEST_NEW_ENV"),
40 Some(val) => env::set_var("RUN_TEST_NEW_ENV", &val)
1a4d82fc
JJ
41 }
42
32a655c1 43 let result = cmd.output().unwrap();
9346a6ac 44 let output = String::from_utf8_lossy(&result.stdout);
1a4d82fc 45
85aaf69f 46 assert!(!output.contains("RUN_TEST_NEW_ENV"),
1a4d82fc
JJ
47 "found RUN_TEST_NEW_ENV inside of:\n\n{}", output);
48}