Skip to content

Commit

Permalink
fix(add): Don't select yanked versions when normalizing names (#14895)
Browse files Browse the repository at this point in the history
### What does this PR try to resolve?

Fixes #14893

In writing a test for this, I had a hard time finding the other tests as
they mixed
- Having an `add_` prefix
- Calling this fuzzy vs normalized

So I made the test names consistent

### How should we test and review this PR?

### Additional information
  • Loading branch information
weihanglo authored Dec 5, 2024
2 parents 0b3ad41 + 5df493e commit 9e2c367
Show file tree
Hide file tree
Showing 50 changed files with 162 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,13 @@ impl<'gctx> Source for RegistrySource<'gctx> {
}
any_pending |= self
.index
.query_inner(name_permutation, &req, &mut *self.ops, f)?
.query_inner(name_permutation, &req, &mut *self.ops, &mut |s| {
if !s.is_yanked() {
f(s);
} else if kind == QueryKind::Alternatives {
f(s);
}
})?
.is_pending();
}
}
Expand Down
14 changes: 8 additions & 6 deletions tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ mod add_basic;
mod add_multiple;
mod add_no_vendored_package_with_alter_registry;
mod add_no_vendored_package_with_vendor;
mod add_normalized_name_external;
mod add_toolchain;
mod add_workspace_non_fuzzy;
mod build;
mod build_prefer_existing_version;
mod change_rename_target;
Expand All @@ -14,7 +12,6 @@ mod deprecated_default_features;
mod deprecated_section;
mod detect_workspace_inherit;
mod detect_workspace_inherit_features;
mod detect_workspace_inherit_fuzzy;
mod detect_workspace_inherit_optional;
mod detect_workspace_inherit_path_base;
mod detect_workspace_inherit_public;
Expand All @@ -28,7 +25,6 @@ mod features;
mod features_activated_over_limit;
mod features_deactivated_over_limit;
mod features_empty;
mod features_fuzzy;
mod features_multiple_occurrences;
mod features_preserve;
mod features_spaced_values;
Expand All @@ -42,7 +38,6 @@ mod git_inferred_name;
mod git_inferred_name_multiple;
mod git_multiple_names;
mod git_multiple_packages_features;
mod git_normalized_name;
mod git_registry;
mod git_rev;
mod git_tag;
Expand Down Expand Up @@ -75,6 +70,13 @@ mod no_args;
mod no_default_features;
mod no_optional;
mod no_public;
mod normalize_name_git;
mod normalize_name_path;
mod normalize_name_path_existing;
mod normalize_name_registry;
mod normalize_name_registry_existing;
mod normalize_name_registry_yanked;
mod normalize_name_workspace_dep;
mod offline_empty_cache;
mod optional;
mod overwrite_default_features;
Expand Down Expand Up @@ -118,7 +120,6 @@ mod path_base_unstable;
mod path_dev;
mod path_inferred_name;
mod path_inferred_name_conflicts_full_feature;
mod path_normalized_name;
mod preserve_dep_std_table;
mod preserve_features_sorted;
mod preserve_features_table;
Expand Down Expand Up @@ -149,3 +150,4 @@ mod vers;
mod workspace_name;
mod workspace_path;
mod workspace_path_dev;
mod yanked;
31 changes: 31 additions & 0 deletions tests/testsuite/cargo_add/normalize_name_registry_yanked/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;
use cargo_test_support::prelude::*;
use cargo_test_support::str;
use cargo_test_support::Project;

#[cargo_test]
fn case() {
cargo_test_support::registry::init();
cargo_test_support::registry::Package::new("linked-hash-map", "0.5.0").publish();
cargo_test_support::registry::Package::new("linked-hash-map", "0.5.4").publish();
cargo_test_support::registry::Package::new("linked-hash-map", "0.6.0")
.yanked(true)
.publish();

let project = Project::from_template(current_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("linked_hash_map")
.current_dir(cwd)
.assert()
.success()
.stdout_eq(str![""])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
edition = "2015"

[dependencies]
linked-hash-map = "0.5.4"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/yanked/in
31 changes: 31 additions & 0 deletions tests/testsuite/cargo_add/yanked/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;
use cargo_test_support::prelude::*;
use cargo_test_support::str;
use cargo_test_support::Project;

#[cargo_test]
fn case() {
cargo_test_support::registry::init();
cargo_test_support::registry::Package::new("linked-hash-map", "0.5.0").publish();
cargo_test_support::registry::Package::new("linked-hash-map", "0.5.4").publish();
cargo_test_support::registry::Package::new("linked-hash-map", "0.6.0")
.yanked(true)
.publish();

let project = Project::from_template(current_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("linked-hash-map")
.current_dir(cwd)
.assert()
.success()
.stdout_eq(str![""])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
9 changes: 9 additions & 0 deletions tests/testsuite/cargo_add/yanked/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
edition = "2015"

[dependencies]
linked-hash-map = "0.5.4"
31 changes: 31 additions & 0 deletions tests/testsuite/cargo_add/yanked/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9e2c367

Please sign in to comment.