diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index 83695507983..01f49e32ff8 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -158,44 +158,32 @@ fn rust_version_bad_nonsense() { } #[cargo_test] -fn rust_version_too_high() { - let p = project() +fn rust_version_older_than_edition() { + project() .file( "Cargo.toml", r#" [package] name = "foo" version = "0.0.1" - edition = "2015" authors = [] - rust-version = "1.9876.0" + rust-version = "1.1" + edition = "2018" [[bin]] name = "foo" "#, ) .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("check") + .build() + .cargo("check") .with_status(101) - .with_stderr( - "\ -[ERROR] rustc [..] is not supported by the following package: - foo@0.0.1 requires rustc 1.9876.0 - -", + .with_stderr_contains(" rust-version 1.1 is older than first version (1.31.0) required by the specified edition (2018)", ) .run(); - p.cargo("check --ignore-rust-version").run(); } #[cargo_test] -fn dependency_rust_version_newer_than_rustc() { - Package::new("bar", "0.0.1") - .rust_version("1.2345.0") - .file("src/lib.rs", "fn other_stuff() {}") - .publish(); - +fn lint_self_incompatible_with_rust_version() { let p = project() .file( "Cargo.toml", @@ -205,26 +193,20 @@ fn dependency_rust_version_newer_than_rustc() { version = "0.0.1" edition = "2015" authors = [] - [dependencies] - bar = "0.0.1" + rust-version = "1.9876.0" + [[bin]] + name = "foo" "#, ) - .file("src/main.rs", "fn main(){}") + .file("src/main.rs", "fn main() {}") .build(); p.cargo("check") .with_status(101) .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 [..] + foo@0.0.1 requires rustc 1.9876.0 ", ) @@ -233,16 +215,20 @@ where `` is the latest version supporting rustc [..] } #[cargo_test] -fn dependency_tree_rust_version_newer_than_rustc() { - Package::new("baz", "0.0.1") - .dep("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("bar", "0.0.1") + 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( @@ -252,26 +238,35 @@ fn dependency_tree_rust_version_newer_than_rustc() { name = "foo" version = "0.0.1" edition = "2015" + rust-version = "1.50" authors = [] [dependencies] - baz = "0.0.1" + too_new_parent = "0.0.1" + rustc_compatible = "0.0.1" "#, ) .file("src/main.rs", "fn main(){}") .build(); + p.cargo("generate-lockfile") + .with_stderr( + "\ +[UPDATING] `[..]` index +[LOCKING] 4 packages to latest compatible versions +", + ) + .run(); 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 [..] @@ -283,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(); @@ -337,34 +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 --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] 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 compatible versions ", ) .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") .masquerade_as_nightly_cargo(&["msrv-policy"]) .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(); @@ -372,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(); @@ -390,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(){}") @@ -403,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() {}") @@ -444,6 +453,7 @@ fn dependency_rust_version_backtracking() { edition = "2015" authors = [] rust-version = "1.60.0" + [dependencies] no-rust-version = "2" "#, @@ -451,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(); @@ -507,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() {}") @@ -521,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() {}") @@ -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 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(); @@ -678,26 +705,90 @@ See https://github.com/rust-lang/cargo/issues/9930 for more information about th } #[cargo_test] -fn rust_version_older_than_edition() { - project() +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.1" - edition = "2018" - [[bin]] - name = "foo" + rust-version = "1.60.0" + + [dependencies] + only-newer = "1.0.0" + newer-and-older = "1.0.0" "#, ) - .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)", + .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(); }