]>
Commit | Line | Data |
---|---|---|
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 | 7 | use std::process::Command; |
85aaf69f | 8 | use std::env; |
1a4d82fc JJ |
9 | |
10 | #[cfg(all(unix, not(target_os="android")))] | |
11 | pub fn env_cmd() -> Command { | |
12 | Command::new("env") | |
13 | } | |
14 | #[cfg(target_os="android")] | |
15 | pub 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)] | |
22 | pub fn env_cmd() -> Command { | |
23 | let mut cmd = Command::new("cmd"); | |
24 | cmd.arg("/c").arg("set"); | |
25 | cmd | |
26 | } | |
27 | ||
28 | fn 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 | } |