Skip to content

Commit

Permalink
Test(ship): Add coverage for binstall
Browse files Browse the repository at this point in the history
As part of #16.

Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>
  • Loading branch information
PaulDance committed Dec 23, 2024
1 parent 27766e4 commit 2961c41
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
INFO cargo_liner::cargo > Fetching latest package versions...
Updating `dummy-registry` index
note: to learn more about a package, run `cargo info <name>`
INFO cargo_liner > Results:
┌──────┬─────────────┬─────────────┬────────┐
│ Name │ Old version │ New version │ Status │
├──────┼─────────────┼─────────────┼────────┤
│ abc │ ø │ 0.0.0 │ 🛈 │
└──────┴─────────────┴─────────────┴────────┘
INFO cargo_liner::cargo > Installing `abc`...
INFO resolve: Resolving package: 'abc'
ERROR Fatal error:

× For crate abc: could not GET http://127.0.0.1:[..]/index/config.json:
│ builder error for url (http://127.0.0.1:[..]/index/config.json)
├─▶ could not GET http://127.0.0.1:[..]/index/config.json: builder error
│ for url (http://127.0.0.1:[..]/index/config.json)
├─▶ builder error for url (http://127.0.0.1:[..]/index/config.json)
╰─▶ URL scheme is not allowed

Error:
0: Failed to install or update one of the configured packages.
1: Failed to install "abc".
2: Cargo process finished unsuccessfully: [EXIT_STATUS]: 76

Location:
src/[..].rs:[..]

Note: This can happen for many reasons.
Suggestion: Read Cargo's output.
Suggestion: Use `--no-fail-fast` to ignore this and continue on with other packages.

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
INFO cargo_liner::cargo > Fetching latest package versions...
Updating `dummy-registry` index
note: to learn more about a package, run `cargo info <name>`
INFO cargo_liner > Results:
┌──────┬─────────────┬─────────────┬────────┐
│ Name │ Old version │ New version │ Status │
├──────┼─────────────┼─────────────┼────────┤
│ abc │ ø │ 0.0.0 │ 🛈 │
└──────┴─────────────┴─────────────┴────────┘
INFO cargo_liner::cargo > Installing `abc`...
Updating `dummy-registry` index
Downloading crates ...
Downloaded abc v0.0.0 (registry `dummy-registry`)
Installing abc v0.0.0 (registry `dummy-registry`)
Updating `dummy-registry` index
Compiling abc v0.0.0 (registry `dummy-registry`)
Finished `release` profile [optimized] target(s) in [ELAPSED]s
Installing [ROOT]/home/.cargo/bin/abc
Installed package `abc v0.0.0 (registry `dummy-registry`)` (executable `abc`)
warning: be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
INFO cargo_liner > Installation report:
┌──────┬─────────────┬─────────────┬────────┐
│ Name │ Old version │ New version │ Status │
├──────┼─────────────┼─────────────┼────────┤
│ abc │ ø │ 0.0.0 │ + │
└──────┴─────────────┴─────────────┴────────┘
INFO cargo_liner > Done.
110 changes: 110 additions & 0 deletions tests/ship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1962,3 +1962,113 @@ fn validate_ship_confignoself_envwithself_clinoself_noupdate() {
.stderr_eq(snapbox::file!["fixtures/ship/validate_ship_noself_nothing.stderr"].raw());
assert_installed("cargo-liner");
}

/// Test that the tool is at least called when using `always` globally.
///
/// Binstall seems to outright refuse http URLs, so it is rather incompatible
/// with the execution context used here. Just at least validating the tool is
/// indeed called seems to be the only possibility here.
#[ignore = "cargo-binstall is not made available to CI yet."]
#[cargo_test]
fn validate_ship_binstall_globalalways_isused() {
let _reg = init_registry();
fake_install_self();
fake_publish("abc", "0.0.0");
write_user_config(&[
"[defaults]",
"ship.binstall = 'always'",
"[packages]",
// Explicitly passing the registry is necessary as otherwise crates.io
// is implicitly used by the tool that does not have the same hacks.
"abc = { version = '*', registry = 'dummy-registry' }",
]);

cargo_liner()
.args(["ship", "--no-self"])
.assert()
.failure()
.stdout_eq("".into_data().raw())
.stderr_eq(snapbox::file![
"fixtures/ship/validate_ship_binstall_globalalways_isused.stderr"
]);
assert_not_installed("abc");
}

/// Test that the tool is not used when using `never` globally.
///
/// This is the same as if only letting `auto` since it is disabled under tests.
#[ignore = "cargo-binstall is not made available to CI yet."]
#[cargo_test]
fn validate_ship_binstall_globalnever_isunused() {
let _reg = init_registry();
fake_install_self();
fake_publish("abc", "0.0.0");
write_user_config(&[
"[defaults]",
"ship.binstall = 'never'",
"[packages]",
"abc = { version = '*', registry = 'dummy-registry' }",
]);

cargo_liner()
.args(["ship", "--no-self"])
.assert()
.success()
.stdout_eq("".into_data().raw())
.stderr_eq(snapbox::file![
"fixtures/ship/validate_ship_binstall_globalnever_isunused.stderr"
]);
assert_installed("abc");
}

/// Test that the per-package configuration has precedence over the global one.
#[ignore = "cargo-binstall is not made available to CI yet."]
#[cargo_test]
fn validate_ship_binstall_globalnever_localalways_isused() {
let _reg = init_registry();
fake_install_self();
fake_publish("abc", "0.0.0");
write_user_config(&[
"[defaults]",
"ship.binstall = 'never'",
"[packages]",
"abc = { version = '*', binstall = 'always', registry = 'dummy-registry' }",
]);

cargo_liner()
.args(["ship", "--no-self"])
.assert()
.failure()
.stdout_eq("".into_data().raw())
// Same as above.
.stderr_eq(snapbox::file![
"fixtures/ship/validate_ship_binstall_globalalways_isused.stderr"
]);
assert_not_installed("abc");
}

/// Test that the per-package configuration has precedence over the global one.
#[ignore = "cargo-binstall is not made available to CI yet."]
#[cargo_test]
fn validate_ship_binstall_globalalways_localnever_isunused() {
let _reg = init_registry();
fake_install_self();
fake_publish("abc", "0.0.0");
write_user_config(&[
"[defaults]",
"ship.binstall = 'always'",
"[packages]",
"abc = { version = '*', binstall = 'never', registry = 'dummy-registry' }",
]);

cargo_liner()
.args(["ship", "--no-self"])
.assert()
.success()
.stdout_eq("".into_data().raw())
// Same as above.
.stderr_eq(snapbox::file![
"fixtures/ship/validate_ship_binstall_globalnever_isunused.stderr"
]);
assert_installed("abc");
}

0 comments on commit 2961c41

Please sign in to comment.