From 04f84e461b3c862fcf43e476004da24f88727867 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 16 Apr 2024 16:44:11 -0500 Subject: [PATCH 1/3] test(msrv): Group bad rust-version tests --- tests/testsuite/rust_version.rs | 50 ++++++++++++++++----------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index 83695507983..09f9697f003 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -157,6 +157,31 @@ fn rust_version_bad_nonsense() { .run(); } +#[cargo_test] +fn rust_version_older_than_edition() { + project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + rust-version = "1.1" + edition = "2018" + [[bin]] + name = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build() + .cargo("check") + .with_status(101) + .with_stderr_contains(" rust-version 1.1 is older than first version (1.31.0) required by the specified edition (2018)", + ) + .run(); +} + #[cargo_test] fn rust_version_too_high() { let p = project() @@ -676,28 +701,3 @@ See https://github.com/rust-lang/cargo/issues/9930 for more information about th ) .run(); } - -#[cargo_test] -fn rust_version_older_than_edition() { - project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - rust-version = "1.1" - edition = "2018" - [[bin]] - name = "foo" - "#, - ) - .file("src/main.rs", "fn main() {}") - .build() - .cargo("check") - .with_status(101) - .with_stderr_contains(" rust-version 1.1 is older than first version (1.31.0) required by the specified edition (2018)", - ) - .run(); -} From d6643254b577051f661b804aaa70702994c917e6 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 16 Apr 2024 16:32:08 -0500 Subject: [PATCH 2/3] test(msrv): Show regular MSRV resolve case --- tests/testsuite/rust_version.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index 09f9697f003..d94c0742e72 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -369,26 +369,35 @@ fn dependency_rust_version_older_and_newer_than_package() { .file("src/main.rs", "fn main(){}") .build(); - p.cargo("check --ignore-rust-version") + p.cargo("check") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr( "\ [UPDATING] `dummy-registry` index -[LOCKING] 2 packages to latest compatible versions +[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions +[ADDING] bar v1.5.0 (latest: v1.6.0) [DOWNLOADING] crates ... -[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`) -[CHECKING] bar v1.6.0 +[DOWNLOADED] bar v1.5.0 (registry `dummy-registry`) +[CHECKING] bar v1.5.0 [CHECKING] [..] [FINISHED] [..] ", ) .run(); - p.cargo("check") + + std::fs::remove_file(p.root().join("Cargo.lock")).unwrap(); + p.cargo("check --ignore-rust-version") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr( "\ +[UPDATING] `dummy-registry` index +[LOCKING] 2 packages to latest compatible versions +[DOWNLOADING] crates ... +[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`) +[CHECKING] bar v1.6.0 +[CHECKING] [..] [FINISHED] [..] ", ) From 3a3dda38d96006b07afab3a9b3eb9ee56dacf87f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 16 Apr 2024 16:42:44 -0500 Subject: [PATCH 3/3] test(msrv): Reorganize MSRV tests - Merge test cases - Clarify names - Focus on `cargo tree`, rather than `cargo check` (faster and more to what we are testing) --- tests/testsuite/rust_version.rs | 398 +++++++++++++++++++------------- 1 file changed, 240 insertions(+), 158 deletions(-) diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index d94c0742e72..01f49e32ff8 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -183,7 +183,7 @@ fn rust_version_older_than_edition() { } #[cargo_test] -fn rust_version_too_high() { +fn lint_self_incompatible_with_rust_version() { let p = project() .file( "Cargo.toml", @@ -215,11 +215,20 @@ fn rust_version_too_high() { } #[cargo_test] -fn dependency_rust_version_newer_than_rustc() { - Package::new("bar", "0.0.1") +fn lint_dep_incompatible_with_rust_version() { + Package::new("too_new_parent", "0.0.1") + .dep("too_new_child", "0.0.1") .rust_version("1.2345.0") .file("src/lib.rs", "fn other_stuff() {}") .publish(); + Package::new("too_new_child", "0.0.1") + .rust_version("1.2345.0") + .file("src/lib.rs", "fn other_stuff() {}") + .publish(); + Package::new("rustc_compatible", "0.0.1") + .rust_version("1.60.0") + .file("src/lib.rs", "fn other_stuff() {}") + .publish(); let p = project() .file( @@ -229,74 +238,35 @@ fn dependency_rust_version_newer_than_rustc() { name = "foo" version = "0.0.1" edition = "2015" + rust-version = "1.50" authors = [] [dependencies] - bar = "0.0.1" + too_new_parent = "0.0.1" + rustc_compatible = "0.0.1" "#, ) .file("src/main.rs", "fn main(){}") .build(); - p.cargo("check") - .with_status(101) + p.cargo("generate-lockfile") .with_stderr( "\ [UPDATING] `[..]` index -[LOCKING] 2 packages to latest compatible versions -[DOWNLOADING] crates ... -[DOWNLOADED] bar v0.0.1 (registry `[..]`) -[ERROR] rustc [..] is not supported by the following package: - bar@0.0.1 requires rustc 1.2345.0 -Either upgrade rustc or select compatible dependency versions with -`cargo update @ --precise ` -where `` is the latest version supporting rustc [..] - +[LOCKING] 4 packages to latest compatible versions ", ) .run(); - p.cargo("check --ignore-rust-version").run(); -} - -#[cargo_test] -fn dependency_tree_rust_version_newer_than_rustc() { - Package::new("baz", "0.0.1") - .dep("bar", "0.0.1") - .rust_version("1.2345.0") - .file("src/lib.rs", "fn other_stuff() {}") - .publish(); - Package::new("bar", "0.0.1") - .rust_version("1.2345.0") - .file("src/lib.rs", "fn other_stuff() {}") - .publish(); - - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - edition = "2015" - authors = [] - [dependencies] - baz = "0.0.1" - "#, - ) - .file("src/main.rs", "fn main(){}") - .build(); - p.cargo("check") .with_status(101) .with_stderr( "\ -[UPDATING] `[..]` index -[LOCKING] 3 packages to latest compatible versions [DOWNLOADING] crates ... -[DOWNLOADED] baz v0.0.1 (registry `[..]`) -[DOWNLOADED] bar v0.0.1 (registry `[..]`) +[DOWNLOADED] too_new_parent v0.0.1 (registry `[..]`) +[DOWNLOADED] too_new_child v0.0.1 (registry `[..]`) +[DOWNLOADED] rustc_compatible v0.0.1 (registry `[..]`) [ERROR] rustc [..] is not supported by the following packages: - bar@0.0.1 requires rustc 1.2345.0 - baz@0.0.1 requires rustc 1.2345.0 + too_new_child@0.0.1 requires rustc 1.2345.0 + too_new_parent@0.0.1 requires rustc 1.2345.0 Either upgrade rustc or select compatible dependency versions with `cargo update @ --precise ` where `` is the latest version supporting rustc [..] @@ -308,46 +278,16 @@ where `` is the latest version supporting rustc [..] } #[cargo_test] -fn dependency_rust_version_newer_than_package() { - Package::new("bar", "1.6.0") +fn resolve_with_rust_version() { + Package::new("only-newer", "1.6.0") .rust_version("1.65.0") .file("src/lib.rs", "fn other_stuff() {}") .publish(); - - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - edition = "2015" - authors = [] - rust-version = "1.60.0" - [dependencies] - bar = "1.0.0" - "#, - ) - .file("src/main.rs", "fn main(){}") - .build(); - - p.cargo("check") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) - .run(); - p.cargo("check --ignore-rust-version") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) - .run(); -} - -#[cargo_test] -fn dependency_rust_version_older_and_newer_than_package() { - Package::new("bar", "1.5.0") + Package::new("newer-and-older", "1.5.0") .rust_version("1.55.0") .file("src/lib.rs", "fn other_stuff() {}") .publish(); - Package::new("bar", "1.6.0") + Package::new("newer-and-older", "1.6.0") .rust_version("1.65.0") .file("src/lib.rs", "fn other_stuff() {}") .publish(); @@ -362,43 +302,52 @@ fn dependency_rust_version_older_and_newer_than_package() { edition = "2015" authors = [] rust-version = "1.60.0" + [dependencies] - bar = "1.0.0" + only-newer = "1.0.0" + newer-and-older = "1.0.0" "#, ) .file("src/main.rs", "fn main(){}") .build(); - p.cargo("check") + p.cargo("generate-lockfile --ignore-rust-version") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr( "\ [UPDATING] `dummy-registry` index -[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions -[ADDING] bar v1.5.0 (latest: v1.6.0) -[DOWNLOADING] crates ... -[DOWNLOADED] bar v1.5.0 (registry `dummy-registry`) -[CHECKING] bar v1.5.0 -[CHECKING] [..] -[FINISHED] [..] +[LOCKING] 3 packages to latest compatible versions +", + ) + .run(); + p.cargo("tree") + .with_stdout( + "\ +foo v0.0.1 ([CWD]) +├── newer-and-older v1.6.0 +└── only-newer v1.6.0 ", ) .run(); - std::fs::remove_file(p.root().join("Cargo.lock")).unwrap(); - p.cargo("check --ignore-rust-version") + p.cargo("generate-lockfile") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr( "\ [UPDATING] `dummy-registry` index -[LOCKING] 2 packages to latest compatible versions -[DOWNLOADING] crates ... -[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`) -[CHECKING] bar v1.6.0 -[CHECKING] [..] -[FINISHED] [..] +[LOCKING] 3 packages to latest Rust 1.60.0 compatible versions +[ADDING] newer-and-older v1.5.0 (latest: v1.6.0) +", + ) + .run(); + p.cargo("tree") + .with_stdout( + "\ +foo v0.0.1 ([CWD]) +├── newer-and-older v1.5.0 +└── only-newer v1.6.0 ", ) .run(); @@ -406,11 +355,15 @@ fn dependency_rust_version_older_and_newer_than_package() { #[cargo_test] fn resolve_with_rustc() { - Package::new("bar", "1.5.0") - .rust_version("1.0") + Package::new("only-newer", "1.6.0") + .rust_version("1.2345") .file("src/lib.rs", "fn other_stuff() {}") .publish(); - Package::new("bar", "1.6.0") + Package::new("newer-and-older", "1.5.0") + .rust_version("1.55.0") + .file("src/lib.rs", "fn other_stuff() {}") + .publish(); + Package::new("newer-and-older", "1.6.0") .rust_version("1.2345") .file("src/lib.rs", "fn other_stuff() {}") .publish(); @@ -424,8 +377,11 @@ fn resolve_with_rustc() { version = "0.0.1" edition = "2015" authors = [] + rust-version = "1.60.0" + [dependencies] - bar = "1.0.0" + only-newer = "1.0.0" + newer-and-older = "1.0.0" "#, ) .file("src/main.rs", "fn main(){}") @@ -437,25 +393,44 @@ fn resolve_with_rustc() { .with_stderr( "\ [UPDATING] `dummy-registry` index -[LOCKING] 2 packages to latest compatible versions +[LOCKING] 3 packages to latest compatible versions +", + ) + .run(); + p.cargo("tree") + .with_stdout( + "\ +foo v0.0.1 ([CWD]) +├── newer-and-older v1.6.0 +└── only-newer v1.6.0 ", ) .run(); + p.cargo("generate-lockfile") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr( "\ [UPDATING] `dummy-registry` index -[LOCKING] 2 packages to latest Rust [..] compatible versions -[ADDING] bar v1.5.0 (latest: v1.6.0) +[LOCKING] 3 packages to latest Rust [..] compatible versions +[ADDING] newer-and-older v1.5.0 (latest: v1.6.0) +", + ) + .run(); + p.cargo("tree") + .with_stdout( + "\ +foo v0.0.1 ([CWD]) +├── newer-and-older v1.5.0 +└── only-newer v1.6.0 ", ) .run(); } #[cargo_test] -fn dependency_rust_version_backtracking() { +fn resolve_with_backtracking() { Package::new("has-rust-version", "1.6.0") .rust_version("1.65.0") .file("src/lib.rs", "fn other_stuff() {}") @@ -478,6 +453,7 @@ fn dependency_rust_version_backtracking() { edition = "2015" authors = [] rust-version = "1.60.0" + [dependencies] no-rust-version = "2" "#, @@ -485,45 +461,63 @@ fn dependency_rust_version_backtracking() { .file("src/main.rs", "fn main(){}") .build(); - p.cargo("check --ignore-rust-version") + p.cargo("generate-lockfile --ignore-rust-version") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr( "\ [UPDATING] `dummy-registry` index [LOCKING] 3 packages to latest compatible versions -[DOWNLOADING] crates ... -[DOWNLOADED] no-rust-version v2.2.0 (registry `dummy-registry`) -[DOWNLOADED] has-rust-version v1.6.0 (registry `dummy-registry`) -[CHECKING] has-rust-version v1.6.0 -[CHECKING] no-rust-version v2.2.0 -[CHECKING] [..] -[FINISHED] [..] ", ) .run(); - p.cargo("check") + p.cargo("tree") + .with_stdout( + "\ +foo v0.0.1 ([CWD]) +└── no-rust-version v2.2.0 + └── has-rust-version v1.6.0 +", + ) + .run(); + + // Ideally we'd pick `has-rust-version` 1.6.0 which requires backtracking + p.cargo("generate-lockfile") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr( "\ -[FINISHED] [..] +[UPDATING] `dummy-registry` index +[LOCKING] 3 packages to latest Rust 1.60.0 compatible versions +", + ) + .run(); + p.cargo("tree") + .with_stdout( + "\ +foo v0.0.1 ([CWD]) +└── no-rust-version v2.2.0 + └── has-rust-version v1.6.0 ", ) .run(); } #[cargo_test] -fn workspace_with_mixed_rust_version() { - Package::new("bar", "1.4.0") +fn resolve_with_multiple_rust_versions() { + Package::new("only-newer", "1.6.0") + .rust_version("1.65.0") + .file("src/lib.rs", "fn other_stuff() {}") + .publish(); + Package::new("newer-and-older", "1.5.0") .rust_version("1.45.0") .file("src/lib.rs", "fn other_stuff() {}") .publish(); - Package::new("bar", "1.5.0") + Package::new("newer-and-older", "1.5.1") .rust_version("1.55.0") .file("src/lib.rs", "fn other_stuff() {}") .publish(); - Package::new("bar", "1.6.0") + Package::new("newer-and-older", "1.6.0") .rust_version("1.65.0") .file("src/lib.rs", "fn other_stuff() {}") .publish(); @@ -541,8 +535,10 @@ fn workspace_with_mixed_rust_version() { edition = "2015" authors = [] rust-version = "1.60.0" + [dependencies] - bar = "1.0.0" + only-newer = "1.0.0" + newer-and-older = "1.0.0" "#, ) .file("src/main.rs", "fn main() {}") @@ -555,41 +551,59 @@ fn workspace_with_mixed_rust_version() { edition = "2015" authors = [] rust-version = "1.50.0" + [dependencies] - bar = "1.0.0" + only-newer = "1.0.0" + newer-and-older = "1.0.0" "#, ) .file("lower/src/main.rs", "fn main() {}") .build(); - p.cargo("check --ignore-rust-version") + p.cargo("generate-lockfile --ignore-rust-version") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr( "\ [UPDATING] `dummy-registry` index -[LOCKING] 3 packages to latest compatible versions -[DOWNLOADING] crates ... -[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`) -[CHECKING] bar v1.6.0 -[CHECKING] [..] -[FINISHED] [..] +[LOCKING] 4 packages to latest compatible versions ", ) .run(); - p.cargo("check") + p.cargo("tree") + .with_stdout( + "\ +higher v0.0.1 ([CWD]) +├── newer-and-older v1.6.0 +└── only-newer v1.6.0 +", + ) + .run(); + + p.cargo("generate-lockfile") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr( "\ -[FINISHED] [..] +[UPDATING] `dummy-registry` index +[LOCKING] 4 packages to latest Rust 1.50.0 compatible versions +[ADDING] newer-and-older v1.5.0 (latest: v1.6.0) +", + ) + .run(); + p.cargo("tree") + .with_stdout( + "\ +higher v0.0.1 ([CWD]) +├── newer-and-older v1.5.0 +└── only-newer v1.6.0 ", ) .run(); } #[cargo_test] -fn generate_lockfile_msrv_resolve() { +fn generate_lockfile_ignore_rust_version_is_unstable() { Package::new("bar", "1.5.0") .rust_version("1.55.0") .file("src/lib.rs", "fn other_stuff() {}") @@ -623,27 +637,6 @@ fn generate_lockfile_msrv_resolve() { [ERROR] the `--ignore-rust-version` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels. See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag. -", - ) - .run(); - p.cargo("generate-lockfile --ignore-rust-version") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) - .with_stderr( - "\ -[UPDATING] `dummy-registry` index -[LOCKING] 2 packages to latest compatible versions -", - ) - .run(); - p.cargo("generate-lockfile") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) - .with_stderr( - "\ -[UPDATING] `dummy-registry` index -[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions -[ADDING] bar v1.5.0 (latest: v1.6.0) ", ) .run(); @@ -710,3 +703,92 @@ See https://github.com/rust-lang/cargo/issues/9930 for more information about th ) .run(); } + +#[cargo_test] +fn check_msrv_resolve() { + Package::new("only-newer", "1.6.0") + .rust_version("1.65.0") + .file("src/lib.rs", "fn other_stuff() {}") + .publish(); + Package::new("newer-and-older", "1.5.0") + .rust_version("1.55.0") + .file("src/lib.rs", "fn other_stuff() {}") + .publish(); + Package::new("newer-and-older", "1.6.0") + .rust_version("1.65.0") + .file("src/lib.rs", "fn other_stuff() {}") + .publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + authors = [] + rust-version = "1.60.0" + + [dependencies] + only-newer = "1.0.0" + newer-and-older = "1.0.0" + "#, + ) + .file("src/main.rs", "fn main(){}") + .build(); + + p.cargo("check --ignore-rust-version") + .arg("-Zmsrv-policy") + .masquerade_as_nightly_cargo(&["msrv-policy"]) + .with_stderr( + "\ +[UPDATING] `dummy-registry` index +[LOCKING] 3 packages to latest compatible versions +[DOWNLOADING] crates ... +[DOWNLOADED] [..] +[DOWNLOADED] [..] +[CHECKING] [..] +[CHECKING] [..] +[CHECKING] foo [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +", + ) + .run(); + p.cargo("tree") + .with_stdout( + "\ +foo v0.0.1 ([CWD]) +├── newer-and-older v1.6.0 +└── only-newer v1.6.0 +", + ) + .run(); + + std::fs::remove_file(p.root().join("Cargo.lock")).unwrap(); + p.cargo("check") + .arg("-Zmsrv-policy") + .masquerade_as_nightly_cargo(&["msrv-policy"]) + .with_stderr( + "\ +[UPDATING] `dummy-registry` index +[LOCKING] 3 packages to latest Rust 1.60.0 compatible versions +[ADDING] newer-and-older v1.5.0 (latest: v1.6.0) +[DOWNLOADING] crates ... +[DOWNLOADED] [..] +[CHECKING] [..] +[CHECKING] foo [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +", + ) + .run(); + p.cargo("tree") + .with_stdout( + "\ +foo v0.0.1 ([CWD]) +├── newer-and-older v1.5.0 +└── only-newer v1.6.0 +", + ) + .run(); +}