Skip to content

Commit 7faf764

Browse files
committed
test: expand env-var-path coverage (Fixes #389)
1 parent 6072b60 commit 7faf764

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

  • crates/pet-env-var-path/src

crates/pet-env-var-path/src/lib.rs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,113 @@ mod tests {
185185

186186
assert!(!is_windows_apps_path(&path, None));
187187
}
188+
189+
// ── additional coverage ───────────────────────────────────────
190+
191+
#[test]
192+
fn search_paths_returns_empty_for_empty_locations() {
193+
let environment = TestEnvironment {
194+
user_home: None,
195+
global_search_locations: vec![],
196+
};
197+
198+
let result = get_search_paths_from_env_variables(&environment);
199+
assert!(result.is_empty());
200+
}
201+
202+
#[test]
203+
fn search_paths_returns_empty_when_all_are_windows_apps() {
204+
let home = create_test_dir("all-apps");
205+
let apps1 = home
206+
.join("AppData")
207+
.join("Local")
208+
.join("Microsoft")
209+
.join("WindowsApps");
210+
let apps2 = home
211+
.join("AppData")
212+
.join("Local")
213+
.join("Microsoft")
214+
.join("WindowsApps")
215+
.join("subdir");
216+
fs::create_dir_all(&apps1).unwrap();
217+
fs::create_dir_all(&apps2).unwrap();
218+
219+
let environment = TestEnvironment {
220+
user_home: Some(home.clone()),
221+
global_search_locations: vec![apps1, apps2],
222+
};
223+
224+
let result = get_search_paths_from_env_variables(&environment);
225+
assert!(result.is_empty());
226+
227+
fs::remove_dir_all(home).unwrap();
228+
}
229+
230+
#[test]
231+
fn is_windows_apps_path_matches_with_known_home() {
232+
let home = create_test_dir("known-home");
233+
let apps_path = home
234+
.join("AppData")
235+
.join("Local")
236+
.join("Microsoft")
237+
.join("WindowsApps");
238+
fs::create_dir_all(&apps_path).unwrap();
239+
240+
assert!(is_windows_apps_path(&apps_path, Some(&home)));
241+
242+
fs::remove_dir_all(home).unwrap();
243+
}
244+
245+
#[test]
246+
fn is_windows_apps_path_matches_subdirectory_of_apps() {
247+
let home = create_test_dir("apps-subdir");
248+
let apps_subdir = home
249+
.join("AppData")
250+
.join("Local")
251+
.join("Microsoft")
252+
.join("WindowsApps")
253+
.join("PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0");
254+
// No need to create on disk - starts_with is a path comparison
255+
256+
assert!(is_windows_apps_path(&apps_subdir, Some(&home)));
257+
258+
fs::remove_dir_all(home).unwrap();
259+
}
260+
261+
#[test]
262+
fn is_windows_apps_path_rejects_unrelated_path() {
263+
let path = PathBuf::from(if cfg!(windows) {
264+
r"C:\Python312"
265+
} else {
266+
"/usr/local/bin"
267+
});
268+
269+
assert!(!is_windows_apps_path(&path, None));
270+
}
271+
272+
#[test]
273+
fn normalize_search_path_handles_non_existent_path() {
274+
let non_existent = PathBuf::from(if cfg!(windows) {
275+
r"C:\this\path\does\not\exist"
276+
} else {
277+
"/this/path/does/not/exist"
278+
});
279+
280+
// On Unix, canonicalize fails for non-existent paths so it returns original
281+
// On Windows, norm_case returns the path as-is
282+
let result = normalize_search_path(non_existent.clone());
283+
// Should not panic and should return something
284+
assert!(!result.as_os_str().is_empty());
285+
}
286+
287+
#[test]
288+
fn normalize_search_path_handles_existing_path() {
289+
let temp = create_test_dir("normalize");
290+
291+
let result = normalize_search_path(temp.clone());
292+
// On all platforms, an existing path should normalize successfully
293+
assert!(result.exists());
294+
295+
fs::remove_dir_all(temp).unwrap();
296+
}
188297
}

0 commit comments

Comments
 (0)