Skip to content
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

test(install): Verify 2024 edition / resolver=3 doesn't affect resolution #14724

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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