]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/process-envs.rs
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.
11 // ignore-cloudabi no processes
12 // ignore-emscripten no processes
14 use std
::process
::Command
;
16 use std
::collections
::HashMap
;
18 #[cfg(all(unix, not(target_os="android")))]
19 pub fn env_cmd() -> Command
{
22 #[cfg(target_os="android")]
23 pub fn env_cmd() -> Command
{
24 let mut cmd
= Command
::new("/system/bin/sh");
25 cmd
.arg("-c").arg("set");
30 pub fn env_cmd() -> Command
{
31 let mut cmd
= Command
::new("cmd");
32 cmd
.arg("/c").arg("set");
37 // save original environment
38 let old_env
= env
::var_os("RUN_TEST_NEW_ENV");
40 env
::set_var("RUN_TEST_NEW_ENV", "123");
42 // create filtered environment vector
43 let filtered_env
: HashMap
<String
, String
> =
44 env
::vars().filter(|&(ref k
, _
)| k
== "PATH").collect();
46 let mut cmd
= env_cmd();
48 cmd
.envs(&filtered_env
);
50 // restore original environment
52 None
=> env
::remove_var("RUN_TEST_NEW_ENV"),
53 Some(val
) => env
::set_var("RUN_TEST_NEW_ENV", &val
)
56 let result
= cmd
.output().unwrap();
57 let output
= String
::from_utf8_lossy(&result
.stdout
);
59 assert
!(!output
.contains("RUN_TEST_NEW_ENV"),
60 "found RUN_TEST_NEW_ENV inside of:\n\n{}", output
);