Skip to content

Commit

Permalink
Auto merge of #14724 - epage:resolver, r=weihanglo
Browse files Browse the repository at this point in the history
test(install): Verify 2024 edition / resolver=3 doesn't affect resolution

### What does this PR try to resolve?

I was worried there might be bugs related to this.  With this out of the way, I think we'll be ready to stabilize `resolver = "3"`.

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

### Additional information
  • Loading branch information
bors committed Oct 25, 2024
2 parents 8315873 + 487bbc8 commit 28274d0
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
26 changes: 25 additions & 1 deletion crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ pub struct Package {
local: bool,
alternative: bool,
invalid_json: bool,
edition: Option<String>,
resolver: Option<String>,
proc_macro: bool,
links: Option<String>,
rust_version: Option<String>,
Expand Down Expand Up @@ -1250,6 +1252,8 @@ impl Package {
local: false,
alternative: false,
invalid_json: false,
edition: None,
resolver: None,
proc_macro: false,
links: None,
rust_version: None,
Expand Down Expand Up @@ -1385,6 +1389,18 @@ impl Package {
self
}

/// Specifies `package.edition`
pub fn edition(&mut self, edition: &str) -> &mut Package {
self.edition = Some(edition.to_owned());
self
}

/// Specifies `package.resolver`
pub fn resolver(&mut self, resolver: &str) -> &mut Package {
self.resolver = Some(resolver.to_owned());
self
}

/// Specifies whether or not this is a proc macro.
pub fn proc_macro(&mut self, proc_macro: bool) -> &mut Package {
self.proc_macro = proc_macro;
Expand Down Expand Up @@ -1570,7 +1586,15 @@ impl Package {
));

if let Some(version) = &self.rust_version {
manifest.push_str(&format!("rust-version = \"{}\"", version));
manifest.push_str(&format!("rust-version = \"{}\"\n", version));
}

if let Some(edition) = &self.edition {
manifest.push_str(&format!("edition = \"{}\"\n", edition));
}

if let Some(resolver) = &self.resolver {
manifest.push_str(&format!("resolver = \"{}\"\n", resolver));
}

if !self.features.is_empty() {
Expand Down
80 changes: 80 additions & 0 deletions tests/testsuite/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,86 @@ fn cargo_install_ignores_msrv_config() {
.run();
}

#[cargo_test(nightly, reason = "edition2024 in rustc is unstable")]
fn cargo_install_ignores_resolver_v3_msrv_change() {
Package::new("dep", "1.0.0")
.rust_version("1.50")
.file("src/lib.rs", "fn hello() {}")
.publish();
Package::new("dep", "1.1.0")
.rust_version("1.70")
.file("src/lib.rs", "fn hello() {}")
.publish();
Package::new("foo", "0.0.1")
.rust_version("1.60")
.cargo_feature("edition2024")
.resolver("3")
.file("src/main.rs", "fn main() {}")
.dep("dep", "1")
.publish();

cargo_process("install foo")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["edition2024", "msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[DOWNLOADING] crates ...
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
[INSTALLING] foo v0.0.1
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] dep v1.1.0 (registry `dummy-registry`)
[COMPILING] dep v1.1.0
[COMPILING] foo v0.0.1
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
"#]])
.run();
}

#[cargo_test(nightly, reason = "edition2024 in rustc is unstable")]
fn cargo_install_ignores_edition_2024_msrv_change() {
Package::new("dep", "1.0.0")
.rust_version("1.50")
.file("src/lib.rs", "fn hello() {}")
.publish();
Package::new("dep", "1.1.0")
.rust_version("1.70")
.file("src/lib.rs", "fn hello() {}")
.publish();
Package::new("foo", "0.0.1")
.rust_version("1.60")
.cargo_feature("edition2024")
.edition("2024")
.file("src/main.rs", "fn main() {}")
.dep("dep", "1")
.publish();

cargo_process("install foo")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["edition2024", "msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[DOWNLOADING] crates ...
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
[INSTALLING] foo v0.0.1
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] dep v1.1.0 (registry `dummy-registry`)
[COMPILING] dep v1.1.0
[COMPILING] foo v0.0.1
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
"#]])
.run();
}

#[cargo_test]
fn report_rust_versions() {
Package::new("dep-only-low-compatible", "1.55.0")
Expand Down

0 comments on commit 28274d0

Please sign in to comment.