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