From 255f62229964d7b433726441012e8cacccd87837 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 23 Oct 2024 14:53:46 -0500 Subject: [PATCH 1/4] feat(test): Allow setting resolver on published packages --- crates/cargo-test-support/src/registry.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/cargo-test-support/src/registry.rs b/crates/cargo-test-support/src/registry.rs index 9e0bc9e3ed9..18a719a6a6f 100644 --- a/crates/cargo-test-support/src/registry.rs +++ b/crates/cargo-test-support/src/registry.rs @@ -571,6 +571,7 @@ pub struct Package { local: bool, alternative: bool, invalid_json: bool, + resolver: Option, proc_macro: bool, links: Option, rust_version: Option, @@ -1250,6 +1251,7 @@ impl Package { local: false, alternative: false, invalid_json: false, + resolver: None, proc_macro: false, links: None, rust_version: None, @@ -1385,6 +1387,12 @@ impl Package { 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; @@ -1570,7 +1578,11 @@ 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(resolver) = &self.resolver { + manifest.push_str(&format!("resolver = \"{}\"\n", resolver)); } if !self.features.is_empty() { From 646e29abb50678e83b3db303715fe9e9d87731e4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 23 Oct 2024 15:14:02 -0500 Subject: [PATCH 2/4] feat(test): Allow setting edition on published packages --- crates/cargo-test-support/src/registry.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/cargo-test-support/src/registry.rs b/crates/cargo-test-support/src/registry.rs index 18a719a6a6f..207cf74a6ec 100644 --- a/crates/cargo-test-support/src/registry.rs +++ b/crates/cargo-test-support/src/registry.rs @@ -571,6 +571,7 @@ pub struct Package { local: bool, alternative: bool, invalid_json: bool, + edition: Option, resolver: Option, proc_macro: bool, links: Option, @@ -1251,6 +1252,7 @@ impl Package { local: false, alternative: false, invalid_json: false, + edition: None, resolver: None, proc_macro: false, links: None, @@ -1387,6 +1389,12 @@ 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()); @@ -1581,6 +1589,10 @@ impl Package { 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)); } From 49f096edaf2e3597427c7ba8084464204c4baa79 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 23 Oct 2024 15:13:06 -0500 Subject: [PATCH 3/4] test(install): Verify resolver=3 is ignored --- tests/testsuite/rust_version.rs | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index 98aae8d2593..d96dbc2c92a 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -958,6 +958,46 @@ 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] fn report_rust_versions() { Package::new("dep-only-low-compatible", "1.55.0") From 487bbc813fd116ae3d284dfe2f78063c99cadc1f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 23 Oct 2024 15:15:02 -0500 Subject: [PATCH 4/4] test(install): Verify edition=2024 is ignored --- tests/testsuite/rust_version.rs | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index d96dbc2c92a..41423714d73 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -998,6 +998,46 @@ fn cargo_install_ignores_resolver_v3_msrv_change() { .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")