Skip to content

Commit dbdc737

Browse files
committed
refactor git-path tests
1 parent 8d84818 commit dbdc737

File tree

7 files changed

+79
-80
lines changed

7 files changed

+79
-80
lines changed

gix-path/tests/path.rs

Lines changed: 0 additions & 80 deletions
This file was deleted.
File renamed without changes.

gix-path/tests/path/env.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#[test]
2+
fn exe_invocation() {
3+
let actual = gix_path::env::exe_invocation();
4+
assert!(
5+
!actual.as_os_str().is_empty(),
6+
"it finds something as long as git is installed somewhere on the system (or a default location)"
7+
);
8+
}
9+
10+
#[test]
11+
fn installation_config() {
12+
assert_ne!(
13+
gix_path::env::installation_config().map(|p| p.components().count()),
14+
gix_path::env::installation_config_prefix().map(|p| p.components().count()),
15+
"the prefix is a bit shorter than the installation config path itself"
16+
);
17+
}
18+
19+
#[test]
20+
fn system_prefix() {
21+
assert_ne!(
22+
gix_path::env::system_prefix(),
23+
None,
24+
"git should be present when running tests"
25+
);
26+
}
27+
28+
#[test]
29+
fn home_dir() {
30+
assert_ne!(
31+
gix_path::env::home_dir(),
32+
None,
33+
"we find a home on every system these tests execute"
34+
);
35+
}
36+
37+
mod xdg_config {
38+
use std::ffi::OsStr;
39+
40+
#[test]
41+
fn prefers_xdg_config_bases() {
42+
let actual = gix_path::env::xdg_config("test", &mut |n| {
43+
(n == OsStr::new("XDG_CONFIG_HOME")).then(|| "marker".into())
44+
})
45+
.expect("set");
46+
#[cfg(unix)]
47+
assert_eq!(actual.to_str(), Some("marker/git/test"));
48+
#[cfg(windows)]
49+
assert_eq!(actual.to_str(), Some("marker\\git\\test"));
50+
}
51+
52+
#[test]
53+
fn falls_back_to_home() {
54+
let actual = gix_path::env::xdg_config("test", &mut |n| (n == OsStr::new("HOME")).then(|| "marker".into()))
55+
.expect("set");
56+
#[cfg(unix)]
57+
assert_eq!(actual.to_str(), Some("marker/.config/git/test"));
58+
#[cfg(windows)]
59+
assert_eq!(actual.to_str(), Some("marker\\.config\\git\\test"));
60+
}
61+
}

gix-path/tests/path/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pub type Result<T = ()> = std::result::Result<T, Box<dyn std::error::Error>>;
2+
3+
mod convert;
4+
mod realpath;
5+
mod home_dir {
6+
#[test]
7+
fn returns_existing_directory() {
8+
if let Some(home) = gix_path::env::home_dir() {
9+
assert!(
10+
home.is_dir(),
11+
"the home directory would typically exist, even though on unix we don't test for that."
12+
);
13+
}
14+
}
15+
}
16+
17+
mod env;
18+
mod util;
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)