]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/env-home-dir.rs
New upstream version 1.12.0+dfsg1
[rustc.git] / src / test / run-pass / env-home-dir.rs
1 // Copyright 2015 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 // ignore-emscripten
12
13 #![feature(path)]
14
15 use std::env::*;
16 use std::path::PathBuf;
17
18 #[cfg(unix)]
19 fn main() {
20 let oldhome = var("HOME");
21
22 set_var("HOME", "/home/MountainView");
23 assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
24
25 remove_var("HOME");
26 if cfg!(target_os = "android") {
27 assert!(home_dir().is_none());
28 } else {
29 assert!(home_dir().is_some());
30 }
31 }
32
33 #[cfg(windows)]
34 fn main() {
35 let oldhome = var("HOME");
36 let olduserprofile = var("USERPROFILE");
37
38 remove_var("HOME");
39 remove_var("USERPROFILE");
40
41 assert!(home_dir().is_some());
42
43 set_var("HOME", "/home/MountainView");
44 assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
45
46 remove_var("HOME");
47
48 set_var("USERPROFILE", "/home/MountainView");
49 assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
50
51 set_var("HOME", "/home/MountainView");
52 set_var("USERPROFILE", "/home/PaloAlto");
53 assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
54 }