]> git.lizzy.rs Git - rust.git/blob - src/test/ui/process/process-remove-from-env.rs
Rollup merge of #90498 - joshtriplett:target-tier-policy-draft-updates, r=Mark-Simulacrum
[rust.git] / src / test / ui / process / process-remove-from-env.rs
1 // run-pass
2 // ignore-emscripten no processes
3 // ignore-sgx no processes
4 // ignore-vxworks no 'env'
5
6 use std::process::Command;
7 use std::env;
8
9 #[cfg(all(unix, not(target_os="android")))]
10 pub fn env_cmd() -> Command {
11     Command::new("env")
12 }
13 #[cfg(target_os="android")]
14 pub fn env_cmd() -> Command {
15     let mut cmd = Command::new("/system/bin/sh");
16     cmd.arg("-c").arg("set");
17     cmd
18 }
19
20 #[cfg(windows)]
21 pub fn env_cmd() -> Command {
22     let mut cmd = Command::new("cmd");
23     cmd.arg("/c").arg("set");
24     cmd
25 }
26
27 fn main() {
28     // save original environment
29     let old_env = env::var_os("RUN_TEST_NEW_ENV");
30
31     env::set_var("RUN_TEST_NEW_ENV", "123");
32
33     let mut cmd = env_cmd();
34     cmd.env_remove("RUN_TEST_NEW_ENV");
35
36     // restore original environment
37     match old_env {
38         None => env::remove_var("RUN_TEST_NEW_ENV"),
39         Some(val) => env::set_var("RUN_TEST_NEW_ENV", &val)
40     }
41
42     let result = cmd.output().unwrap();
43     let output = String::from_utf8_lossy(&result.stdout);
44
45     assert!(!output.contains("RUN_TEST_NEW_ENV"),
46             "found RUN_TEST_NEW_ENV inside of:\n\n{}", output);
47 }