Skip to content

Commit 84f9672

Browse files
committed
Factor out shared code to a helper
This introduces an `if_exepath()` helper for use in streamlining closures to pass to `system_prefix_from_exepath_var()` in tests.
1 parent 24c11ac commit 84f9672

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

gix-path/src/env/tests.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ mod system_prefix {
44
use serial_test::serial;
55
use std::{ffi::OsString, path::PathBuf};
66

7+
fn if_exepath(key: &str, value: impl Into<OsString>) -> Option<OsString> {
8+
match key {
9+
"EXEPATH" => Some(value.into()),
10+
_ => None,
11+
}
12+
}
13+
714
struct ExePath {
815
_tempdir: tempfile::TempDir,
916
path: PathBuf,
@@ -43,10 +50,7 @@ mod system_prefix {
4350
}
4451

4552
fn var_os_func(&self, key: &str) -> Option<OsString> {
46-
match key {
47-
"EXEPATH" => Some(self.path.clone().into_os_string()),
48-
_ => None,
49-
}
53+
if_exepath(key, self.path.as_os_str())
5054
}
5155
}
5256

@@ -113,10 +117,7 @@ mod system_prefix {
113117
let exepath = ExePath::new();
114118
exepath.create_subdir(name);
115119
let _cwd = gix_testtools::set_current_dir(&exepath.path).expect("can change to test dir");
116-
let outcome = system_prefix_from_exepath_var(|key| match key {
117-
"EXEPATH" => Some("".into()),
118-
_ => None,
119-
});
120+
let outcome = system_prefix_from_exepath_var(|key| if_exepath(key, ""));
120121
assert_eq!(outcome, None);
121122
}
122123
}

0 commit comments

Comments
 (0)