2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2017-10-17 18:45:42 -07:00
|
|
|
// ignore-emscripten no processes
|
2019-04-24 09:26:33 -07:00
|
|
|
// ignore-sgx no processes
|
2019-07-31 17:09:07 -07:00
|
|
|
// ignore-vxworks no 'env'
|
2022-09-12 22:38:49 +00:00
|
|
|
// ignore-fuchsia no 'env'
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2015-04-10 11:12:43 -07:00
|
|
|
use std::process::Command;
|
2015-02-13 22:08:05 +02:00
|
|
|
use std::env;
|
2014-10-03 17:16:05 +03: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 22:08:05 +02:00
|
|
|
let old_env = env::var_os("RUN_TEST_NEW_ENV");
|
2014-10-03 17:16:05 +03:00
|
|
|
|
2015-02-13 22:08:05 +02:00
|
|
|
env::set_var("RUN_TEST_NEW_ENV", "123");
|
2014-10-03 17:16:05 +03:00
|
|
|
|
|
|
|
let mut cmd = env_cmd();
|
|
|
|
cmd.env_remove("RUN_TEST_NEW_ENV");
|
|
|
|
|
|
|
|
// restore original environment
|
|
|
|
match old_env {
|
2015-02-13 22:08:05 +02:00
|
|
|
None => env::remove_var("RUN_TEST_NEW_ENV"),
|
|
|
|
Some(val) => env::set_var("RUN_TEST_NEW_ENV", &val)
|
2014-10-03 17:16:05 +03:00
|
|
|
}
|
|
|
|
|
2017-01-10 13:00:07 -05:00
|
|
|
let result = cmd.output().unwrap();
|
2015-04-10 11:12:43 -07:00
|
|
|
let output = String::from_utf8_lossy(&result.stdout);
|
2014-10-03 17:16:05 +03:00
|
|
|
|
2015-01-26 21:21:15 -05:00
|
|
|
assert!(!output.contains("RUN_TEST_NEW_ENV"),
|
2014-10-03 17:16:05 +03:00
|
|
|
"found RUN_TEST_NEW_ENV inside of:\n\n{}", output);
|
|
|
|
}
|