Skip to content

Commit

Permalink
Refactor(tests/common+ship): Remove some repetition with new assert_n…
Browse files Browse the repository at this point in the history
…ot_installed_all

Signed-off-by: Paul Mabileau <[email protected]>
  • Loading branch information
PaulDance committed Aug 13, 2024
1 parent e7a9ee5 commit 614daec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 8 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ pub fn assert_not_installed(pkg: &'static str) {
);
}

/// Runs [`assert_not_installed`] on all the packages yielded by the given
/// iterator.
pub fn assert_not_installed_all(pkgs: impl IntoIterator<Item = &'static str>) {
for pkg in pkgs {
assert_not_installed(pkg);
}
}

/// Publishes the given package name and version to the local fake registry
/// with minimal contents.
pub fn fake_publish(pkg: &str, ver: &str) {
Expand Down
16 changes: 5 additions & 11 deletions tests/ship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,7 @@ fn validate_ship_install_failfast() {
.stderr_eq(snapbox::file![
"fixtures/ship/validate_ship_install_failfast.stderr"
]);
assert_not_installed("abc");
assert_not_installed("def");
assert_not_installed_all(["abc", "def"]);
}

#[cargo_test]
Expand Down Expand Up @@ -1579,8 +1578,7 @@ fn validate_ship_partial_nofailfast_allerrnoff_isenderr() {
"fixtures/ship/validate_ship_partial_nofailfast_allerrnoff_isenderr.stderr"
]);
assert_installed_all(["p1", "p3", "p5"]);
assert_not_installed("p2");
assert_not_installed("p4");
assert_not_installed_all(["p2", "p4"]);
}

#[cargo_test]
Expand All @@ -1606,9 +1604,7 @@ fn validate_ship_partial_nofailfast_oneerrnoff_oneerrff_isfasterr() {
"fixtures/ship/validate_ship_partial_nofailfast_oneerrnoff_oneerrff_isfasterr.stderr"
]);
assert_installed_all(["p1", "p3"]);
assert_not_installed("p2");
assert_not_installed("p4");
assert_not_installed("p5");
assert_not_installed_all(["p2", "p4", "p5"]);
}

#[cargo_test]
Expand Down Expand Up @@ -1667,8 +1663,7 @@ fn validate_ship_partialandglobal_nofailfast_allerrnoff_isenderr() {
"fixtures/ship/validate_ship_partialandglobal_nofailfast_allerrnoff_isenderr.stderr"
]);
assert_installed_all(["p1", "p3", "p5"]);
assert_not_installed("p2");
assert_not_installed("p4");
assert_not_installed_all(["p2", "p4"]);
}

#[cargo_test]
Expand All @@ -1694,8 +1689,7 @@ fn validate_ship_partialandglobal_nofailfast_oneerrnoff_oneerrff_isenderr() {
"fixtures/ship/validate_ship_partialandglobal_nofailfast_oneerrnoff_oneerrff_isenderr.stderr"
]);
assert_installed_all(["p1", "p3", "p5"]);
assert_not_installed("p2");
assert_not_installed("p4");
assert_not_installed_all(["p2", "p4"]);
}

#[cargo_test]
Expand Down

0 comments on commit 614daec

Please sign in to comment.