Auto merge of #13767 - epage:msrv-test, r=ehuss

test(msrv): Re-organize MSRV tests

### What does this PR try to resolve?

- Merge test cases
- Clarify names
- Focus on `cargo tree`, rather than `cargo check` (faster and more to
  what we are testing)

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

### Additional information
This commit is contained in:
bors 2024-04-17 15:32:37 +00:00
commit 852a31615d

View File

@ -158,7 +158,32 @@ fn rust_version_bad_nonsense() {
} }
#[cargo_test] #[cargo_test]
fn rust_version_too_high() { 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 lint_self_incompatible_with_rust_version() {
let p = project() let p = project()
.file( .file(
"Cargo.toml", "Cargo.toml",
@ -190,11 +215,20 @@ fn rust_version_too_high() {
} }
#[cargo_test] #[cargo_test]
fn dependency_rust_version_newer_than_rustc() { fn lint_dep_incompatible_with_rust_version() {
Package::new("bar", "0.0.1") Package::new("too_new_parent", "0.0.1")
.dep("too_new_child", "0.0.1")
.rust_version("1.2345.0") .rust_version("1.2345.0")
.file("src/lib.rs", "fn other_stuff() {}") .file("src/lib.rs", "fn other_stuff() {}")
.publish(); .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() let p = project()
.file( .file(
@ -204,74 +238,35 @@ fn dependency_rust_version_newer_than_rustc() {
name = "foo" name = "foo"
version = "0.0.1" version = "0.0.1"
edition = "2015" edition = "2015"
rust-version = "1.50"
authors = [] authors = []
[dependencies] [dependencies]
bar = "0.0.1" too_new_parent = "0.0.1"
rustc_compatible = "0.0.1"
"#, "#,
) )
.file("src/main.rs", "fn main(){}") .file("src/main.rs", "fn main(){}")
.build(); .build();
p.cargo("check") p.cargo("generate-lockfile")
.with_status(101)
.with_stderr( .with_stderr(
"\ "\
[UPDATING] `[..]` index [UPDATING] `[..]` index
[LOCKING] 2 packages to latest compatible versions [LOCKING] 4 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 <name>@<current-ver> --precise <compatible-ver>`
where `<compatible-ver>` is the latest version supporting rustc [..]
", ",
) )
.run(); .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") p.cargo("check")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr(
"\ "\
[UPDATING] `[..]` index
[LOCKING] 3 packages to latest compatible versions
[DOWNLOADING] crates ... [DOWNLOADING] crates ...
[DOWNLOADED] baz v0.0.1 (registry `[..]`) [DOWNLOADED] too_new_parent v0.0.1 (registry `[..]`)
[DOWNLOADED] bar 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: [ERROR] rustc [..] is not supported by the following packages:
bar@0.0.1 requires rustc 1.2345.0 too_new_child@0.0.1 requires rustc 1.2345.0
baz@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 Either upgrade rustc or select compatible dependency versions with
`cargo update <name>@<current-ver> --precise <compatible-ver>` `cargo update <name>@<current-ver> --precise <compatible-ver>`
where `<compatible-ver>` is the latest version supporting rustc [..] where `<compatible-ver>` is the latest version supporting rustc [..]
@ -283,46 +278,16 @@ where `<compatible-ver>` is the latest version supporting rustc [..]
} }
#[cargo_test] #[cargo_test]
fn dependency_rust_version_newer_than_package() { fn resolve_with_rust_version() {
Package::new("bar", "1.6.0") Package::new("only-newer", "1.6.0")
.rust_version("1.65.0") .rust_version("1.65.0")
.file("src/lib.rs", "fn other_stuff() {}") .file("src/lib.rs", "fn other_stuff() {}")
.publish(); .publish();
Package::new("newer-and-older", "1.5.0")
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")
.rust_version("1.55.0") .rust_version("1.55.0")
.file("src/lib.rs", "fn other_stuff() {}") .file("src/lib.rs", "fn other_stuff() {}")
.publish(); .publish();
Package::new("bar", "1.6.0") Package::new("newer-and-older", "1.6.0")
.rust_version("1.65.0") .rust_version("1.65.0")
.file("src/lib.rs", "fn other_stuff() {}") .file("src/lib.rs", "fn other_stuff() {}")
.publish(); .publish();
@ -337,34 +302,52 @@ fn dependency_rust_version_older_and_newer_than_package() {
edition = "2015" edition = "2015"
authors = [] authors = []
rust-version = "1.60.0" rust-version = "1.60.0"
[dependencies] [dependencies]
bar = "1.0.0" only-newer = "1.0.0"
newer-and-older = "1.0.0"
"#, "#,
) )
.file("src/main.rs", "fn main(){}") .file("src/main.rs", "fn main(){}")
.build(); .build();
p.cargo("check --ignore-rust-version") p.cargo("generate-lockfile --ignore-rust-version")
.arg("-Zmsrv-policy") .arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"]) .masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr( .with_stderr(
"\ "\
[UPDATING] `dummy-registry` index [UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions [LOCKING] 3 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`)
[CHECKING] bar v1.6.0
[CHECKING] [..]
[FINISHED] [..]
", ",
) )
.run(); .run();
p.cargo("check") 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") .arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"]) .masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr( .with_stderr(
"\ "\
[FINISHED] [..] [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)
",
)
.run();
p.cargo("tree")
.with_stdout(
"\
foo v0.0.1 ([CWD])
newer-and-older v1.5.0
only-newer v1.6.0
", ",
) )
.run(); .run();
@ -372,11 +355,15 @@ fn dependency_rust_version_older_and_newer_than_package() {
#[cargo_test] #[cargo_test]
fn resolve_with_rustc() { fn resolve_with_rustc() {
Package::new("bar", "1.5.0") Package::new("only-newer", "1.6.0")
.rust_version("1.0") .rust_version("1.2345")
.file("src/lib.rs", "fn other_stuff() {}") .file("src/lib.rs", "fn other_stuff() {}")
.publish(); .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") .rust_version("1.2345")
.file("src/lib.rs", "fn other_stuff() {}") .file("src/lib.rs", "fn other_stuff() {}")
.publish(); .publish();
@ -390,8 +377,11 @@ fn resolve_with_rustc() {
version = "0.0.1" version = "0.0.1"
edition = "2015" edition = "2015"
authors = [] authors = []
rust-version = "1.60.0"
[dependencies] [dependencies]
bar = "1.0.0" only-newer = "1.0.0"
newer-and-older = "1.0.0"
"#, "#,
) )
.file("src/main.rs", "fn main(){}") .file("src/main.rs", "fn main(){}")
@ -403,25 +393,44 @@ fn resolve_with_rustc() {
.with_stderr( .with_stderr(
"\ "\
[UPDATING] `dummy-registry` index [UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions [LOCKING] 3 packages to latest compatible versions
", ",
) )
.run(); .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") p.cargo("generate-lockfile")
.arg("-Zmsrv-policy") .arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"]) .masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr( .with_stderr(
"\ "\
[UPDATING] `dummy-registry` index [UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest Rust [..] compatible versions [LOCKING] 3 packages to latest Rust [..] compatible versions
[ADDING] bar v1.5.0 (latest: v1.6.0) [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(); .run();
} }
#[cargo_test] #[cargo_test]
fn dependency_rust_version_backtracking() { fn resolve_with_backtracking() {
Package::new("has-rust-version", "1.6.0") Package::new("has-rust-version", "1.6.0")
.rust_version("1.65.0") .rust_version("1.65.0")
.file("src/lib.rs", "fn other_stuff() {}") .file("src/lib.rs", "fn other_stuff() {}")
@ -444,6 +453,7 @@ fn dependency_rust_version_backtracking() {
edition = "2015" edition = "2015"
authors = [] authors = []
rust-version = "1.60.0" rust-version = "1.60.0"
[dependencies] [dependencies]
no-rust-version = "2" no-rust-version = "2"
"#, "#,
@ -451,45 +461,63 @@ fn dependency_rust_version_backtracking() {
.file("src/main.rs", "fn main(){}") .file("src/main.rs", "fn main(){}")
.build(); .build();
p.cargo("check --ignore-rust-version") p.cargo("generate-lockfile --ignore-rust-version")
.arg("-Zmsrv-policy") .arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"]) .masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr( .with_stderr(
"\ "\
[UPDATING] `dummy-registry` index [UPDATING] `dummy-registry` index
[LOCKING] 3 packages to latest compatible versions [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(); .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") .arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"]) .masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr( .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(); .run();
} }
#[cargo_test] #[cargo_test]
fn workspace_with_mixed_rust_version() { fn resolve_with_multiple_rust_versions() {
Package::new("bar", "1.4.0") 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") .rust_version("1.45.0")
.file("src/lib.rs", "fn other_stuff() {}") .file("src/lib.rs", "fn other_stuff() {}")
.publish(); .publish();
Package::new("bar", "1.5.0") Package::new("newer-and-older", "1.5.1")
.rust_version("1.55.0") .rust_version("1.55.0")
.file("src/lib.rs", "fn other_stuff() {}") .file("src/lib.rs", "fn other_stuff() {}")
.publish(); .publish();
Package::new("bar", "1.6.0") Package::new("newer-and-older", "1.6.0")
.rust_version("1.65.0") .rust_version("1.65.0")
.file("src/lib.rs", "fn other_stuff() {}") .file("src/lib.rs", "fn other_stuff() {}")
.publish(); .publish();
@ -507,8 +535,10 @@ fn workspace_with_mixed_rust_version() {
edition = "2015" edition = "2015"
authors = [] authors = []
rust-version = "1.60.0" rust-version = "1.60.0"
[dependencies] [dependencies]
bar = "1.0.0" only-newer = "1.0.0"
newer-and-older = "1.0.0"
"#, "#,
) )
.file("src/main.rs", "fn main() {}") .file("src/main.rs", "fn main() {}")
@ -521,41 +551,59 @@ fn workspace_with_mixed_rust_version() {
edition = "2015" edition = "2015"
authors = [] authors = []
rust-version = "1.50.0" rust-version = "1.50.0"
[dependencies] [dependencies]
bar = "1.0.0" only-newer = "1.0.0"
newer-and-older = "1.0.0"
"#, "#,
) )
.file("lower/src/main.rs", "fn main() {}") .file("lower/src/main.rs", "fn main() {}")
.build(); .build();
p.cargo("check --ignore-rust-version") p.cargo("generate-lockfile --ignore-rust-version")
.arg("-Zmsrv-policy") .arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"]) .masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr( .with_stderr(
"\ "\
[UPDATING] `dummy-registry` index [UPDATING] `dummy-registry` index
[LOCKING] 3 packages to latest compatible versions [LOCKING] 4 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`)
[CHECKING] bar v1.6.0
[CHECKING] [..]
[FINISHED] [..]
", ",
) )
.run(); .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") .arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"]) .masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr( .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(); .run();
} }
#[cargo_test] #[cargo_test]
fn generate_lockfile_msrv_resolve() { fn generate_lockfile_ignore_rust_version_is_unstable() {
Package::new("bar", "1.5.0") Package::new("bar", "1.5.0")
.rust_version("1.55.0") .rust_version("1.55.0")
.file("src/lib.rs", "fn other_stuff() {}") .file("src/lib.rs", "fn other_stuff() {}")
@ -589,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 [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://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. 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(); .run();
@ -678,26 +705,90 @@ See https://github.com/rust-lang/cargo/issues/9930 for more information about th
} }
#[cargo_test] #[cargo_test]
fn rust_version_older_than_edition() { fn check_msrv_resolve() {
project() 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( .file(
"Cargo.toml", "Cargo.toml",
r#" r#"
[package] [package]
name = "foo" name = "foo"
version = "0.0.1" version = "0.0.1"
edition = "2015"
authors = [] authors = []
rust-version = "1.1" rust-version = "1.60.0"
edition = "2018"
[[bin]] [dependencies]
name = "foo" only-newer = "1.0.0"
newer-and-older = "1.0.0"
"#, "#,
) )
.file("src/main.rs", "fn main(){}") .file("src/main.rs", "fn main(){}")
.build() .build();
.cargo("check")
.with_status(101) p.cargo("check --ignore-rust-version")
.with_stderr_contains(" rust-version 1.1 is older than first version (1.31.0) required by the specified edition (2018)", .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(); .run();
} }