Skip to content

Commit 40b3d02

Browse files
committed
test(git): generalize shallow tests
1 parent 4f15cc8 commit 40b3d02

File tree

1 file changed

+53
-21
lines changed

1 file changed

+53
-21
lines changed

tests/testsuite/git_shallow.rs

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ fn fetch_dep_two_revs(backend: Backend, mode: RepoMode) {
130130

131131
#[cargo_test]
132132
fn gitoxide_fetch_shallow_dep_branch_and_rev() -> anyhow::Result<()> {
133+
fetch_shallow_dep_branch_and_rev(Backend::Gitoxide)
134+
}
135+
136+
fn fetch_shallow_dep_branch_and_rev(backend: Backend) -> anyhow::Result<()> {
133137
let (bar, bar_repo) = git::new_repo("bar", |p| {
134138
p.file("Cargo.toml", &basic_manifest("bar", "1.0.0"))
135139
.file("src/lib.rs", "")
@@ -164,8 +168,8 @@ fn gitoxide_fetch_shallow_dep_branch_and_rev() -> anyhow::Result<()> {
164168
.build();
165169

166170
p.cargo("check")
167-
.arg("-Zgitoxide=fetch")
168-
.arg("-Zgit=shallow-deps")
171+
.arg_line(backend.to_arg())
172+
.arg_line(RepoMode::Shallow.to_deps_arg())
169173
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-deps"])
170174
.run();
171175

@@ -188,6 +192,10 @@ fn gitoxide_fetch_shallow_dep_branch_and_rev() -> anyhow::Result<()> {
188192

189193
#[cargo_test]
190194
fn gitoxide_fetch_shallow_dep_branch_to_rev() -> anyhow::Result<()> {
195+
fetch_shallow_dep_branch_to_rev(Backend::Gitoxide)
196+
}
197+
198+
fn fetch_shallow_dep_branch_to_rev(backend: Backend) -> anyhow::Result<()> {
191199
// db exists from previous build, then dependency changes to refer to revision that isn't
192200
// available in the shallow fetch.
193201

@@ -221,8 +229,8 @@ fn gitoxide_fetch_shallow_dep_branch_to_rev() -> anyhow::Result<()> {
221229
.build();
222230

223231
p.cargo("check")
224-
.arg("-Zgitoxide=fetch")
225-
.arg("-Zgit=shallow-deps")
232+
.arg_line(backend.to_arg())
233+
.arg_line(RepoMode::Shallow.to_deps_arg())
226234
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-deps"])
227235
.run();
228236

@@ -252,8 +260,8 @@ fn gitoxide_fetch_shallow_dep_branch_to_rev() -> anyhow::Result<()> {
252260
.build();
253261

254262
p.cargo("check")
255-
.arg("-Zgitoxide=fetch")
256-
.arg("-Zgit=shallow-deps")
263+
.arg_line(backend.to_arg())
264+
.arg_line(RepoMode::Shallow.to_deps_arg())
257265
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-deps"])
258266
.run();
259267

@@ -267,6 +275,10 @@ fn gitoxide_fetch_shallow_dep_branch_to_rev() -> anyhow::Result<()> {
267275

268276
#[cargo_test]
269277
fn gitoxide_fetch_shallow_index_then_git2_fetch_complete() -> anyhow::Result<()> {
278+
fetch_shallow_index_then_git2_fetch_complete(Backend::Gitoxide)
279+
}
280+
281+
fn fetch_shallow_index_then_git2_fetch_complete(backend: Backend) -> anyhow::Result<()> {
270282
Package::new("bar", "1.0.0").publish();
271283
let p = project()
272284
.file(
@@ -283,7 +295,7 @@ fn gitoxide_fetch_shallow_index_then_git2_fetch_complete() -> anyhow::Result<()>
283295
.file("src/lib.rs", "")
284296
.build();
285297
p.cargo("fetch")
286-
.arg("-Zgitoxide=fetch")
298+
.arg_line(backend.to_arg())
287299
.arg("-Zgit=shallow-index")
288300
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
289301
.run();
@@ -323,6 +335,10 @@ fn gitoxide_fetch_shallow_index_then_git2_fetch_complete() -> anyhow::Result<()>
323335

324336
#[cargo_test]
325337
fn gitoxide_fetch_shallow_dep_then_git2_fetch_complete() -> anyhow::Result<()> {
338+
fetch_shallow_dep_then_git2_fetch_complete(Backend::Gitoxide)
339+
}
340+
341+
fn fetch_shallow_dep_then_git2_fetch_complete(backend: Backend) -> anyhow::Result<()> {
326342
// Example where an old lockfile with an explicit branch="master" in Cargo.toml.
327343
Package::new("bar", "1.0.0").publish();
328344
let (bar, bar_repo) = git::new_repo("bar", |p| {
@@ -363,8 +379,8 @@ fn gitoxide_fetch_shallow_dep_then_git2_fetch_complete() -> anyhow::Result<()> {
363379
.build();
364380

365381
p.cargo("update")
366-
.arg("-Zgitoxide=fetch")
367-
.arg("-Zgit=shallow-deps")
382+
.arg_line(backend.to_arg())
383+
.arg_line(RepoMode::Shallow.to_deps_arg())
368384
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-deps"])
369385
.run();
370386

@@ -460,6 +476,10 @@ fn gitoxide_fetch_shallow_dep_then_git2_fetch_complete() -> anyhow::Result<()> {
460476

461477
#[cargo_test]
462478
fn gitoxide_fetch_shallow_dep_then_gitoxide_fetch_complete() -> anyhow::Result<()> {
479+
fetch_shallow_dep_then_gitoxide_fetch_complete(Backend::Gitoxide)
480+
}
481+
482+
fn fetch_shallow_dep_then_gitoxide_fetch_complete(backend: Backend) -> anyhow::Result<()> {
463483
Package::new("bar", "1.0.0").publish();
464484
let (bar, bar_repo) = git::new_repo("bar", |p| {
465485
p.file("Cargo.toml", &basic_manifest("bar", "1.0.0"))
@@ -499,8 +519,8 @@ fn gitoxide_fetch_shallow_dep_then_gitoxide_fetch_complete() -> anyhow::Result<(
499519
.build();
500520

501521
p.cargo("update")
502-
.arg("-Zgitoxide=fetch")
503-
.arg("-Zgit=shallow-deps")
522+
.arg_line(backend.to_arg())
523+
.arg_line(RepoMode::Shallow.to_deps_arg())
504524
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-deps"])
505525
.run();
506526

@@ -544,7 +564,7 @@ fn gitoxide_fetch_shallow_dep_then_gitoxide_fetch_complete() -> anyhow::Result<(
544564
}
545565

546566
p.cargo("update")
547-
.arg("-Zgitoxide=fetch") // shallow-deps is omitted intentionally
567+
.arg_line(Backend::Gitoxide.to_arg()) // shallow-deps is omitted intentionally
548568
.masquerade_as_nightly_cargo(&["gitoxide=fetch"])
549569
.run();
550570

@@ -599,6 +619,10 @@ fn gitoxide_fetch_shallow_dep_then_gitoxide_fetch_complete() -> anyhow::Result<(
599619

600620
#[cargo_test]
601621
fn gitoxide_fetch_shallow_index_then_preserve_shallow() -> anyhow::Result<()> {
622+
fetch_shallow_index_then_preserve_shallow(Backend::Gitoxide)
623+
}
624+
625+
fn fetch_shallow_index_then_preserve_shallow(backend: Backend) -> anyhow::Result<()> {
602626
Package::new("bar", "1.0.0").publish();
603627
let p = project()
604628
.file(
@@ -615,7 +639,7 @@ fn gitoxide_fetch_shallow_index_then_preserve_shallow() -> anyhow::Result<()> {
615639
.file("src/lib.rs", "")
616640
.build();
617641
p.cargo("fetch")
618-
.arg("-Zgitoxide=fetch")
642+
.arg_line(backend.to_arg())
619643
.arg("-Zgit=shallow-index")
620644
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
621645
.run();
@@ -633,7 +657,7 @@ fn gitoxide_fetch_shallow_index_then_preserve_shallow() -> anyhow::Result<()> {
633657

634658
Package::new("bar", "1.1.0").publish();
635659
p.cargo("update")
636-
.arg("-Zgitoxide=fetch")
660+
.arg_line(backend.to_arg())
637661
.arg("-Zgit=shallow-index") // NOTE: the flag needs to be consistent or else a different index is created
638662
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
639663
.run();
@@ -651,7 +675,7 @@ fn gitoxide_fetch_shallow_index_then_preserve_shallow() -> anyhow::Result<()> {
651675
Package::new("bar", "1.2.0").publish();
652676
Package::new("bar", "1.3.0").publish();
653677
p.cargo("update")
654-
.arg("-Zgitoxide=fetch")
678+
.arg_line(backend.to_arg())
655679
.arg("-Zgit=shallow-index")
656680
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
657681
.run();
@@ -672,6 +696,10 @@ fn gitoxide_fetch_shallow_index_then_preserve_shallow() -> anyhow::Result<()> {
672696
/// If there is shallow *and* non-shallow fetches, non-shallow will naturally be returned due to sort order.
673697
#[cargo_test]
674698
fn gitoxide_fetch_complete_index_then_shallow() -> anyhow::Result<()> {
699+
fetch_complete_index_then_shallow(Backend::Gitoxide)
700+
}
701+
702+
fn fetch_complete_index_then_shallow(backend: Backend) -> anyhow::Result<()> {
675703
Package::new("bar", "1.0.0").publish();
676704
let p = project()
677705
.file(
@@ -688,7 +716,7 @@ fn gitoxide_fetch_complete_index_then_shallow() -> anyhow::Result<()> {
688716
.file("src/lib.rs", "")
689717
.build();
690718
p.cargo("fetch")
691-
.arg("-Zgitoxide=fetch")
719+
.arg_line(backend.to_arg())
692720
.masquerade_as_nightly_cargo(&["gitoxide=fetch"])
693721
.run();
694722

@@ -705,7 +733,7 @@ fn gitoxide_fetch_complete_index_then_shallow() -> anyhow::Result<()> {
705733

706734
Package::new("bar", "1.1.0").publish();
707735
p.cargo("update")
708-
.arg("-Zgitoxide=fetch")
736+
.arg_line(backend.to_arg())
709737
.arg("-Zgit=shallow-index")
710738
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
711739
.run();
@@ -728,7 +756,7 @@ fn gitoxide_fetch_complete_index_then_shallow() -> anyhow::Result<()> {
728756
Package::new("bar", "1.2.0").publish();
729757
Package::new("bar", "1.3.0").publish();
730758
p.cargo("update")
731-
.arg("-Zgitoxide=fetch")
759+
.arg_line(backend.to_arg())
732760
.arg("-Zgit=shallow-index")
733761
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
734762
.run();
@@ -745,7 +773,7 @@ fn gitoxide_fetch_complete_index_then_shallow() -> anyhow::Result<()> {
745773
assert!(shallow_repo.is_shallow());
746774

747775
p.cargo("update")
748-
.arg("-Zgitoxide=fetch")
776+
.arg_line(backend.to_arg())
749777
.masquerade_as_nightly_cargo(&["gitoxide=fetch"])
750778
.run();
751779

@@ -763,6 +791,10 @@ fn gitoxide_fetch_complete_index_then_shallow() -> anyhow::Result<()> {
763791

764792
#[cargo_test]
765793
fn gitoxide_fetch_shallow_index_then_abort_and_update() -> anyhow::Result<()> {
794+
fetch_shallow_index_then_abort_and_update(Backend::Gitoxide)
795+
}
796+
797+
fn fetch_shallow_index_then_abort_and_update(backend: Backend) -> anyhow::Result<()> {
766798
Package::new("bar", "1.0.0").publish();
767799
let p = project()
768800
.file(
@@ -779,7 +811,7 @@ fn gitoxide_fetch_shallow_index_then_abort_and_update() -> anyhow::Result<()> {
779811
.file("src/lib.rs", "")
780812
.build();
781813
p.cargo("fetch")
782-
.arg("-Zgitoxide=fetch")
814+
.arg_line(backend.to_arg())
783815
.arg("-Zgit=shallow-index")
784816
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
785817
.run();
@@ -802,7 +834,7 @@ fn gitoxide_fetch_shallow_index_then_abort_and_update() -> anyhow::Result<()> {
802834

803835
Package::new("bar", "1.1.0").publish();
804836
p.cargo("update")
805-
.arg("-Zgitoxide=fetch")
837+
.arg_line(backend.to_arg())
806838
.arg("-Zgit=shallow-index")
807839
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
808840
.run();

0 commit comments

Comments
 (0)