@@ -181,26 +181,27 @@ mod tests {
181
181
Some ( text. to_str ( ) ?. to_lowercase ( ) . ends_with ( & suffix. to_lowercase ( ) ) )
182
182
}
183
183
184
+ /// The common global program files paths on this system, by process and system architecture.
184
185
#[ cfg( windows) ]
185
186
#[ derive( Clone , Debug ) ]
186
- struct PathsByRole {
187
+ struct ProgramFilesPaths {
187
188
/// The program files directory used for whatever architecture this program was built for.
188
- pf_current : PathBuf ,
189
+ current : PathBuf ,
189
190
190
191
/// The x86 program files directory regardless of the architecture of the program.
191
192
///
192
193
/// If Rust gains Windows targets like ARMv7 where this is unavailable, this could fail.
193
- pf_x86 : PathBuf ,
194
+ x86 : PathBuf ,
194
195
195
196
/// The 64-bit program files directory if there is one.
196
197
///
197
198
/// This is present on x64 and also ARM64 systems. On an ARM64 system, ARM64 and AMD64
198
199
/// programs use the same program files directory while 32-bit x86 and ARM programs use two
199
200
/// others. Only a 32-bit has no 64-bit program files directory.
200
- maybe_pf_64bit : Option < PathBuf > ,
201
+ maybe_64bit : Option < PathBuf > ,
201
202
}
202
203
203
- impl PathsByRole {
204
+ impl ProgramFilesPaths {
204
205
/// Gets the three common kinds of global program files paths without environment variables.
205
206
///
206
207
/// The idea here is to obtain this information, which the `alternative_locations()` unit
@@ -237,9 +238,9 @@ mod tests {
237
238
. ok ( ) ;
238
239
239
240
Self {
240
- pf_current,
241
- pf_x86,
242
- maybe_pf_64bit,
241
+ current : pf_current,
242
+ x86 : pf_x86,
243
+ maybe_64bit : maybe_pf_64bit,
243
244
}
244
245
}
245
246
@@ -248,80 +249,74 @@ mod tests {
248
249
/// This checks that `obtain_envlessly()` returned paths that are likely to be correct and
249
250
/// that satisfy the most important properties based on the current system and process.
250
251
fn validate ( self ) -> Self {
251
- let PathsByRole {
252
- pf_current,
253
- pf_x86,
254
- maybe_pf_64bit,
255
- } = self ;
256
-
257
252
match PlatformArchitecture :: current ( ) . expect ( "Process and system 'bitness' should be available." ) {
258
253
PlatformArchitecture :: Is32on32 => {
259
254
assert_eq ! (
260
- pf_current . as_os_str( ) ,
261
- pf_x86 . as_os_str( ) ,
255
+ self . current . as_os_str( ) ,
256
+ self . x86 . as_os_str( ) ,
262
257
"Our program files path is exactly identical to the 32-bit one." ,
263
258
) ;
264
259
for arch_suffix in [ " (x86)" , " (Arm)" ] {
265
- let has_arch_suffix = ends_with_case_insensitive ( pf_current . as_os_str ( ) , arch_suffix)
260
+ let has_arch_suffix = ends_with_case_insensitive ( self . current . as_os_str ( ) , arch_suffix)
266
261
. expect ( "Assume the test system's important directories are valid Unicode." ) ;
267
262
assert ! (
268
263
!has_arch_suffix,
269
264
"The 32-bit program files directory name on a 32-bit system mentions no architecture." ,
270
265
) ;
271
266
}
272
267
assert_eq ! (
273
- maybe_pf_64bit , None ,
268
+ self . maybe_64bit , None ,
274
269
"A 32-bit system has no 64-bit program files directory." ,
275
270
) ;
276
271
}
277
272
PlatformArchitecture :: Is32on64 => {
278
273
assert_eq ! (
279
- pf_current . as_os_str( ) ,
280
- pf_x86 . as_os_str( ) ,
274
+ self . current . as_os_str( ) ,
275
+ self . x86 . as_os_str( ) ,
281
276
"Our program files path is exactly identical to the 32-bit one." ,
282
277
) ;
283
- let pf_64bit = maybe_pf_64bit
278
+ let pf_64bit = self
279
+ . maybe_64bit
284
280
. as_ref ( )
285
281
. expect ( "The 64-bit program files directory exists." ) ;
286
282
assert_ne ! (
287
- & pf_x86 , pf_64bit,
283
+ & self . x86 , pf_64bit,
288
284
"The 32-bit and 64-bit program files directories have different locations." ,
289
285
) ;
290
286
}
291
287
PlatformArchitecture :: Is64on64 => {
292
- let pf_64bit = maybe_pf_64bit
288
+ let pf_64bit = self
289
+ . maybe_64bit
293
290
. as_ref ( )
294
291
. expect ( "The 64-bit program files directory exists." ) ;
295
292
assert_eq ! (
296
- pf_current . as_os_str( ) ,
293
+ self . current . as_os_str( ) ,
297
294
pf_64bit. as_os_str( ) ,
298
295
"Our program files path is exactly identical to the 64-bit one." ,
299
296
) ;
300
297
assert_ne ! (
301
- & pf_x86 , pf_64bit,
298
+ & self . x86 , pf_64bit,
302
299
"The 32-bit and 64-bit program files directories have different locations." ,
303
300
) ;
304
301
}
305
302
}
306
303
307
- Self {
308
- pf_current,
309
- pf_x86,
310
- maybe_pf_64bit,
311
- }
304
+ self
312
305
}
313
306
}
314
307
315
308
#[ test]
316
309
#[ cfg( windows) ]
317
310
fn alternative_locations ( ) {
318
- let PathsByRole {
319
- pf_current,
320
- pf_x86,
321
- maybe_pf_64bit,
322
- } = PathsByRole :: obtain_envlessly ( ) . validate ( ) ;
311
+ 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." ) ;
323
318
324
- // FIXME: Assert the relationships between the above values and ALTERNATIVE_LOCATIONS contents!
319
+ // FIXME: Assert the other relationships between pf values and ALTERNATIVE_LOCATIONS contents!
325
320
}
326
321
327
322
#[ test]
0 commit comments