Skip to content

Commit dd1e5c8

Browse files
committed
Assert ALTERNATIVE_LOCATIONS count and prefixes
And extract the corresponding suffixes, to be used in some of the subsequent assertions.
1 parent 3dd1d1f commit dd1e5c8

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

gix-path/src/env/git.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,52 @@ mod tests {
305305
}
306306
}
307307

308+
/// Paths relative to process architecture specific program files directories.
309+
#[cfg(windows)]
310+
#[derive(Clone, Debug)]
311+
struct GitBinSuffixes<'a> {
312+
x86: &'a Path,
313+
maybe_64bit: Option<&'a Path>,
314+
}
315+
316+
#[cfg(windows)]
317+
impl<'a> GitBinSuffixes<'a> {
318+
/// Assert that `ALTERNATIVE_LOCATIONS` has the given prefixes, and extract the suffixes.
319+
fn assert_from(pf: &'a ProgramFilesPaths) -> Self {
320+
match super::ALTERNATIVE_LOCATIONS.as_slice() {
321+
[primary, secondary] => {
322+
let prefix_64bit = pf
323+
.maybe_64bit
324+
.as_ref()
325+
.expect("It gives two paths only if one can be 64-bit.");
326+
let got_64bit = primary
327+
.strip_prefix(prefix_64bit)
328+
.expect("It gives the 64-bit path and lists it first.");
329+
let x86 = secondary
330+
.strip_prefix(pf.x86.as_path())
331+
.expect("It gives the 32-bit path and lists it second.");
332+
Self {
333+
x86,
334+
maybe_64bit: Some(got_64bit),
335+
}
336+
}
337+
[only] => {
338+
assert_eq!(pf.maybe_64bit, None, "It gives one path only if none can be 64-bit.");
339+
Self {
340+
x86: only,
341+
maybe_64bit: None,
342+
}
343+
}
344+
other => panic!("Got length {}, expected 1 or 2.", other.len()),
345+
}
346+
}
347+
}
348+
308349
#[test]
309350
#[cfg(windows)]
310351
fn alternative_locations() {
311352
let pf = ProgramFilesPaths::obtain_envlessly().validate();
312-
313-
let primary_suffix = super::ALTERNATIVE_LOCATIONS
314-
.get(0)
315-
.expect("It gave at least one path (assuming normal conditions).")
316-
.strip_prefix(pf.current)
317-
.expect("It gave a process architecture specific directory and listed it first.");
353+
let suffixes = GitBinSuffixes::assert_from(&pf);
318354

319355
// FIXME: Assert the other relationships between pf values and ALTERNATIVE_LOCATIONS contents!
320356
}

0 commit comments

Comments
 (0)