Skip to content

Commit 6a96814

Browse files
committed
✅ Add a basic test
1 parent c3bb33c commit 6a96814

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,24 @@ mod win32 {
9494
Some(PathBuf::from(path))
9595
}
9696
}
97+
98+
#[cfg(test)]
99+
mod tests {
100+
use super::*;
101+
102+
#[test]
103+
fn home() {
104+
let home = home_dir().unwrap();
105+
assert!(home.is_dir());
106+
107+
if let Ok(env_home) = std::env::var("HOME") {
108+
// If `HOME` is set, `home_dir` took the value from it.
109+
let env_home = PathBuf::from(env_home);
110+
assert_eq!(home, env_home);
111+
112+
// With `HOME` unset, `home_dir` should still return the same value.
113+
std::env::remove_var("HOME");
114+
assert_eq!(home_dir().unwrap(), env_home);
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)