]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/process-remove-from-env.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.git] / src / test / run-pass / process-remove-from-env.rs
1 // Copyright 2014 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.
4 //
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.
10
11 // pretty-expanded FIXME #23616
12
13 #![feature(old_io)]
14
15 use std::old_io::Command;
16 use std::env;
17
18 #[cfg(all(unix, not(target_os="android")))]
19 pub fn env_cmd() -> Command {
20     Command::new("env")
21 }
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");
26     cmd
27 }
28
29 #[cfg(windows)]
30 pub fn env_cmd() -> Command {
31     let mut cmd = Command::new("cmd");
32     cmd.arg("/c").arg("set");
33     cmd
34 }
35
36 fn main() {
37     // save original environment
38     let old_env = env::var_os("RUN_TEST_NEW_ENV");
39
40     env::set_var("RUN_TEST_NEW_ENV", "123");
41
42     let mut cmd = env_cmd();
43     cmd.env_remove("RUN_TEST_NEW_ENV");
44
45     // restore original environment
46     match old_env {
47         None => env::remove_var("RUN_TEST_NEW_ENV"),
48         Some(val) => env::set_var("RUN_TEST_NEW_ENV", &val)
49     }
50
51     let prog = cmd.spawn().unwrap();
52     let result = prog.wait_with_output().unwrap();
53     let output = String::from_utf8_lossy(&result.output);
54
55     assert!(!output.contains("RUN_TEST_NEW_ENV"),
56             "found RUN_TEST_NEW_ENV inside of:\n\n{}", output);
57 }