Skip to content

Commit e365244

Browse files
authored
Merge pull request #2133 from EliahKagan/program-files-next
Make the `gix_path::env::git` tests clearer and more granular
2 parents c149116 + 1f3edb5 commit e365244

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

gix-path/src/env/git/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ where
3939
let varname_current = "ProgramFiles";
4040

4141
// 64-bit relative bin dirs. So far, this is always `mingw64` or `clangarm64`, not `urct64` or
42-
// `clang64`. We check `clangarm64` before `mingw64`, because in the strage case that both are
42+
// `clang64`. We check `clangarm64` before `mingw64`, because in the strange case that both are
4343
// available, we don't want to skip over a native ARM64 executable for an emulated x86_64 one.
4444
let suffixes_64 = [r"Git\clangarm64\bin", r"Git\mingw64\bin"].as_slice();
4545

gix-path/src/env/git/tests.rs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ mod locations {
5050
}
5151

5252
#[test]
53-
fn locations_under_program_files_ordinary() {
53+
fn locations_under_program_files_no_vars() {
54+
assert_eq!(locations_from!(), Vec::<PathBuf>::new());
55+
}
56+
57+
#[test]
58+
fn locations_under_program_files_ordinary_values_current_var_only() {
5459
assert_eq!(
5560
locations_from!(
5661
"ProgramFiles" => r"C:\Program Files",
@@ -64,6 +69,10 @@ mod locations {
6469
pathbuf_vec![r"C:\Program Files\Git\mingw32\bin"]
6570
},
6671
);
72+
}
73+
74+
#[test]
75+
fn locations_under_program_files_ordinary_values_all_vars() {
6776
assert_eq!(
6877
locations_from!(
6978
"ProgramFiles" => {
@@ -82,11 +91,10 @@ mod locations {
8291
r"C:\Program Files (x86)\Git\mingw32\bin",
8392
],
8493
);
85-
assert_eq!(locations_from!(), Vec::<PathBuf>::new());
8694
}
8795

8896
#[test]
89-
fn locations_under_program_files_strange() {
97+
fn locations_under_program_files_strange_values_all_vars_distinct() {
9098
assert_eq!(
9199
locations_from!(
92100
"ProgramFiles" => r"X:\cur\rent",
@@ -110,12 +118,20 @@ mod locations {
110118
]
111119
},
112120
);
121+
}
122+
123+
#[test]
124+
fn locations_under_program_files_strange_values_64bit_var_only() {
113125
assert_eq!(
114126
locations_from!(
115127
"ProgramW6432" => r"Z:\wi\de",
116128
),
117129
pathbuf_vec![r"Z:\wi\de\Git\clangarm64\bin", r"Z:\wi\de\Git\mingw64\bin"],
118130
);
131+
}
132+
133+
#[test]
134+
fn locations_under_program_files_strange_values_all_vars_path_cruft() {
119135
assert_eq!(
120136
locations_from!(
121137
"ProgramFiles" => r"Z:/wi//de/",
@@ -137,6 +153,10 @@ mod locations {
137153
]
138154
},
139155
);
156+
}
157+
158+
#[test]
159+
fn locations_under_program_files_strange_values_some_relative() {
140160
assert_eq!(
141161
locations_from!(
142162
"ProgramFiles" => r"foo\bar",
@@ -161,7 +181,11 @@ mod locations {
161181
// is for the test suite, and doing it this way allows problems to be caught earlier if
162182
// a change made on a 64-bit development machine breaks the IsWow64Process() call.
163183
let mut wow64process = BOOL::default();
164-
unsafe { IsWow64Process(GetCurrentProcess(), &mut wow64process)? };
184+
unsafe {
185+
// SAFETY: `GetCurrentProcess` always succeeds, and the handle it returns is a
186+
// valid process handle to pass to `IsWow64Process`.
187+
IsWow64Process(GetCurrentProcess(), &mut wow64process)?;
188+
}
165189

166190
let platform_bitness = if wow64process.as_bool() {
167191
Self::Is32on64
@@ -181,27 +205,29 @@ mod locations {
181205
Some(folded_text.ends_with(&folded_pattern))
182206
}
183207

184-
/// The common global program files paths on this system, by process and system architecture.
208+
/// The most common global program files paths on this system, by process and system architecture.
209+
///
210+
/// This omits the 32-bit ARM program files directory, as Git for Windows is never installed there.
185211
#[derive(Clone, Debug)]
186212
struct ProgramFilesPaths {
187213
/// The program files directory used for whatever architecture this program was built for.
188214
current: PathBuf,
189215

190-
/// The x86 program files directory regardless of the architecture of the program.
216+
/// The 32-bit x86 program files directory regardless of the architecture of the program.
191217
///
192218
/// If Rust gains Windows targets like ARMv7 where this is unavailable, this could fail.
193219
x86: PathBuf,
194220

195221
/// The 64-bit program files directory if there is one.
196222
///
197-
/// This is present on x64 and also ARM64 systems. On an ARM64 system, ARM64 and AMD64
198-
/// programs use the same program files directory while 32-bit x86 and ARM programs use
199-
/// two others. Only a 32-bit system has no 64-bit program files directory.
223+
/// This is present on x64 (AMD64) and also ARM64 systems. On an ARM64 system, ARM64 and
224+
/// AMD64 programs use the same program files directory while 32-bit x86 and 32-bit ARM
225+
/// programs use two others. Only a 32-bit system has no 64-bit program files directory.
200226
maybe_64bit: Option<PathBuf>,
201227
}
202228

203229
impl ProgramFilesPaths {
204-
/// Get the three common kinds of global program files paths without environment variables.
230+
/// Get the three most common kinds of global program files paths without environment variables.
205231
///
206232
/// The idea here is to obtain this information, which the `alternative_locations()` unit
207233
/// test uses to learn the expected alternative locations, without duplicating *any* of the

0 commit comments

Comments
 (0)