@@ -305,16 +305,52 @@ mod tests {
305
305
}
306
306
}
307
307
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
+
308
349
#[ test]
309
350
#[ cfg( windows) ]
310
351
fn alternative_locations ( ) {
311
352
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) ;
318
354
319
355
// FIXME: Assert the other relationships between pf values and ALTERNATIVE_LOCATIONS contents!
320
356
}
0 commit comments