]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/process-remove-from-env.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / process-remove-from-env.rs
CommitLineData
1a4d82fc
JJ
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
c34b1796
AL
11// pretty-expanded FIXME #23616
12
13#![feature(old_io)]
14
85aaf69f
SL
15use std::old_io::Command;
16use std::env;
1a4d82fc
JJ
17
18#[cfg(all(unix, not(target_os="android")))]
19pub fn env_cmd() -> Command {
20 Command::new("env")
21}
22#[cfg(target_os="android")]
23pub 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)]
30pub fn env_cmd() -> Command {
31 let mut cmd = Command::new("cmd");
32 cmd.arg("/c").arg("set");
33 cmd
34}
35
36fn main() {
37 // save original environment
85aaf69f 38 let old_env = env::var_os("RUN_TEST_NEW_ENV");
1a4d82fc 39
85aaf69f 40 env::set_var("RUN_TEST_NEW_ENV", "123");
1a4d82fc
JJ
41
42 let mut cmd = env_cmd();
43 cmd.env_remove("RUN_TEST_NEW_ENV");
44
45 // restore original environment
46 match old_env {
85aaf69f
SL
47 None => env::remove_var("RUN_TEST_NEW_ENV"),
48 Some(val) => env::set_var("RUN_TEST_NEW_ENV", &val)
1a4d82fc
JJ
49 }
50
51 let prog = cmd.spawn().unwrap();
52 let result = prog.wait_with_output().unwrap();
85aaf69f 53 let output = String::from_utf8_lossy(&result.output);
1a4d82fc 54
85aaf69f 55 assert!(!output.contains("RUN_TEST_NEW_ENV"),
1a4d82fc
JJ
56 "found RUN_TEST_NEW_ENV inside of:\n\n{}", output);
57}