Skip to content

Commit 03705aa

Browse files
committed
Add tests to ensure this issue is fixed
Added QueryKind::Normalized, and used it in cargo-add Rename Fuzzy to Alternatives Optimize the tests, use in/ to generate templates update tests since the snapbox upgrade
1 parent e7ff7a6 commit 03705aa

File tree

28 files changed

+134
-10
lines changed

28 files changed

+134
-10
lines changed

crates/resolver-tests/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ pub fn resolve_with_config_raw(
112112
for summary in self.list.iter() {
113113
let matched = match kind {
114114
QueryKind::Exact => dep.matches(summary),
115-
QueryKind::Fuzzy => true,
115+
QueryKind::Alternatives => true,
116+
QueryKind::Normalized => true,
116117
};
117118
if matched {
118119
self.used.insert(summary.package_id());

src/cargo/core/resolver/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ pub(super) fn activation_error(
305305
// Maybe the user mistyped the name? Like `dep-thing` when `Dep_Thing`
306306
// was meant. So we try asking the registry for a `fuzzy` search for suggestions.
307307
let candidates = loop {
308-
match registry.query_vec(&new_dep, QueryKind::Fuzzy) {
308+
match registry.query_vec(&new_dep, QueryKind::Alternatives) {
309309
Poll::Ready(Ok(candidates)) => break candidates,
310310
Poll::Ready(Err(e)) => return to_resolve_err(e),
311311
Poll::Pending => match registry.block_until_ready() {

src/cargo/ops/cargo_add/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ fn get_latest_dependency(
588588
}
589589
MaybeWorkspace::Other(query) => {
590590
let possibilities = loop {
591-
match registry.query_vec(&query, QueryKind::Fuzzy) {
591+
match registry.query_vec(&query, QueryKind::Normalized) {
592592
std::task::Poll::Ready(res) => {
593593
break res?;
594594
}
@@ -711,7 +711,7 @@ fn select_package(
711711
MaybeWorkspace::Other(query) => {
712712
let possibilities = loop {
713713
// Exact to avoid returning all for path/git
714-
match registry.query_vec(&query, QueryKind::Exact) {
714+
match registry.query_vec(&query, QueryKind::Normalized) {
715715
std::task::Poll::Ready(res) => {
716716
break res?;
717717
}
@@ -938,7 +938,7 @@ fn populate_available_features(
938938
}
939939

940940
let possibilities = loop {
941-
match registry.query_vec(&query, QueryKind::Exact) {
941+
match registry.query_vec(&query, QueryKind::Normalized) {
942942
std::task::Poll::Ready(res) => {
943943
break res?;
944944
}

src/cargo/sources/directory.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ impl<'cfg> Source for DirectorySource<'cfg> {
108108
let packages = self.packages.values().map(|p| &p.0);
109109
let matches = packages.filter(|pkg| match kind {
110110
QueryKind::Exact => dep.matches(pkg.summary()),
111-
QueryKind::Fuzzy => true,
111+
QueryKind::Alternatives => true,
112+
QueryKind::Normalized => dep.matches(pkg.summary()),
112113
});
113114
for summary in matches.map(|pkg| pkg.summary().clone()) {
114115
f(IndexSummary::Candidate(summary));

src/cargo/sources/path.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ impl<'cfg> Source for PathSource<'cfg> {
554554
for s in self.packages.iter().map(|p| p.summary()) {
555555
let matched = match kind {
556556
QueryKind::Exact => dep.matches(s),
557-
QueryKind::Fuzzy => true,
557+
QueryKind::Alternatives => true,
558+
QueryKind::Normalized => dep.matches(s),
558559
};
559560
if matched {
560561
f(IndexSummary::Candidate(s.clone()))

src/cargo/sources/registry/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,8 @@ impl<'cfg> Source for RegistrySource<'cfg> {
792792
.query_inner(dep.package_name(), &req, &mut *self.ops, &mut |s| {
793793
let matched = match kind {
794794
QueryKind::Exact => dep.matches(s.as_summary()),
795-
QueryKind::Fuzzy => true,
795+
QueryKind::Alternatives => true,
796+
QueryKind::Normalized => true,
796797
};
797798
if !matched {
798799
return;
@@ -831,7 +832,7 @@ impl<'cfg> Source for RegistrySource<'cfg> {
831832
return Poll::Ready(Ok(()));
832833
}
833834
let mut any_pending = false;
834-
if kind == QueryKind::Fuzzy {
835+
if kind == QueryKind::Alternatives || kind == QueryKind::Normalized {
835836
// Attempt to handle misspellings by searching for a chain of related
836837
// names to the original name. The resolver will later
837838
// reject any candidates that have the wrong name, and with this it'll

src/cargo/sources/source.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ pub enum QueryKind {
179179
/// Path/Git sources may return all dependencies that are at that URI,
180180
/// whereas an `Registry` source may return dependencies that have the same
181181
/// canonicalization.
182-
Fuzzy,
182+
Alternatives,
183+
/// Match a denpendency in all ways and will normalize the package name.
184+
/// Each source defines what normalizing means.
185+
Normalized,
183186
}
184187

185188
/// A download status that represents if a [`Package`] has already been
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[source.crates-io]
2+
replace-with = "vendored-sources"
3+
4+
[source.vendored-sources]
5+
directory = "./vendor"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"

tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/src/lib.rs

Whitespace-only changes.

0 commit comments

Comments
 (0)