-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(replace): Partial-version spec support #12806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2fc644a
test(spec): Make room for more tests
epage 1bf12a5
test(spec): Cover meta/pre cases for partial versions
epage ae068fb
test(replace): Show behavior post-#12614
epage 0ec3274
fix(spec): Ensure PackageIdSpec respects version 'build' field
epage d318ed4
fix(spec): Require opt-in for pre-release
epage 7502318
fix(replace): Error, rather than assert, on version mismatch
epage 1e34066
test(replace): Clarify name for remaining new test
epage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,8 +176,7 @@ impl PackageIdSpec { | |
} | ||
|
||
if let Some(ref v) = self.version { | ||
let req = v.exact_req(); | ||
if !req.matches(package_id.version()) { | ||
if !v.matches(package_id.version()) { | ||
return false; | ||
} | ||
} | ||
|
@@ -444,15 +443,50 @@ mod tests { | |
fn matching() { | ||
let url = Url::parse("https://example.com").unwrap(); | ||
let sid = SourceId::for_registry(&url).unwrap(); | ||
let foo = PackageId::new("foo", "1.2.3", sid).unwrap(); | ||
let bar = PackageId::new("bar", "1.2.3", sid).unwrap(); | ||
|
||
let foo = PackageId::new("foo", "1.2.3", sid).unwrap(); | ||
assert!(PackageIdSpec::parse("foo").unwrap().matches(foo)); | ||
assert!(!PackageIdSpec::parse("foo").unwrap().matches(bar)); | ||
assert!(!PackageIdSpec::parse("bar").unwrap().matches(foo)); | ||
assert!(PackageIdSpec::parse("foo:1.2.3").unwrap().matches(foo)); | ||
assert!(!PackageIdSpec::parse("foo:1.2.2").unwrap().matches(foo)); | ||
assert!(PackageIdSpec::parse("[email protected]").unwrap().matches(foo)); | ||
assert!(!PackageIdSpec::parse("[email protected]").unwrap().matches(foo)); | ||
assert!(PackageIdSpec::parse("[email protected]").unwrap().matches(foo)); | ||
|
||
let meta = PackageId::new("meta", "1.2.3+hello", sid).unwrap(); | ||
assert!(PackageIdSpec::parse("meta").unwrap().matches(meta)); | ||
assert!(PackageIdSpec::parse("meta@1").unwrap().matches(meta)); | ||
assert!(PackageIdSpec::parse("[email protected]").unwrap().matches(meta)); | ||
assert!(PackageIdSpec::parse("[email protected]").unwrap().matches(meta)); | ||
assert!(!PackageIdSpec::parse("[email protected]") | ||
.unwrap() | ||
.matches(meta)); | ||
assert!(PackageIdSpec::parse("[email protected]+hello") | ||
.unwrap() | ||
.matches(meta)); | ||
assert!(!PackageIdSpec::parse("[email protected]+bye") | ||
.unwrap() | ||
.matches(meta)); | ||
|
||
let pre = PackageId::new("pre", "1.2.3-alpha.0", sid).unwrap(); | ||
assert!(PackageIdSpec::parse("pre").unwrap().matches(pre)); | ||
assert!(!PackageIdSpec::parse("pre@1").unwrap().matches(pre)); | ||
assert!(!PackageIdSpec::parse("[email protected]").unwrap().matches(pre)); | ||
assert!(!PackageIdSpec::parse("[email protected]").unwrap().matches(pre)); | ||
assert!(PackageIdSpec::parse("[email protected]") | ||
.unwrap() | ||
.matches(pre)); | ||
assert!(!PackageIdSpec::parse("[email protected]") | ||
.unwrap() | ||
.matches(pre)); | ||
assert!(!PackageIdSpec::parse("[email protected]") | ||
.unwrap() | ||
.matches(pre)); | ||
assert!(!PackageIdSpec::parse("[email protected]+hello") | ||
.unwrap() | ||
.matches(pre)); | ||
assert!(!PackageIdSpec::parse("[email protected]+hello") | ||
.unwrap() | ||
.matches(pre)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1298,3 +1298,157 @@ fn override_plus_dep() { | |
.with_stderr_contains("error: cyclic package dependency: [..]") | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn override_generic_matching_other_versions() { | ||
Package::new("bar", "0.1.0+a").publish(); | ||
|
||
let bar = git::repo(&paths::root().join("override")) | ||
.file("Cargo.toml", &basic_manifest("bar", "0.1.0")) | ||
.file("src/lib.rs", "pub fn bar() {}") | ||
.build(); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
&format!( | ||
r#" | ||
[package] | ||
name = "foo" | ||
version = "0.0.1" | ||
authors = [] | ||
|
||
[dependencies] | ||
bar = "0.1.0" | ||
|
||
[replace] | ||
"bar:0.1.0" = {{ git = '{}' }} | ||
"#, | ||
bar.url() | ||
), | ||
) | ||
.file( | ||
"src/lib.rs", | ||
"extern crate bar; pub fn foo() { bar::bar(); }", | ||
) | ||
.build(); | ||
|
||
p.cargo("check") | ||
.with_stderr( | ||
"\ | ||
[UPDATING] `dummy-registry` index | ||
[UPDATING] git repository `[..]` | ||
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..]/foo)` | ||
|
||
Caused by: | ||
replacement specification `https://github.com/rust-lang/crates.io-index#[email protected]` matched 0.1.0+a and tried to override it with 0.1.0 | ||
avoid matching unrelated packages by being more specific | ||
", | ||
) | ||
.with_status(101) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn override_respects_spec_metadata() { | ||
Package::new("bar", "0.1.0+a").publish(); | ||
|
||
let bar = git::repo(&paths::root().join("override")) | ||
.file("Cargo.toml", &basic_manifest("bar", "0.1.0+a")) | ||
.file("src/lib.rs", "pub fn bar() {}") | ||
.build(); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
&format!( | ||
r#" | ||
[package] | ||
name = "foo" | ||
version = "0.0.1" | ||
authors = [] | ||
|
||
[dependencies] | ||
bar = "0.1.0" | ||
|
||
[replace] | ||
"bar:0.1.0+notTheBuild" = {{ git = '{}' }} | ||
"#, | ||
bar.url() | ||
), | ||
) | ||
.file( | ||
"src/lib.rs", | ||
"extern crate bar; pub fn foo() { bar::bar(); }", | ||
) | ||
.build(); | ||
|
||
p.cargo("check") | ||
.with_stderr( | ||
"\ | ||
[UPDATING] `dummy-registry` index | ||
[WARNING] package replacement is not used: https://github.com/rust-lang/crates.io-index#[email protected]+notTheBuild | ||
[DOWNLOADING] crates ... | ||
[DOWNLOADED] bar v0.1.0+a (registry `dummy-registry`) | ||
[CHECKING] bar v0.1.0+a | ||
[CHECKING] foo v0.0.1 ([..]/foo) | ||
[..] | ||
[..] | ||
[..] | ||
[..] | ||
[..] | ||
[..] | ||
[..] | ||
error: could not compile `foo` (lib) due to previous error | ||
", | ||
) | ||
.with_status(101) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn override_spec_metadata_is_optional() { | ||
Package::new("bar", "0.1.0+a").publish(); | ||
|
||
let bar = git::repo(&paths::root().join("override")) | ||
.file("Cargo.toml", &basic_manifest("bar", "0.1.0+a")) | ||
.file("src/lib.rs", "pub fn bar() {}") | ||
.build(); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
&format!( | ||
r#" | ||
[package] | ||
name = "foo" | ||
version = "0.0.1" | ||
authors = [] | ||
|
||
[dependencies] | ||
bar = "0.1.0" | ||
|
||
[replace] | ||
"bar:0.1.0" = {{ git = '{}' }} | ||
"#, | ||
bar.url() | ||
), | ||
) | ||
.file( | ||
"src/lib.rs", | ||
"extern crate bar; pub fn foo() { bar::bar(); }", | ||
) | ||
.build(); | ||
|
||
p.cargo("check") | ||
.with_stderr( | ||
"\ | ||
[UPDATING] `dummy-registry` index | ||
[UPDATING] git repository `[..]` | ||
[CHECKING] bar v0.1.0+a (file://[..]) | ||
[CHECKING] foo v0.0.1 ([CWD]) | ||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] | ||
", | ||
) | ||
.run(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.