From c4c7f9fcf91d6c30303e452754384d4175cc0274 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Mon, 11 Dec 2023 11:18:19 +0800 Subject: [PATCH 1/2] test: add a case for inspect the unpublished workspace package Signed-off-by: hi-rustin --- tests/testsuite/cargo_information/mod.rs | 1 + .../in/Cargo.lock | 16 ++++++++++++ .../in/Cargo.toml | 8 ++++++ .../in/src/lib.rs | 1 + .../within_ws_and_pick_ws_package/mod.rs | 26 +++++++++++++++++++ .../out/Cargo.lock | 16 ++++++++++++ .../out/Cargo.toml | 8 ++++++ .../out/src/lib.rs | 1 + .../within_ws_and_pick_ws_package/stderr.log | 3 +++ .../within_ws_and_pick_ws_package/stdout.log | 0 10 files changed, 80 insertions(+) create mode 100644 tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/Cargo.lock create mode 100644 tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/Cargo.toml create mode 100644 tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/src/lib.rs create mode 100644 tests/testsuite/cargo_information/within_ws_and_pick_ws_package/mod.rs create mode 100644 tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/Cargo.lock create mode 100644 tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/Cargo.toml create mode 100644 tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/src/lib.rs create mode 100644 tests/testsuite/cargo_information/within_ws_and_pick_ws_package/stderr.log create mode 100644 tests/testsuite/cargo_information/within_ws_and_pick_ws_package/stdout.log diff --git a/tests/testsuite/cargo_information/mod.rs b/tests/testsuite/cargo_information/mod.rs index 44cb3e8..ffb47a5 100644 --- a/tests/testsuite/cargo_information/mod.rs +++ b/tests/testsuite/cargo_information/mod.rs @@ -17,6 +17,7 @@ mod with_locked_within_ws; mod with_offline; mod with_quiet; mod within_ws; +mod within_ws_and_pick_ws_package; mod within_ws_with_alternative_registry; // Invoke `cargo-info info` with the test environment. diff --git a/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/Cargo.lock b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/Cargo.lock new file mode 100644 index 0000000..cf3fed8 --- /dev/null +++ b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cargo-list-test-fixture" +version = "0.2.0" +dependencies = [ + "my-package", +] + +[[package]] +name = "my-package" +version = "0.1.1+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61758fedb08b81e9c6967f0661a54feb83fb38eb4bde3614119fbc1d03c1cedf" diff --git a/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/Cargo.toml b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/Cargo.toml new file mode 100644 index 0000000..443359c --- /dev/null +++ b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.2.0" + +[dependencies] +my-package = "0.1" diff --git a/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/src/lib.rs b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/src/lib.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/in/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/mod.rs b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/mod.rs new file mode 100644 index 0000000..79e291e --- /dev/null +++ b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/mod.rs @@ -0,0 +1,26 @@ +use cargo_test_macro::cargo_test; +use cargo_test_support::{compare::assert_ui, curr_dir, Project}; + +use super::{cargo_info, init_registry_without_token}; + +#[cargo_test] +fn case() { + init_registry_without_token(); + cargo_test_support::registry::Package::new("my-package", "0.1.1+my-package").publish(); + cargo_test_support::registry::Package::new("cargo-list-test-fixture", "0.1.1+my-package") + .publish(); + + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + cargo_info() + .arg("cargo-list-test-fixture") + .current_dir(cwd) + .assert() + .failure() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/Cargo.lock b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/Cargo.lock new file mode 100644 index 0000000..cf3fed8 --- /dev/null +++ b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cargo-list-test-fixture" +version = "0.2.0" +dependencies = [ + "my-package", +] + +[[package]] +name = "my-package" +version = "0.1.1+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61758fedb08b81e9c6967f0661a54feb83fb38eb4bde3614119fbc1d03c1cedf" diff --git a/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/Cargo.toml b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/Cargo.toml new file mode 100644 index 0000000..443359c --- /dev/null +++ b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.2.0" + +[dependencies] +my-package = "0.1" diff --git a/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/src/lib.rs b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/src/lib.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/out/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/stderr.log b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/stderr.log new file mode 100644 index 0000000..e1dd0e5 --- /dev/null +++ b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/stderr.log @@ -0,0 +1,3 @@ +thread 'main' panicked at /Users/hi-rustin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-0.75.1/src/cargo/sources/registry/mod.rs:463:9: +assertion failed: source_id.is_remote_registry() +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/stdout.log b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/stdout.log new file mode 100644 index 0000000..e69de29 From babad221ae8f4dbe8be964ef750e5581999b4dcb Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Mon, 11 Dec 2023 11:26:09 +0800 Subject: [PATCH 2/2] fix: bail out an error for non remote registry Signed-off-by: hi-rustin --- src/ops/info.rs | 4 ++++ .../within_ws_and_pick_ws_package/stderr.log | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ops/info.rs b/src/ops/info.rs index 152afee..0a57fce 100644 --- a/src/ops/info.rs +++ b/src/ops/info.rs @@ -46,6 +46,10 @@ pub fn info( package_id = None; } + if !source_ids.original.is_remote_registry() { + anyhow::bail!("`cargo info` command currently only supports remote registry"); + } + query_and_pretty_view(spec, package_id, config, registry, source_ids) } diff --git a/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/stderr.log b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/stderr.log index e1dd0e5..b5b9890 100644 --- a/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/stderr.log +++ b/tests/testsuite/cargo_information/within_ws_and_pick_ws_package/stderr.log @@ -1,3 +1 @@ -thread 'main' panicked at /Users/hi-rustin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-0.75.1/src/cargo/sources/registry/mod.rs:463:9: -assertion failed: source_id.is_remote_registry() -note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace +error: `cargo info` command currently only supports remote registry