Skip to content

Commit 1ee98bf

Browse files
committed
Make EXE_INFO testable and add a basic test for it
This extracts the code used to lazily initialize `EXE_INFO` into a separate `exe_info` helper, which is an implementation detail, but can be called any number of times without caching from the tests. It also adds one test. The tests of downstream functions (those that use `EXE_INFO`) remain more important. But this will allow the test to be expanded, or another added, to test more expectations that `EXE_INFO` is supposed to satisfy.
1 parent ccd0401 commit 1ee98bf

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

gix-path/src/env/git/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ pub(super) static EXE_NAME: &str = "git";
8080
/// Invoke the git executable to obtain the origin configuration, which is cached and returned.
8181
///
8282
/// The git executable is the one found in PATH or an alternative location.
83-
pub(super) static EXE_INFO: Lazy<Option<BString>> = Lazy::new(|| {
83+
pub(super) static EXE_INFO: Lazy<Option<BString>> = Lazy::new(exe_info);
84+
85+
fn exe_info() -> Option<BString> {
8486
let mut cmd = git_cmd(EXE_NAME.into());
8587
gix_trace::debug!(cmd = ?cmd, "invoking git for installation config path");
8688
let cmd_output = match cmd.output() {
@@ -98,7 +100,7 @@ pub(super) static EXE_INFO: Lazy<Option<BString>> = Lazy::new(|| {
98100
};
99101

100102
first_file_from_config_with_origin(cmd_output.as_slice().into()).map(ToOwned::to_owned)
101-
});
103+
}
102104

103105
fn git_cmd(executable: PathBuf) -> Command {
104106
let mut cmd = Command::new(executable);

gix-path/src/env/git/tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,19 @@ mod locations {
357357

358358
use std::path::Path;
359359

360+
#[test]
361+
fn exe_info() {
362+
let path = super::exe_info()
363+
.map(crate::from_bstring)
364+
.expect("Nonempty config in the test environment");
365+
366+
assert!(
367+
path.is_absolute(),
368+
"Absolute, unless overridden such as with GIT_CONFIG_SYSTEM"
369+
);
370+
assert!(path.exists(), "Exists, since `git config` just found an entry there");
371+
}
372+
360373
#[test]
361374
fn first_file_from_config_with_origin() {
362375
let macos =

0 commit comments

Comments
 (0)