2018-08-30 07:18:55 -05:00
|
|
|
//@ run-pass
|
2024-03-06 14:44:54 -06:00
|
|
|
//@ ignore-wasm32 no processes
|
2019-04-24 11:26:33 -05:00
|
|
|
//@ ignore-sgx no processes
|
2019-07-31 19:09:07 -05:00
|
|
|
//@ ignore-vxworks no 'env'
|
2022-09-12 17:38:49 -05:00
|
|
|
//@ ignore-fuchsia no 'env'
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2015-04-10 13:12:43 -05:00
|
|
|
use std::process::Command;
|
2015-02-13 14:08:05 -06:00
|
|
|
use std::env;
|
2014-10-03 09:16:05 -05:00
|
|
|
|
|
|
|
#[cfg(all(unix, not(target_os="android")))]
|
|
|
|
pub fn env_cmd() -> Command {
|
|
|
|
Command::new("env")
|
|
|
|
}
|
|
|
|
#[cfg(target_os="android")]
|
|
|
|
pub fn env_cmd() -> Command {
|
|
|
|
let mut cmd = Command::new("/system/bin/sh");
|
|
|
|
cmd.arg("-c").arg("set");
|
|
|
|
cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
pub fn env_cmd() -> Command {
|
|
|
|
let mut cmd = Command::new("cmd");
|
|
|
|
cmd.arg("/c").arg("set");
|
|
|
|
cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// save original environment
|
2015-02-13 14:08:05 -06:00
|
|
|
let old_env = env::var_os("RUN_TEST_NEW_ENV");
|
2014-10-03 09:16:05 -05:00
|
|
|
|
2015-02-13 14:08:05 -06:00
|
|
|
env::set_var("RUN_TEST_NEW_ENV", "123");
|
2014-10-03 09:16:05 -05:00
|
|
|
|
|
|
|
let mut cmd = env_cmd();
|
|
|
|
cmd.env_remove("RUN_TEST_NEW_ENV");
|
|
|
|
|
|
|
|
// restore original environment
|
|
|
|
match old_env {
|
2015-02-13 14:08:05 -06:00
|
|
|
None => env::remove_var("RUN_TEST_NEW_ENV"),
|
|
|
|
Some(val) => env::set_var("RUN_TEST_NEW_ENV", &val)
|
2014-10-03 09:16:05 -05:00
|
|
|
}
|
|
|
|
|
2017-01-10 12:00:07 -06:00
|
|
|
let result = cmd.output().unwrap();
|
2015-04-10 13:12:43 -05:00
|
|
|
let output = String::from_utf8_lossy(&result.stdout);
|
2014-10-03 09:16:05 -05:00
|
|
|
|
2015-01-26 20:21:15 -06:00
|
|
|
assert!(!output.contains("RUN_TEST_NEW_ENV"),
|
2014-10-03 09:16:05 -05:00
|
|
|
"found RUN_TEST_NEW_ENV inside of:\n\n{}", output);
|
|
|
|
}
|