1 // Copyright 2014, 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 use std::process::Command;
15 use std::collections::HashMap;
17 #[cfg(all(unix, not(target_os="android")))]
18 pub fn env_cmd() -> Command {
21 #[cfg(target_os="android")]
22 pub fn env_cmd() -> Command {
23 let mut cmd = Command::new("/system/bin/sh");
24 cmd.arg("-c").arg("set");
29 pub fn env_cmd() -> Command {
30 let mut cmd = Command::new("cmd");
31 cmd.arg("/c").arg("set");
36 // save original environment
37 let old_env = env::var_os("RUN_TEST_NEW_ENV");
39 env::set_var("RUN_TEST_NEW_ENV", "123");
41 // create filtered environment vector
42 let filtered_env : HashMap<String, String> =
43 env::vars().filter(|&(ref k, _)| k == "PATH").collect();
45 let mut cmd = env_cmd();
47 cmd.envs(&filtered_env);
49 // restore original environment
51 None => env::remove_var("RUN_TEST_NEW_ENV"),
52 Some(val) => env::set_var("RUN_TEST_NEW_ENV", &val)
55 let result = cmd.output().unwrap();
56 let output = String::from_utf8_lossy(&result.stdout);
58 assert!(!output.contains("RUN_TEST_NEW_ENV"),
59 "found RUN_TEST_NEW_ENV inside of:\n\n{}", output);