Skip to content

Commit c9ff0ac

Browse files
committed
Update alternative location unit tests for user program files
Similar to the recent commits but for unit-style tests rather than integration-style tests, this updates the unit tests for Windows-specific `git` executable alternative locations to include locations under the per-user program files directory in the user's local application data directory. (As noted in ff3df53 where these unit tests were last updated, they are pure unit tests, rather than integration tests, because of how they test the `locations_under_program_files()` helper rather than `ALTERNATIVE_LOCATIONS` itself.) As in the integration-style tests updated in the preceding two commits, these tests will now fail until the logic for enumerating alternative locations to check for the `git` executable is extended to include locations in the user's local program files directory.
1 parent cab4c85 commit c9ff0ac

File tree

1 file changed

+200
-6
lines changed

1 file changed

+200
-6
lines changed

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

Lines changed: 200 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ mod locations {
5555
}
5656

5757
#[test]
58-
fn locations_under_program_files_ordinary_values_current_var_only() {
58+
fn locations_under_program_files_global_only_ordinary_values_current_var_only() {
5959
assert_eq!(
6060
locations_from!(
6161
"ProgramFiles" => r"C:\Program Files",
@@ -72,7 +72,7 @@ mod locations {
7272
}
7373

7474
#[test]
75-
fn locations_under_program_files_ordinary_values_all_vars() {
75+
fn locations_under_program_files_global_only_ordinary_values_all_vars() {
7676
assert_eq!(
7777
locations_from!(
7878
"ProgramFiles" => {
@@ -94,7 +94,7 @@ mod locations {
9494
}
9595

9696
#[test]
97-
fn locations_under_program_files_strange_values_all_vars_distinct() {
97+
fn locations_under_program_files_global_only_strange_values_all_vars_distinct() {
9898
assert_eq!(
9999
locations_from!(
100100
"ProgramFiles" => r"X:\cur\rent",
@@ -121,7 +121,7 @@ mod locations {
121121
}
122122

123123
#[test]
124-
fn locations_under_program_files_strange_values_64bit_var_only() {
124+
fn locations_under_program_files_global_only_strange_values_64bit_var_only() {
125125
assert_eq!(
126126
locations_from!(
127127
"ProgramW6432" => r"Z:\wi\de",
@@ -131,7 +131,7 @@ mod locations {
131131
}
132132

133133
#[test]
134-
fn locations_under_program_files_strange_values_all_vars_path_cruft() {
134+
fn locations_under_program_files_global_only_strange_values_all_vars_path_cruft() {
135135
assert_eq!(
136136
locations_from!(
137137
"ProgramFiles" => r"Z:/wi//de/",
@@ -156,7 +156,7 @@ mod locations {
156156
}
157157

158158
#[test]
159-
fn locations_under_program_files_strange_values_some_relative() {
159+
fn locations_under_program_files_global_only_strange_values_some_relative() {
160160
assert_eq!(
161161
locations_from!(
162162
"ProgramFiles" => r"foo\bar",
@@ -167,6 +167,200 @@ mod locations {
167167
);
168168
}
169169

170+
#[test]
171+
fn locations_under_program_files_local_only_ordinary_value() {
172+
assert_eq!(
173+
locations_from!(
174+
"LocalAppData" => r"C:\Users\alice\AppData\Local",
175+
),
176+
pathbuf_vec![
177+
r"C:\Users\alice\AppData\Local\Programs\Git\clangarm64\bin",
178+
r"C:\Users\alice\AppData\Local\Programs\Git\mingw64\bin",
179+
r"C:\Users\alice\AppData\Local\Programs\Git\mingw32\bin",
180+
],
181+
);
182+
}
183+
184+
#[test]
185+
fn locations_under_program_files_local_only_strange_value_path_cruft() {
186+
assert_eq!(
187+
locations_from!(
188+
"LocalAppData" => r"\\.\Q:\Documents and Settings/bob\/weird\.\sub//dir",
189+
),
190+
pathbuf_vec![
191+
r"\\.\Q:\Documents and Settings\bob\weird\sub\dir\Programs\Git\clangarm64\bin",
192+
r"\\.\Q:\Documents and Settings\bob\weird\sub\dir\Programs\Git\mingw64\bin",
193+
r"\\.\Q:\Documents and Settings\bob\weird\sub\dir\Programs\Git\mingw32\bin",
194+
],
195+
);
196+
}
197+
198+
#[test]
199+
fn locations_under_program_files_local_only_strange_value_empty() {
200+
assert_eq!(
201+
locations_from!(
202+
"LocalAppData" => "",
203+
),
204+
Vec::<PathBuf>::new(),
205+
);
206+
}
207+
208+
#[test]
209+
fn locations_under_program_files_local_only_strange_value_relative_nonempty() {
210+
assert_eq!(
211+
locations_from!(
212+
"LocalAppData" => r"AppData\Local",
213+
),
214+
Vec::<PathBuf>::new(),
215+
);
216+
}
217+
218+
#[test]
219+
fn locations_under_program_files_local_and_global_ordinary_values_limited_vars() {
220+
assert_eq!(
221+
locations_from!(
222+
"LocalAppData" => r"C:\Users\alice\AppData\Local",
223+
"ProgramFiles" => r"C:\Program Files",
224+
),
225+
if cfg!(target_pointer_width = "64") {
226+
pathbuf_vec![
227+
r"C:\Users\alice\AppData\Local\Programs\Git\clangarm64\bin",
228+
r"C:\Users\alice\AppData\Local\Programs\Git\mingw64\bin",
229+
r"C:\Users\alice\AppData\Local\Programs\Git\mingw32\bin",
230+
r"C:\Program Files\Git\clangarm64\bin",
231+
r"C:\Program Files\Git\mingw64\bin",
232+
]
233+
} else {
234+
pathbuf_vec![
235+
r"C:\Users\alice\AppData\Local\Programs\Git\clangarm64\bin",
236+
r"C:\Users\alice\AppData\Local\Programs\Git\mingw64\bin",
237+
r"C:\Users\alice\AppData\Local\Programs\Git\mingw32\bin",
238+
r"C:\Program Files\Git\mingw32\bin",
239+
]
240+
},
241+
);
242+
}
243+
244+
#[test]
245+
fn locations_under_program_files_local_and_global_ordinary_values_all_vars() {
246+
assert_eq!(
247+
locations_from!(
248+
"LocalAppData" => r"C:\Users\bob\AppData\Local",
249+
"ProgramFiles" => {
250+
if cfg!(target_pointer_width = "64") {
251+
r"C:\Program Files"
252+
} else {
253+
r"C:\Program Files (x86)"
254+
}
255+
},
256+
"ProgramFiles(x86)" => r"C:\Program Files (x86)",
257+
"ProgramW6432" => r"C:\Program Files",
258+
),
259+
pathbuf_vec![
260+
r"C:\Users\bob\AppData\Local\Programs\Git\clangarm64\bin",
261+
r"C:\Users\bob\AppData\Local\Programs\Git\mingw64\bin",
262+
r"C:\Users\bob\AppData\Local\Programs\Git\mingw32\bin",
263+
r"C:\Program Files\Git\clangarm64\bin",
264+
r"C:\Program Files\Git\mingw64\bin",
265+
r"C:\Program Files (x86)\Git\mingw32\bin",
266+
],
267+
);
268+
}
269+
270+
#[test]
271+
fn locations_under_program_files_local_and_global_strange_values_all_vars_distinct() {
272+
assert_eq!(
273+
locations_from!(
274+
"LocalAppData" => r"W:\us\er",
275+
"ProgramFiles" => r"X:\cur\rent",
276+
"ProgramFiles(x86)" => r"Y:\nar\row",
277+
"ProgramW6432" => r"Z:\wi\de",
278+
),
279+
if cfg!(target_pointer_width = "64") {
280+
pathbuf_vec![
281+
r"W:\us\er\Programs\Git\clangarm64\bin",
282+
r"W:\us\er\Programs\Git\mingw64\bin",
283+
r"W:\us\er\Programs\Git\mingw32\bin",
284+
r"Z:\wi\de\Git\clangarm64\bin",
285+
r"Z:\wi\de\Git\mingw64\bin",
286+
r"Y:\nar\row\Git\mingw32\bin",
287+
r"X:\cur\rent\Git\clangarm64\bin",
288+
r"X:\cur\rent\Git\mingw64\bin",
289+
]
290+
} else {
291+
pathbuf_vec![
292+
r"W:\us\er\Programs\Git\clangarm64\bin",
293+
r"W:\us\er\Programs\Git\mingw64\bin",
294+
r"W:\us\er\Programs\Git\mingw32\bin",
295+
r"Z:\wi\de\Git\clangarm64\bin",
296+
r"Z:\wi\de\Git\mingw64\bin",
297+
r"Y:\nar\row\Git\mingw32\bin",
298+
r"X:\cur\rent\Git\mingw32\bin",
299+
]
300+
},
301+
);
302+
}
303+
304+
#[test]
305+
fn locations_under_program_files_local_and_global_strange_values_limited_64bit_var() {
306+
assert_eq!(
307+
locations_from!(
308+
"LocalAppData" => r"W:\us\er",
309+
"ProgramW6432" => r"Z:\wi\de",
310+
),
311+
pathbuf_vec![
312+
r"W:\us\er\Programs\Git\clangarm64\bin",
313+
r"W:\us\er\Programs\Git\mingw64\bin",
314+
r"W:\us\er\Programs\Git\mingw32\bin",
315+
r"Z:\wi\de\Git\clangarm64\bin",
316+
r"Z:\wi\de\Git\mingw64\bin",
317+
],
318+
);
319+
}
320+
321+
#[test]
322+
fn locations_under_program_files_local_and_global_strange_values_crufty_cross_clash() {
323+
assert_eq!(
324+
locations_from!(
325+
"LocalAppData" => r"Y:\nar\row",
326+
"ProgramFiles" => r"Z:/wi//de/",
327+
"ProgramFiles(x86)" => r"Y:/\nar/row\Programs",
328+
"ProgramW6432" => r"Z:\wi\.\de",
329+
),
330+
if cfg!(target_pointer_width = "64") {
331+
pathbuf_vec![
332+
r"Y:\nar\row\Programs\Git\clangarm64\bin",
333+
r"Y:\nar\row\Programs\Git\mingw64\bin",
334+
r"Y:\nar\row\Programs\Git\mingw32\bin",
335+
r"Z:\wi\de\Git\clangarm64\bin",
336+
r"Z:\wi\de\Git\mingw64\bin",
337+
]
338+
} else {
339+
pathbuf_vec![
340+
r"Y:\nar\row\Programs\Git\clangarm64\bin",
341+
r"Y:\nar\row\Programs\Git\mingw64\bin",
342+
r"Y:\nar\row\Programs\Git\mingw32\bin",
343+
r"Z:\wi\de\Git\clangarm64\bin",
344+
r"Z:\wi\de\Git\mingw64\bin",
345+
r"Z:\wi\de\Git\mingw32\bin",
346+
]
347+
},
348+
);
349+
}
350+
351+
#[test]
352+
fn locations_under_program_files_local_and_global_strange_values_some_relative() {
353+
assert_eq!(
354+
locations_from!(
355+
"LocalAppData" => "dir",
356+
"ProgramFiles" => r"foo\bar",
357+
"ProgramFiles(x86)" => r"\\host\share\subdir",
358+
"ProgramW6432" => r"",
359+
),
360+
pathbuf_vec![r"\\host\share\subdir\Git\mingw32\bin"],
361+
);
362+
}
363+
170364
#[derive(Clone, Copy, Debug)]
171365
enum PlatformBitness {
172366
Is32on32,

0 commit comments

Comments
 (0)