Skip to content

Commit

Permalink
refactor git-path tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 9, 2025
1 parent 8d84818 commit dbdc737
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 80 deletions.
80 changes: 0 additions & 80 deletions gix-path/tests/path.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions gix-path/tests/path/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#[test]
fn exe_invocation() {
let actual = gix_path::env::exe_invocation();
assert!(
!actual.as_os_str().is_empty(),
"it finds something as long as git is installed somewhere on the system (or a default location)"
);
}

#[test]
fn installation_config() {
assert_ne!(
gix_path::env::installation_config().map(|p| p.components().count()),
gix_path::env::installation_config_prefix().map(|p| p.components().count()),
"the prefix is a bit shorter than the installation config path itself"
);
}

#[test]
fn system_prefix() {
assert_ne!(
gix_path::env::system_prefix(),
None,
"git should be present when running tests"
);
}

#[test]
fn home_dir() {
assert_ne!(
gix_path::env::home_dir(),
None,
"we find a home on every system these tests execute"
);
}

mod xdg_config {
use std::ffi::OsStr;

#[test]
fn prefers_xdg_config_bases() {
let actual = gix_path::env::xdg_config("test", &mut |n| {
(n == OsStr::new("XDG_CONFIG_HOME")).then(|| "marker".into())
})
.expect("set");
#[cfg(unix)]
assert_eq!(actual.to_str(), Some("marker/git/test"));
#[cfg(windows)]
assert_eq!(actual.to_str(), Some("marker\\git\\test"));
}

#[test]
fn falls_back_to_home() {
let actual = gix_path::env::xdg_config("test", &mut |n| (n == OsStr::new("HOME")).then(|| "marker".into()))
.expect("set");
#[cfg(unix)]
assert_eq!(actual.to_str(), Some("marker/.config/git/test"));
#[cfg(windows)]
assert_eq!(actual.to_str(), Some("marker\\.config\\git\\test"));
}
}
18 changes: 18 additions & 0 deletions gix-path/tests/path/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub type Result<T = ()> = std::result::Result<T, Box<dyn std::error::Error>>;

mod convert;
mod realpath;
mod home_dir {
#[test]
fn returns_existing_directory() {
if let Some(home) = gix_path::env::home_dir() {
assert!(
home.is_dir(),
"the home directory would typically exist, even though on unix we don't test for that."
);
}
}
}

mod env;
mod util;
File renamed without changes.
File renamed without changes.

0 comments on commit dbdc737

Please sign in to comment.