]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/env-home-dir.rs
Auto merge of #22853 - FlaPer87:snap, r=alexcrichton
[rust.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 use std::env::*;
12 use std::path::PathBuf;
13
14 #[cfg(unix)]
15 fn main() {
16     let oldhome = var("HOME");
17
18     set_var("HOME", "/home/MountainView");
19     assert!(home_dir() == Some(PathBuf::new("/home/MountainView")));
20
21     remove_var("HOME");
22     if cfg!(target_os = "android") {
23         assert!(home_dir().is_none());
24     } else {
25         assert!(home_dir().is_some());
26     }
27 }
28
29 #[cfg(windows)]
30 fn main() {
31     let oldhome = var("HOME");
32     let olduserprofile = var("USERPROFILE");
33
34     remove_var("HOME");
35     remove_var("USERPROFILE");
36
37     assert!(home_dir().is_some());
38
39     set_var("HOME", "/home/MountainView");
40     assert!(home_dir() == Some(PathBuf::new("/home/MountainView")));
41
42     remove_var("HOME");
43
44     set_var("USERPROFILE", "/home/MountainView");
45     assert!(home_dir() == Some(PathBuf::new("/home/MountainView")));
46
47     set_var("HOME", "/home/MountainView");
48     set_var("USERPROFILE", "/home/PaloAlto");
49     assert!(home_dir() == Some(PathBuf::new("/home/MountainView")));
50 }