Skip to content

Commit 3dd1d1f

Browse files
committed
Rename PathsByRole to ProgramFilesPaths
+ Remove the "pf" parts of its fields. + Refactor usage now that unpacking isn't needed to refer to the values intuitively. + Write a fragment of the unit test that uses it. This was part of checking that the new names make sense, but these particular assertions may not all be kept (and may drastically change form). This is because, even if the process architecture specific path is something we want to list first, that is a change to the implementation that is separate from the first and main fix that this test is being introduced to provide coverage for.
1 parent 95708dd commit 3dd1d1f

File tree

1 file changed

+31
-36
lines changed

1 file changed

+31
-36
lines changed

gix-path/src/env/git.rs

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -181,26 +181,27 @@ mod tests {
181181
Some(text.to_str()?.to_lowercase().ends_with(&suffix.to_lowercase()))
182182
}
183183

184+
/// The common global program files paths on this system, by process and system architecture.
184185
#[cfg(windows)]
185186
#[derive(Clone, Debug)]
186-
struct PathsByRole {
187+
struct ProgramFilesPaths {
187188
/// The program files directory used for whatever architecture this program was built for.
188-
pf_current: PathBuf,
189+
current: PathBuf,
189190

190191
/// The x86 program files directory regardless of the architecture of the program.
191192
///
192193
/// If Rust gains Windows targets like ARMv7 where this is unavailable, this could fail.
193-
pf_x86: PathBuf,
194+
x86: PathBuf,
194195

195196
/// The 64-bit program files directory if there is one.
196197
///
197198
/// This is present on x64 and also ARM64 systems. On an ARM64 system, ARM64 and AMD64
198199
/// programs use the same program files directory while 32-bit x86 and ARM programs use two
199200
/// others. Only a 32-bit has no 64-bit program files directory.
200-
maybe_pf_64bit: Option<PathBuf>,
201+
maybe_64bit: Option<PathBuf>,
201202
}
202203

203-
impl PathsByRole {
204+
impl ProgramFilesPaths {
204205
/// Gets the three common kinds of global program files paths without environment variables.
205206
///
206207
/// The idea here is to obtain this information, which the `alternative_locations()` unit
@@ -237,9 +238,9 @@ mod tests {
237238
.ok();
238239

239240
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,
243244
}
244245
}
245246

@@ -248,80 +249,74 @@ mod tests {
248249
/// This checks that `obtain_envlessly()` returned paths that are likely to be correct and
249250
/// that satisfy the most important properties based on the current system and process.
250251
fn validate(self) -> Self {
251-
let PathsByRole {
252-
pf_current,
253-
pf_x86,
254-
maybe_pf_64bit,
255-
} = self;
256-
257252
match PlatformArchitecture::current().expect("Process and system 'bitness' should be available.") {
258253
PlatformArchitecture::Is32on32 => {
259254
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(),
262257
"Our program files path is exactly identical to the 32-bit one.",
263258
);
264259
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)
266261
.expect("Assume the test system's important directories are valid Unicode.");
267262
assert!(
268263
!has_arch_suffix,
269264
"The 32-bit program files directory name on a 32-bit system mentions no architecture.",
270265
);
271266
}
272267
assert_eq!(
273-
maybe_pf_64bit, None,
268+
self.maybe_64bit, None,
274269
"A 32-bit system has no 64-bit program files directory.",
275270
);
276271
}
277272
PlatformArchitecture::Is32on64 => {
278273
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(),
281276
"Our program files path is exactly identical to the 32-bit one.",
282277
);
283-
let pf_64bit = maybe_pf_64bit
278+
let pf_64bit = self
279+
.maybe_64bit
284280
.as_ref()
285281
.expect("The 64-bit program files directory exists.");
286282
assert_ne!(
287-
&pf_x86, pf_64bit,
283+
&self.x86, pf_64bit,
288284
"The 32-bit and 64-bit program files directories have different locations.",
289285
);
290286
}
291287
PlatformArchitecture::Is64on64 => {
292-
let pf_64bit = maybe_pf_64bit
288+
let pf_64bit = self
289+
.maybe_64bit
293290
.as_ref()
294291
.expect("The 64-bit program files directory exists.");
295292
assert_eq!(
296-
pf_current.as_os_str(),
293+
self.current.as_os_str(),
297294
pf_64bit.as_os_str(),
298295
"Our program files path is exactly identical to the 64-bit one.",
299296
);
300297
assert_ne!(
301-
&pf_x86, pf_64bit,
298+
&self.x86, pf_64bit,
302299
"The 32-bit and 64-bit program files directories have different locations.",
303300
);
304301
}
305302
}
306303

307-
Self {
308-
pf_current,
309-
pf_x86,
310-
maybe_pf_64bit,
311-
}
304+
self
312305
}
313306
}
314307

315308
#[test]
316309
#[cfg(windows)]
317310
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.");
323318

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!
325320
}
326321

327322
#[test]

0 commit comments

Comments
 (0)