From 2961c417eda75a6af01ae17688f6ed5449eb54e9 Mon Sep 17 00:00:00 2001 From: Paul Mabileau Date: Mon, 23 Dec 2024 22:45:37 +0100 Subject: [PATCH] Test(ship): Add coverage for binstall As part of #16. Signed-off-by: Paul Mabileau --- ...e_ship_binstall_globalalways_isused.stderr | 34 ++++++ ..._ship_binstall_globalnever_isunused.stderr | 27 +++++ tests/ship.rs | 110 ++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 tests/fixtures/ship/validate_ship_binstall_globalalways_isused.stderr create mode 100644 tests/fixtures/ship/validate_ship_binstall_globalnever_isunused.stderr diff --git a/tests/fixtures/ship/validate_ship_binstall_globalalways_isused.stderr b/tests/fixtures/ship/validate_ship_binstall_globalalways_isused.stderr new file mode 100644 index 0000000..ded7366 --- /dev/null +++ b/tests/fixtures/ship/validate_ship_binstall_globalalways_isused.stderr @@ -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 ` + 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. diff --git a/tests/fixtures/ship/validate_ship_binstall_globalnever_isunused.stderr b/tests/fixtures/ship/validate_ship_binstall_globalnever_isunused.stderr new file mode 100644 index 0000000..aec6142 --- /dev/null +++ b/tests/fixtures/ship/validate_ship_binstall_globalnever_isunused.stderr @@ -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 ` + 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. diff --git a/tests/ship.rs b/tests/ship.rs index 68a261a..4ce1510 100644 --- a/tests/ship.rs +++ b/tests/ship.rs @@ -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"); +}