]> git.lizzy.rs Git - rust.git/blob - src/test/ui/env-home-dir.rs
Auto merge of #67000 - spastorino:remove-promoted-from-place, r=oli-obk
[rust.git] / src / test / ui / env-home-dir.rs
1 // run-pass
2
3 #![allow(unused_variables)]
4 #![allow(deprecated)]
5 // ignore-cloudabi no environment variables present
6 // ignore-emscripten env vars don't work?
7 // ignore-sgx env vars cannot be modified
8
9 use std::env::*;
10 use std::path::PathBuf;
11
12 #[cfg(unix)]
13 fn main() {
14     let oldhome = var("HOME");
15
16     set_var("HOME", "/home/MountainView");
17     assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
18
19     remove_var("HOME");
20     if cfg!(target_os = "android") {
21         assert!(home_dir().is_none());
22     } else {
23         // When HOME is not set, some platforms return `None`,
24         // but others return `Some` with a default.
25         // Just check that it is not "/home/MountainView".
26         assert_ne!(home_dir(), Some(PathBuf::from("/home/MountainView")));
27     }
28 }
29
30 #[cfg(windows)]
31 fn main() {
32     let oldhome = var("HOME");
33     let olduserprofile = var("USERPROFILE");
34
35     remove_var("HOME");
36     remove_var("USERPROFILE");
37
38     assert!(home_dir().is_some());
39
40     set_var("HOME", "/home/MountainView");
41     assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
42
43     remove_var("HOME");
44
45     set_var("USERPROFILE", "/home/MountainView");
46     assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
47
48     set_var("HOME", "/home/MountainView");
49     set_var("USERPROFILE", "/home/PaloAlto");
50     assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
51 }