Skip to content

Commit cab4c85

Browse files
committed
Fix user program files alternative locations expectations
Unlike the global program files directories, the user program files directory location (the location where it either already exists or would be created the first time it is needed, when installing software) is not architecture-specific. So we cannot decide which of `clangarm64`, `mingw64`, and `mingw32` to look for inside of it based on the values of environment variables, even with our build's `target_pointer_width` to help. This is to say that `pf_user` is fundamentally different from `pf_current`: while `pf_current` is architecture-specific but in a way that varies by executable build, `pf_user` is not architecture-specific. This modifies the integration-style test expectation to include all three subdirectories of a `Git` subdirectory of the user program files directory, in all platforms.
1 parent 9e71d55 commit cab4c85

File tree

1 file changed

+95
-63
lines changed

1 file changed

+95
-63
lines changed

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

Lines changed: 95 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -354,100 +354,132 @@ mod locations {
354354
}
355355
}
356356

357-
/// Architecture-specific Git for Windows paths relative to particular program files directories.
357+
/// Architecture-specific Git for Windows paths relative to the user program files directory.
358358
#[derive(Clone, Debug)]
359-
struct RelativeGitBinPaths<'a> {
360-
global_x86: &'a Path,
361-
maybe_global_x64: Option<&'a Path>,
362-
maybe_global_arm64: Option<&'a Path>,
363-
user_x86: &'a Path,
364-
maybe_user_x64: Option<&'a Path>,
365-
maybe_user_arm64: Option<&'a Path>,
359+
struct RelativeUserGitBinPaths<'a> {
360+
x86: &'a Path,
361+
x64: &'a Path,
362+
arm64: &'a Path,
366363
}
367364

368-
impl<'a> RelativeGitBinPaths<'a> {
369-
/// Assert that `locations` has the given path prefixes, and extract the suffixes.
365+
impl<'a> RelativeUserGitBinPaths<'a> {
366+
/// Assert that `locations` leads with the given user path prefix, and extract the suffixes.
367+
fn assert_from(pf_user: &'a Path, locations: &'static [PathBuf]) -> Self {
368+
match locations {
369+
[path1, path2, path3, ..] => {
370+
let suffix_user_arm64 = path1
371+
.strip_prefix(pf_user)
372+
.expect("It gives a per-user 64-bit ARM64 path and lists it first");
373+
let suffix_user_x64 = path2
374+
.strip_prefix(pf_user)
375+
.expect("It gives a per-user 64-bit x86 path and lists it second");
376+
let suffix_user_x86 = path3
377+
.strip_prefix(pf_user)
378+
.expect("It gives a per-user 32-bit x86 path and lists it third");
379+
Self {
380+
x86: suffix_user_x86,
381+
x64: suffix_user_x64,
382+
arm64: suffix_user_arm64,
383+
}
384+
}
385+
other => panic!(
386+
"{:?} has length {}, so some expected leading user program files paths are absent",
387+
other,
388+
other.len()
389+
),
390+
}
391+
}
392+
393+
/// Assert that suffixes are common Git install locations relative to a program files directory.
394+
fn assert_architectures(&self) {
395+
assert_eq!(self.x86, Path::new("Git/mingw32/bin"));
396+
assert_eq!(self.x64, Path::new("Git/mingw64/bin"));
397+
assert_eq!(self.arm64, Path::new("Git/clangarm64/bin"));
398+
}
399+
}
400+
401+
/// Architecture-specific Git for Windows paths relative to global program files directories.
402+
#[derive(Clone, Debug)]
403+
struct RelativeGlobalGitBinPaths<'a> {
404+
x86: &'a Path,
405+
maybe_x64: Option<&'a Path>,
406+
maybe_arm64: Option<&'a Path>,
407+
}
408+
409+
impl<'a> RelativeGlobalGitBinPaths<'a> {
410+
/// Assert that `locations` trails with the given global path prefixes, and extract the suffixes.
370411
fn assert_from(pf: &'a ProgramFilesPaths, locations: &'static [PathBuf]) -> Self {
371412
match locations {
372-
[path1, path2, path3, path4, path5, path6] => {
413+
[_, _, _, path4, path5, path6] => {
373414
let prefix_64bit = pf
374415
.maybe_64bit
375416
.as_ref()
376-
.expect("It gives six paths only if some can be 64-bit");
377-
let suffix_user_arm64 = path1
378-
.strip_prefix(pf.user.as_path())
379-
.expect("It gives the per-user 64-bit ARM64 path and lists it first");
380-
let suffix_user_x64 = path2
381-
.strip_prefix(pf.user.as_path())
382-
.expect("It gives the per-user 64-bit x86 path and lists it second");
383-
let suffix_user_x86 = path3
384-
.strip_prefix(pf.user.as_path())
385-
.expect("It gives the per-user 32-bit x86 path and lists it third");
417+
.expect("It gives 6 paths only if some global paths can be 64-bit");
386418
let suffix_global_arm64 = path4
387419
.strip_prefix(prefix_64bit)
388-
.expect("It gives the global 64-bit ARM64 path and lists it fourth");
420+
.expect("It gives a global 64-bit ARM64 path and lists it fourth");
389421
let suffix_global_x64 = path5
390422
.strip_prefix(prefix_64bit)
391-
.expect("It gives the global 64-bit x86 path and lists it fifth");
423+
.expect("It gives a global 64-bit x86 path and lists it fifth");
392424
let suffix_global_x86 = path6
393-
.strip_prefix(pf.x86.as_path())
394-
.expect("It gives the global 32-bit path and lists it sixth");
425+
.strip_prefix(&pf.x86)
426+
.expect("It gives a global 32-bit path and lists it sixth");
395427
Self {
396-
global_x86: suffix_global_x86,
397-
maybe_global_x64: Some(suffix_global_x64),
398-
maybe_global_arm64: Some(suffix_global_arm64),
399-
user_x86: suffix_user_x86,
400-
maybe_user_x64: Some(suffix_user_x64),
401-
maybe_user_arm64: Some(suffix_user_arm64),
428+
x86: suffix_global_x86,
429+
maybe_x64: Some(suffix_global_x64),
430+
maybe_arm64: Some(suffix_global_arm64),
402431
}
403432
}
404-
[path1, path2] => {
405-
assert_eq!(pf.maybe_64bit, None, "It gives two paths only if none can be 64-bit.");
406-
let suffix_user_x86 = path1
407-
.strip_prefix(pf.user.as_path())
408-
.expect("It gives the per-user 32-bit path and lists it first");
409-
let suffix_global_x86 = path2
410-
.strip_prefix(pf.x86.as_path())
411-
.expect("It gives the global 32-bit path and lists it second");
433+
[_, _, _, path4] => {
434+
assert_eq!(
435+
pf.maybe_64bit, None,
436+
"It gives 4 paths only if no global paths can be 64-bit.",
437+
);
438+
let suffix_global_x86 = path4
439+
.strip_prefix(&pf.x86)
440+
.expect("It gives a global 32-bit path and lists it fourth");
412441
Self {
413-
global_x86: suffix_global_x86,
414-
maybe_global_x64: None,
415-
maybe_global_arm64: None,
416-
user_x86: suffix_user_x86,
417-
maybe_user_x64: None,
418-
maybe_user_arm64: None,
442+
x86: suffix_global_x86,
443+
maybe_x64: None,
444+
maybe_arm64: None,
419445
}
420446
}
421-
other => panic!("{:?} has length {}, expected 2 or 6.", other, other.len()),
447+
other => panic!("{:?} has length {}, expected 4 or 6.", other, other.len()),
422448
}
423449
}
424450

425-
/// Assert that the suffixes (relative subdirectories) are the common Git install locations.
451+
/// Assert that suffixes are common Git install locations relative to a program files directory.
426452
fn assert_architectures(&self) {
427-
self.assert_architectures_global();
428-
self.assert_architectures_user();
429-
}
430-
431-
fn assert_architectures_global(&self) {
432-
assert_eq!(self.global_x86, Path::new("Git/mingw32/bin"));
453+
assert_eq!(self.x86, Path::new("Git/mingw32/bin"));
433454

434-
if let Some(suffix_x64) = self.maybe_global_x64 {
455+
if let Some(suffix_x64) = self.maybe_x64 {
435456
assert_eq!(suffix_x64, Path::new("Git/mingw64/bin"));
436457
}
437-
if let Some(suffix_arm64) = self.maybe_global_arm64 {
458+
if let Some(suffix_arm64) = self.maybe_arm64 {
438459
assert_eq!(suffix_arm64, Path::new("Git/clangarm64/bin"));
439460
}
440461
}
462+
}
441463

442-
fn assert_architectures_user(&self) {
443-
assert_eq!(self.user_x86, Path::new("Git/mingw32/bin"));
464+
/// Architecture-specific Git for Windows paths relative to particular program files directories.
465+
#[derive(Clone, Debug)]
466+
struct RelativeGitBinPaths<'a> {
467+
global: RelativeGlobalGitBinPaths<'a>,
468+
user: RelativeUserGitBinPaths<'a>,
469+
}
444470

445-
if let Some(suffix_x64) = self.maybe_user_x64 {
446-
assert_eq!(suffix_x64, Path::new("Git/mingw64/bin"));
447-
}
448-
if let Some(suffix_arm64) = self.maybe_user_arm64 {
449-
assert_eq!(suffix_arm64, Path::new("Git/clangarm64/bin"));
450-
}
471+
impl<'a> RelativeGitBinPaths<'a> {
472+
/// Assert that `locations` has the given path prefixes, and extract the suffixes.
473+
fn assert_from(pf: &'a ProgramFilesPaths, locations: &'static [PathBuf]) -> Self {
474+
let user = RelativeUserGitBinPaths::assert_from(&pf.user, locations);
475+
let global = RelativeGlobalGitBinPaths::assert_from(pf, locations);
476+
Self { global, user }
477+
}
478+
479+
/// Assert that global and user suffixes (relative subdirectories) are common Git install locations.
480+
fn assert_architectures(&self) {
481+
self.global.assert_architectures();
482+
self.user.assert_architectures();
451483
}
452484
}
453485

0 commit comments

Comments
 (0)