From 941c414a901140969707c8e7b5c6656992db684f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 21 Mar 2025 06:59:29 -0700 Subject: [PATCH] Add test for cached report id --- tests/testsuite/future_incompat_report.rs | 121 ++++++++++++++++++++-- 1 file changed, 113 insertions(+), 8 deletions(-) diff --git a/tests/testsuite/future_incompat_report.rs b/tests/testsuite/future_incompat_report.rs index bb4e6dbec..ac8a86471 100644 --- a/tests/testsuite/future_incompat_report.rs +++ b/tests/testsuite/future_incompat_report.rs @@ -15,14 +15,47 @@ use super::config::write_config_toml; // An arbitrary lint (unused_variables) that triggers a lint. // We use a special flag to force it to generate a report. -const FUTURE_EXAMPLE: &'static str = "fn main() { let x = 1; }"; +const FUTURE_EXAMPLE: &'static str = "pub fn foo() { let x = 1; }"; // Some text that will be displayed when the lint fires. const FUTURE_OUTPUT: &'static str = "[..]unused variable[..]"; -fn simple_project() -> Project { +/// A project with a future-incompat error in the local package. +fn local_project() -> Project { project() .file("Cargo.toml", &basic_manifest("foo", "0.0.0")) - .file("src/main.rs", FUTURE_EXAMPLE) + .file("src/lib.rs", FUTURE_EXAMPLE) + .build() +} + +/// A project with a future-incompat error in a dependency. +fn dependency_project() -> Project { + Package::new("bar", "1.0.0") + .file( + "Cargo.toml", + r#" + [package] + name = "bar" + version = "1.0.0" + edition = "2015" + repository = "https://example.com/" + "#, + ) + .file("src/lib.rs", FUTURE_EXAMPLE) + .publish(); + project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "1.0.0" + edition = "2015" + + [dependencies] + bar = "1.0" + "#, + ) + .file("src/lib.rs", "") .build() } @@ -31,7 +64,7 @@ fn simple_project() -> Project { reason = "-Zfuture-incompat-test requires nightly (permanently)" )] fn output_on_stable() { - let p = simple_project(); + let p = local_project(); p.cargo("check") .env("RUSTFLAGS", "-Zfuture-incompat-test") @@ -48,7 +81,7 @@ fn output_on_stable() { // This feature is stable, and should not be gated #[cargo_test] fn no_gate_future_incompat_report() { - let p = simple_project(); + let p = local_project(); p.cargo("check --future-incompat-report") .with_status(0) @@ -98,7 +131,7 @@ fn test_zero_future_incompat() { reason = "-Zfuture-incompat-test requires nightly (permanently)" )] fn test_single_crate() { - let p = simple_project(); + let p = local_project(); for command in &["build", "check", "rustc", "test"] { let check_has_future_compat = || { @@ -315,7 +348,7 @@ The package `second-dep v0.0.2` currently triggers the following future incompat reason = "-Zfuture-incompat-test requires nightly (permanently)" )] fn color() { - let p = simple_project(); + let p = local_project(); p.cargo("check") .env("RUSTFLAGS", "-Zfuture-incompat-test") @@ -337,7 +370,7 @@ fn color() { reason = "-Zfuture-incompat-test requires nightly (permanently)" )] fn bad_ids() { - let p = simple_project(); + let p = local_project(); p.cargo("report future-incompatibilities --id 1") .with_status(101) @@ -451,3 +484,75 @@ with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3. "#]]) .run(); } + +#[cargo_test( + nightly, + reason = "-Zfuture-incompat-test requires nightly (permanently)" +)] +fn correct_report_id_when_cached() { + // Checks for a bug where the `--id` value was off-by-one when the report + // is already cached. + let p = dependency_project(); + + p.cargo("check --future-incompat-report") + .env("RUSTFLAGS", "-Zfuture-incompat-test") + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[LOCKING] 1 package to latest compatible version +[DOWNLOADING] crates ... +[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) +[CHECKING] bar v1.0.0 +[CHECKING] foo v1.0.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[WARNING] the following packages contain code that will be rejected by a future version of Rust: bar v1.0.0 +[NOTE] +To solve this problem, you can try the following approaches: + + +- If the issue is not solved by updating the dependencies, a fix has to be +implemented by those dependencies. You can help with that by notifying the +maintainers of this problem (e.g. by creating a bug report) or by proposing a +fix to the maintainers (e.g. by creating a pull request): + + - bar@1.0.0 + - Repository: https://example.com/ + - Detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0` + +- If waiting for an upstream fix is not an option, you can use the `[patch]` +section in `Cargo.toml` to use your own version of the dependency. For more +information, see: +https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section + +[NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` + +"#]]) + .run(); + + p.cargo("check --future-incompat-report") + .env("RUSTFLAGS", "-Zfuture-incompat-test") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[WARNING] the following packages contain code that will be rejected by a future version of Rust: bar v1.0.0 +[NOTE] +To solve this problem, you can try the following approaches: + + +- If the issue is not solved by updating the dependencies, a fix has to be +implemented by those dependencies. You can help with that by notifying the +maintainers of this problem (e.g. by creating a bug report) or by proposing a +fix to the maintainers (e.g. by creating a pull request): + + - bar@1.0.0 + - Repository: https://example.com/ + - Detailed warning command: `cargo report future-incompatibilities --id 2 --package bar@1.0.0` + +- If waiting for an upstream fix is not an option, you can use the `[patch]` +section in `Cargo.toml` to use your own version of the dependency. For more +information, see: +https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section + +[NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` + +"#]]) + .run(); +}