Skip to content

Commit f87322e

Browse files
committed
Merge branch 'fix-1440'
2 parents e2e8cf9 + f5a9884 commit f87322e

File tree

10 files changed

+113
-34
lines changed

10 files changed

+113
-34
lines changed
Binary file not shown.
Binary file not shown.

gix-diff/tests/tree/mod.rs

-9
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,8 @@ mod changes {
253253
":100644 100644 28ce6a8b26aa170e1de65536fe8abe1832bd3242 13c2aca72ab576cb5f22dc8e7f8ba8ddab553a8a M f/f"
254254
);
255255

256-
#[cfg(windows)]
257-
let tree_with_link_id = hex_to_id("3b287f8730c81d0b763c2d294618a5e32b67b4f8");
258-
#[cfg(windows)]
259-
let link_entry_oid = hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
260-
#[cfg(windows)]
261-
let link_entry_mode = EntryKind::Blob;
262-
#[cfg(not(windows))]
263256
let tree_with_link_id = hex_to_id("7e26dba59b6336f87d1d4ae3505a2da302b91c76");
264-
#[cfg(not(windows))]
265257
let link_entry_oid = hex_to_id("2e65efe2a145dda7ee51d1741299f848e5bf752e");
266-
#[cfg(not(windows))]
267258
let link_entry_mode = EntryKind::Link;
268259
assert_eq!(
269260
diff_with_previous_commit_from(&db, &all_commits["f/f mode changed to link"])?,

gix-filter/tests/driver/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod baseline {
1111
if cfg!(windows) {
1212
exe = exe.replace('\\', "/");
1313
}
14-
gix_testtools::scripted_fixture_read_only_with_args("baseline.sh", [exe])?;
14+
gix_testtools::scripted_fixture_read_only_with_args_single_archive("baseline.sh", [exe])?;
1515
Ok(())
1616
}
1717
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
make_worktree_repo.tar
2+
make_worktree_repo_packed.tar

gix/src/remote/connection/fetch/update_refs/tests.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ mod update {
2525
}
2626

2727
fn repo(name: &str) -> gix::Repository {
28-
let dir =
29-
gix_testtools::scripted_fixture_read_only_with_args("make_fetch_repos.sh", [base_repo_path()]).unwrap();
28+
let dir = gix_testtools::scripted_fixture_read_only_with_args_single_archive(
29+
"make_fetch_repos.sh",
30+
[base_repo_path()],
31+
)
32+
.unwrap();
3033
gix::open_opts(dir.join(name), restricted()).unwrap()
3134
}
3235
fn named_repo(name: &str) -> gix::Repository {
3336
let dir = gix_testtools::scripted_fixture_read_only("make_remote_repos.sh").unwrap();
3437
gix::open_opts(dir.join(name), restricted()).unwrap()
3538
}
3639
fn repo_rw(name: &str) -> (gix::Repository, gix_testtools::tempfile::TempDir) {
37-
let dir = gix_testtools::scripted_fixture_writable_with_args(
40+
let dir = gix_testtools::scripted_fixture_writable_with_args_single_archive(
3841
"make_fetch_repos.sh",
3942
[base_repo_path()],
4043
gix_testtools::Creation::ExecuteScript,
@@ -189,7 +192,7 @@ mod update {
189192

190193
#[test]
191194
fn checked_out_branches_in_worktrees_are_rejected_with_additional_information() -> Result {
192-
let root = gix_path::realpath(gix_testtools::scripted_fixture_read_only_with_args(
195+
let root = gix_path::realpath(gix_testtools::scripted_fixture_read_only_with_args_single_archive(
193196
"make_fetch_repos.sh",
194197
[base_repo_path()],
195198
)?)?;

gix/tests/fixtures/generated-archives/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/make_worktree_repo.tar
2+
/make_worktree_repo_bare.tar
23
/make_worktree_repo_with_configs.tar
34
/make_remote_repos.tar
45
/make_complex_shallow_repo.tar

gix/tests/remote/fetch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ mod blocking_and_async_io {
6363
args: impl IntoIterator<Item = S>,
6464
mode: Mode,
6565
) -> Result<(gix::Repository, gix_testtools::tempfile::TempDir), gix::open::Error> {
66-
let dir = gix_testtools::scripted_fixture_writable_with_args(
66+
let dir = gix_testtools::scripted_fixture_writable_with_args_single_archive(
6767
"make_fetch_repos.sh",
6868
[{
6969
let mut url = base_repo_path();

gix/tests/repository/shallow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mod traverse {
7272
#[parallel]
7373
fn complex_graphs_can_be_iterated_despite_multiple_shallow_boundaries() -> crate::Result {
7474
let base = gix_path::realpath(gix_testtools::scripted_fixture_read_only("make_remote_repos.sh")?.join("base"))?;
75-
let shallow_base = gix_testtools::scripted_fixture_read_only_with_args(
75+
let shallow_base = gix_testtools::scripted_fixture_read_only_with_args_single_archive(
7676
"make_complex_shallow_repo.sh",
7777
Some(base.to_string_lossy()),
7878
)?;

tests/tools/src/lib.rs

+101-18
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@ enum DirectoryRoot {
224224
StandaloneTest,
225225
}
226226

227+
/// Don't add a suffix to the archive name as `args` are platform dependent, none-deterministic,
228+
/// or otherwise don't influence the content of the archive.
229+
/// Note that this also means that `args` won't be used to control the hash of the archive itself.
230+
#[derive(Copy, Clone)]
231+
enum ArgsInHash {
232+
Yes,
233+
No,
234+
}
235+
227236
/// Return the path to the `<crate-root>/tests/fixtures/<path>` directory.
228237
pub fn fixture_path(path: impl AsRef<Path>) -> PathBuf {
229238
fixture_path_inner(path, DirectoryRoot::IntegrationTest)
@@ -309,7 +318,19 @@ pub fn scripted_fixture_writable_with_args(
309318
args: impl IntoIterator<Item = impl Into<String>>,
310319
mode: Creation,
311320
) -> Result<tempfile::TempDir> {
312-
scripted_fixture_writable_with_args_inner(script_name, args, mode, DirectoryRoot::IntegrationTest)
321+
scripted_fixture_writable_with_args_inner(script_name, args, mode, DirectoryRoot::IntegrationTest, ArgsInHash::Yes)
322+
}
323+
324+
/// Like [`scripted_fixture_writable()`], but passes `args` to `script_name` while providing control over
325+
/// the way files are created with `mode`.
326+
///
327+
/// See [`scripted_fixture_read_only_with_args_single_archive()`] for important details on what `single_archive` means.
328+
pub fn scripted_fixture_writable_with_args_single_archive(
329+
script_name: impl AsRef<Path>,
330+
args: impl IntoIterator<Item = impl Into<String>>,
331+
mode: Creation,
332+
) -> Result<tempfile::TempDir> {
333+
scripted_fixture_writable_with_args_inner(script_name, args, mode, DirectoryRoot::IntegrationTest, ArgsInHash::No)
313334
}
314335

315336
/// Like [`scripted_fixture_writable_with_args`], but does not prefix the fixture directory with `tests`
@@ -318,24 +339,36 @@ pub fn scripted_fixture_writable_with_args_standalone(
318339
args: impl IntoIterator<Item = impl Into<String>>,
319340
mode: Creation,
320341
) -> Result<tempfile::TempDir> {
321-
scripted_fixture_writable_with_args_inner(script_name, args, mode, DirectoryRoot::StandaloneTest)
342+
scripted_fixture_writable_with_args_inner(script_name, args, mode, DirectoryRoot::StandaloneTest, ArgsInHash::Yes)
343+
}
344+
345+
/// Like [`scripted_fixture_writable_with_args`], but does not prefix the fixture directory with `tests`
346+
///
347+
/// See [`scripted_fixture_read_only_with_args_single_archive()`] for important details on what `single_archive` means.
348+
pub fn scripted_fixture_writable_with_args_standalone_single_archive(
349+
script_name: &str,
350+
args: impl IntoIterator<Item = impl Into<String>>,
351+
mode: Creation,
352+
) -> Result<tempfile::TempDir> {
353+
scripted_fixture_writable_with_args_inner(script_name, args, mode, DirectoryRoot::StandaloneTest, ArgsInHash::No)
322354
}
323355

324356
fn scripted_fixture_writable_with_args_inner(
325357
script_name: impl AsRef<Path>,
326358
args: impl IntoIterator<Item = impl Into<String>>,
327359
mode: Creation,
328360
root: DirectoryRoot,
361+
args_in_hash: ArgsInHash,
329362
) -> Result<tempfile::TempDir> {
330363
let dst = tempfile::TempDir::new()?;
331364
Ok(match mode {
332365
Creation::CopyFromReadOnly => {
333-
let ro_dir = scripted_fixture_read_only_with_args_inner(script_name, args, None, root)?;
366+
let ro_dir = scripted_fixture_read_only_with_args_inner(script_name, args, None, root, args_in_hash)?;
334367
copy_recursively_into_existing_dir(ro_dir, dst.path())?;
335368
dst
336369
}
337370
Creation::ExecuteScript => {
338-
scripted_fixture_read_only_with_args_inner(script_name, args, dst.path().into(), root)?;
371+
scripted_fixture_read_only_with_args_inner(script_name, args, dst.path().into(), root, args_in_hash)?;
339372
dst
340373
}
341374
})
@@ -365,22 +398,49 @@ pub fn scripted_fixture_read_only_with_args(
365398
script_name: impl AsRef<Path>,
366399
args: impl IntoIterator<Item = impl Into<String>>,
367400
) -> Result<PathBuf> {
368-
scripted_fixture_read_only_with_args_inner(script_name, args, None, DirectoryRoot::IntegrationTest)
401+
scripted_fixture_read_only_with_args_inner(script_name, args, None, DirectoryRoot::IntegrationTest, ArgsInHash::Yes)
402+
}
403+
404+
/// Like `scripted_fixture_read_only()`], but passes `args` to `script_name`.
405+
///
406+
/// Also, don't add a suffix to the archive name as `args` are platform dependent, none-deterministic,
407+
/// or otherwise don't influence the content of the archive.
408+
/// Note that this also means that `args` won't be used to control the hash of the archive itself.
409+
///
410+
/// Sometimes, this should be combined with adding the archive name to `.gitignore` to prevent its creation
411+
/// in the first place.
412+
///
413+
/// Note that suffixing archives by default helps to learn what calls are made, and forces the author to
414+
/// think about what should be done to get it right.
415+
pub fn scripted_fixture_read_only_with_args_single_archive(
416+
script_name: impl AsRef<Path>,
417+
args: impl IntoIterator<Item = impl Into<String>>,
418+
) -> Result<PathBuf> {
419+
scripted_fixture_read_only_with_args_inner(script_name, args, None, DirectoryRoot::IntegrationTest, ArgsInHash::No)
369420
}
370421

371422
/// Like [`scripted_fixture_read_only_with_args()`], but does not prefix the fixture directory with `tests`
372423
pub fn scripted_fixture_read_only_with_args_standalone(
373424
script_name: impl AsRef<Path>,
374425
args: impl IntoIterator<Item = impl Into<String>>,
375426
) -> Result<PathBuf> {
376-
scripted_fixture_read_only_with_args_inner(script_name, args, None, DirectoryRoot::StandaloneTest)
427+
scripted_fixture_read_only_with_args_inner(script_name, args, None, DirectoryRoot::StandaloneTest, ArgsInHash::Yes)
428+
}
429+
430+
/// Like [`scripted_fixture_read_only_with_args_standalone()`], only has a single archive.
431+
pub fn scripted_fixture_read_only_with_args_standalone_single_archive(
432+
script_name: impl AsRef<Path>,
433+
args: impl IntoIterator<Item = impl Into<String>>,
434+
) -> Result<PathBuf> {
435+
scripted_fixture_read_only_with_args_inner(script_name, args, None, DirectoryRoot::StandaloneTest, ArgsInHash::No)
377436
}
378437

379438
fn scripted_fixture_read_only_with_args_inner(
380439
script_name: impl AsRef<Path>,
381440
args: impl IntoIterator<Item = impl Into<String>>,
382441
destination_dir: Option<&Path>,
383442
root: DirectoryRoot,
443+
args_in_hash: ArgsInHash,
384444
) -> Result<PathBuf> {
385445
// Assure tempfiles get removed when aborting the test.
386446
gix_tempfile::signal::setup(
@@ -414,11 +474,23 @@ fn scripted_fixture_read_only_with_args_inner(
414474

415475
let script_basename = script_location.file_stem().unwrap_or(script_location.as_os_str());
416476
let archive_file_path = fixture_path_inner(
417-
Path::new("generated-archives").join(format!(
418-
"{}.tar{}",
419-
script_basename.to_str().expect("valid UTF-8"),
420-
if cfg!(feature = "xz") { ".xz" } else { "" }
421-
)),
477+
{
478+
let suffix = match args_in_hash {
479+
ArgsInHash::Yes => {
480+
let mut suffix = args.join("_");
481+
if !suffix.is_empty() {
482+
suffix.insert(0, '_');
483+
}
484+
suffix.replace(['\\', '/', ' ', '.'], "_")
485+
}
486+
ArgsInHash::No => "".into(),
487+
};
488+
Path::new("generated-archives").join(format!(
489+
"{}{suffix}.tar{}",
490+
script_basename.to_str().expect("valid UTF-8"),
491+
if cfg!(feature = "xz") { ".xz" } else { "" }
492+
))
493+
},
422494
root,
423495
);
424496
let (force_run, script_result_directory) = destination_dir.map_or_else(
@@ -447,7 +519,15 @@ fn scripted_fixture_read_only_with_args_inner(
447519
std::fs::remove_dir_all(&script_result_directory).map_err(|err| format!("Failed to remove '{script_result_directory:?}', please try to do that by hand. Original error: {err}"))?
448520
}
449521
std::fs::create_dir_all(&script_result_directory)?;
450-
match extract_archive(&archive_file_path, &script_result_directory, script_identity) {
522+
let script_identity_for_archive = match args_in_hash {
523+
ArgsInHash::Yes => script_identity,
524+
ArgsInHash::No => 0,
525+
};
526+
match extract_archive(
527+
&archive_file_path,
528+
&script_result_directory,
529+
script_identity_for_archive,
530+
) {
451531
Ok((archive_id, platform)) => {
452532
eprintln!(
453533
"Extracted fixture from archive '{}' ({}, {:?})",
@@ -489,12 +569,15 @@ fn scripted_fixture_read_only_with_args_inner(
489569
output.stdout.as_bstr(),
490570
output.stderr.as_bstr()
491571
);
492-
create_archive_if_not_on_ci(&script_result_directory, &archive_file_path, script_identity).map_err(
493-
|err| {
494-
write_failure_marker(&failure_marker);
495-
err
496-
},
497-
)?;
572+
create_archive_if_not_on_ci(
573+
&script_result_directory,
574+
&archive_file_path,
575+
script_identity_for_archive,
576+
)
577+
.map_err(|err| {
578+
write_failure_marker(&failure_marker);
579+
err
580+
})?;
498581
}
499582
}
500583
}

0 commit comments

Comments
 (0)