Skip to content

Commit 9e2c367

Browse files
authored
fix(add): Don't select yanked versions when normalizing names (#14895)
### 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
2 parents 0b3ad41 + 5df493e commit 9e2c367

File tree

50 files changed

+162
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+162
-7
lines changed

src/cargo/sources/registry/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,13 @@ impl<'gctx> Source for RegistrySource<'gctx> {
856856
}
857857
any_pending |= self
858858
.index
859-
.query_inner(name_permutation, &req, &mut *self.ops, f)?
859+
.query_inner(name_permutation, &req, &mut *self.ops, &mut |s| {
860+
if !s.is_yanked() {
861+
f(s);
862+
} else if kind == QueryKind::Alternatives {
863+
f(s);
864+
}
865+
})?
860866
.is_pending();
861867
}
862868
}

tests/testsuite/cargo_add/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ mod add_basic;
22
mod add_multiple;
33
mod add_no_vendored_package_with_alter_registry;
44
mod add_no_vendored_package_with_vendor;
5-
mod add_normalized_name_external;
65
mod add_toolchain;
7-
mod add_workspace_non_fuzzy;
86
mod build;
97
mod build_prefer_existing_version;
108
mod change_rename_target;
@@ -14,7 +12,6 @@ mod deprecated_default_features;
1412
mod deprecated_section;
1513
mod detect_workspace_inherit;
1614
mod detect_workspace_inherit_features;
17-
mod detect_workspace_inherit_fuzzy;
1815
mod detect_workspace_inherit_optional;
1916
mod detect_workspace_inherit_path_base;
2017
mod detect_workspace_inherit_public;
@@ -28,7 +25,6 @@ mod features;
2825
mod features_activated_over_limit;
2926
mod features_deactivated_over_limit;
3027
mod features_empty;
31-
mod features_fuzzy;
3228
mod features_multiple_occurrences;
3329
mod features_preserve;
3430
mod features_spaced_values;
@@ -42,7 +38,6 @@ mod git_inferred_name;
4238
mod git_inferred_name_multiple;
4339
mod git_multiple_names;
4440
mod git_multiple_packages_features;
45-
mod git_normalized_name;
4641
mod git_registry;
4742
mod git_rev;
4843
mod git_tag;
@@ -75,6 +70,13 @@ mod no_args;
7570
mod no_default_features;
7671
mod no_optional;
7772
mod no_public;
73+
mod normalize_name_git;
74+
mod normalize_name_path;
75+
mod normalize_name_path_existing;
76+
mod normalize_name_registry;
77+
mod normalize_name_registry_existing;
78+
mod normalize_name_registry_yanked;
79+
mod normalize_name_workspace_dep;
7880
mod offline_empty_cache;
7981
mod optional;
8082
mod overwrite_default_features;
@@ -118,7 +120,6 @@ mod path_base_unstable;
118120
mod path_dev;
119121
mod path_inferred_name;
120122
mod path_inferred_name_conflicts_full_feature;
121-
mod path_normalized_name;
122123
mod preserve_dep_std_table;
123124
mod preserve_features_sorted;
124125
mod preserve_features_table;
@@ -149,3 +150,4 @@ mod vers;
149150
mod workspace_name;
150151
mod workspace_path;
151152
mod workspace_path_dev;
153+
mod yanked;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../add-basic.in
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use cargo_test_support::compare::assert_ui;
2+
use cargo_test_support::current_dir;
3+
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
5+
use cargo_test_support::str;
6+
use cargo_test_support::Project;
7+
8+
#[cargo_test]
9+
fn case() {
10+
cargo_test_support::registry::init();
11+
cargo_test_support::registry::Package::new("linked-hash-map", "0.5.0").publish();
12+
cargo_test_support::registry::Package::new("linked-hash-map", "0.5.4").publish();
13+
cargo_test_support::registry::Package::new("linked-hash-map", "0.6.0")
14+
.yanked(true)
15+
.publish();
16+
17+
let project = Project::from_template(current_dir!().join("in"));
18+
let project_root = project.root();
19+
let cwd = &project_root;
20+
21+
snapbox::cmd::Command::cargo_ui()
22+
.arg("add")
23+
.arg_line("linked_hash_map")
24+
.current_dir(cwd)
25+
.assert()
26+
.success()
27+
.stdout_eq(str![""])
28+
.stderr_eq(file!["stderr.term.svg"]);
29+
30+
assert_ui().subset_matches(current_dir!().join("out"), &project_root);
31+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"
6+
edition = "2015"
7+
8+
[dependencies]
9+
linked-hash-map = "0.5.4"
Lines changed: 34 additions & 0 deletions

tests/testsuite/cargo_add/yanked/in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../add-basic.in
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use cargo_test_support::compare::assert_ui;
2+
use cargo_test_support::current_dir;
3+
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
5+
use cargo_test_support::str;
6+
use cargo_test_support::Project;
7+
8+
#[cargo_test]
9+
fn case() {
10+
cargo_test_support::registry::init();
11+
cargo_test_support::registry::Package::new("linked-hash-map", "0.5.0").publish();
12+
cargo_test_support::registry::Package::new("linked-hash-map", "0.5.4").publish();
13+
cargo_test_support::registry::Package::new("linked-hash-map", "0.6.0")
14+
.yanked(true)
15+
.publish();
16+
17+
let project = Project::from_template(current_dir!().join("in"));
18+
let project_root = project.root();
19+
let cwd = &project_root;
20+
21+
snapbox::cmd::Command::cargo_ui()
22+
.arg("add")
23+
.arg_line("linked-hash-map")
24+
.current_dir(cwd)
25+
.assert()
26+
.success()
27+
.stdout_eq(str![""])
28+
.stderr_eq(file!["stderr.term.svg"]);
29+
30+
assert_ui().subset_matches(current_dir!().join("out"), &project_root);
31+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"
6+
edition = "2015"
7+
8+
[dependencies]
9+
linked-hash-map = "0.5.4"
Lines changed: 31 additions & 0 deletions

0 commit comments

Comments
 (0)