Skip to content

Commit 5701145

Browse files
committed
Make PathsByRole::maybe_pf_64bit an Option<PathBuf>
The `PathsByRole` test helper struct's `maybe_pf_64bit` member was previously `Result<PathBuf, std::io::Error>`. But construction, which is by `PathsByRole::obtain_envlessly()`, already asserted the expected existence of the other two paths. It should likewise assert that if the guaranteed-64-bit program files path cannot be obtained from the registry, then this is due to it being absent, rather than some other error. Checking this in `obtain_envlessly()` makes it reasonable for `maybe_pf_64bit` to be an `Option<PathBuf>`, as its name would suggest it should be. This in turn makes clear that all the validation and assertions for this "reference value" have already been done. Thus `PathsByRole::validate()` can continue omitting validation for the error type, validation it should not perform because the point of it is do checks that are agnostic of how the paths were obtained. This also makes `PathsByRole` cloneable, which is now possible because it no longer holds on to a `std::io::Error` with its non-cloneable dynamic error information, and adds some other missing traits on test helper types.
1 parent 518fd27 commit 5701145

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

gix-path/src/env/git.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ mod tests {
132132
use {
133133
known_folders::{get_known_folder_path, KnownFolder},
134134
std::ffi::{OsStr, OsString},
135+
std::io::ErrorKind,
135136
std::path::PathBuf,
136137
windows::core::Result as WindowsResult,
137138
windows::Win32::Foundation::BOOL,
@@ -146,6 +147,7 @@ mod tests {
146147
}
147148

148149
#[cfg(windows)]
150+
#[derive(Clone, Copy, Debug)]
149151
enum PlatformArchitecture {
150152
Is32on32,
151153
Is32on64,
@@ -180,6 +182,7 @@ mod tests {
180182
}
181183

182184
#[cfg(windows)]
185+
#[derive(Clone, Debug)]
183186
struct PathsByRole {
184187
/// The program files directory relative to what architecture this program was built for.
185188
pf_current: PathBuf,
@@ -194,7 +197,7 @@ mod tests {
194197
/// This is present on x64 and also ARM64 systems. On an ARM64 system, ARM64 and AMD64
195198
/// programs use the same program files directory while 32-bit x86 and ARM programs use two
196199
/// others. Only a 32-bit has no 64-bit program files directory.
197-
maybe_pf_64bit: Result<PathBuf, std::io::Error>,
200+
maybe_pf_64bit: Option<PathBuf>,
198201
}
199202

200203
impl PathsByRole {
@@ -226,7 +229,12 @@ mod tests {
226229
.open_subkey_with_flags(r#"SOFTWARE\Microsoft\Windows\CurrentVersion"#, KEY_QUERY_VALUE)
227230
.expect("The `CurrentVersion` key exists and allows reading.")
228231
.get_value::<OsString, _>("ProgramW6432Dir")
229-
.map(PathBuf::from);
232+
.map(PathBuf::from)
233+
.map_err(|error| {
234+
assert_eq!(error.kind(), ErrorKind::NotFound);
235+
error
236+
})
237+
.ok();
230238

231239
Self {
232240
pf_current,
@@ -261,9 +269,10 @@ mod tests {
261269
"The 32-bit program files directory name on a 32-bit system mentions no architecture.",
262270
);
263271
}
264-
maybe_pf_64bit
265-
.as_ref()
266-
.expect_err("A 32-bit system has no 64-bit program files directory.");
272+
assert_eq!(
273+
maybe_pf_64bit, None,
274+
"A 32-bit system has no 64-bit program files directory.",
275+
);
267276
}
268277
PlatformArchitecture::Is32on64 => {
269278
assert_eq!(

0 commit comments

Comments
 (0)