Auto merge of #14173 - eth3lbert:snapbox-f, r=weihanglo

test: mirgate fix* and future_incompat_report to snapbox

### What does this PR try to resolve?

Part of https://github.com/rust-lang/cargo/issues/14039.

Migrate following to snapbox:

- `tests/testsuite/fix.rs`
- `tests/testsuite/fix_n_times.rs`
- `tests/testsuite/future_incompat_report.rs`
This commit is contained in:
bors 2024-07-02 16:20:49 +00:00
commit bff8a08165
3 changed files with 513 additions and 371 deletions

File diff suppressed because it is too large Load Diff

View File

@ -14,9 +14,8 @@
//! The [`expect_fix_runs_rustc_n_times`] function handles setting everything //! The [`expect_fix_runs_rustc_n_times`] function handles setting everything
//! up, and verifying the results. //! up, and verifying the results.
#![allow(deprecated)] use cargo_test_support::{basic_manifest, paths, project, str, tools, Execs};
use snapbox::data::Inline;
use cargo_test_support::{basic_manifest, paths, project, tools, Execs};
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::{Mutex, OnceLock}; use std::sync::{Mutex, OnceLock};
@ -60,7 +59,7 @@ enum Step {
fn expect_fix_runs_rustc_n_times( fn expect_fix_runs_rustc_n_times(
sequence: &[Step], sequence: &[Step],
extra_execs: impl FnOnce(&mut Execs), extra_execs: impl FnOnce(&mut Execs),
expected_stderr: &str, expected_stderr: Inline,
expected_lib_rs: &str, expected_lib_rs: &str,
) { ) {
let rustc = rustc_for_cargo_fix(); let rustc = rustc_for_cargo_fix();
@ -73,7 +72,7 @@ fn expect_fix_runs_rustc_n_times(
execs execs
.env("RUSTC", &rustc) .env("RUSTC", &rustc)
.env("RUSTC_FIX_SHIM_SEQUENCE", sequence_str) .env("RUSTC_FIX_SHIM_SEQUENCE", sequence_str)
.with_stderr(expected_stderr); .with_stderr_data(expected_stderr);
extra_execs(&mut execs); extra_execs(&mut execs);
execs.run(); execs.run();
let lib_rs = p.read_file("src/lib.rs"); let lib_rs = p.read_file("src/lib.rs");
@ -270,10 +269,11 @@ fn fix_no_suggestions() {
expect_fix_runs_rustc_n_times( expect_fix_runs_rustc_n_times(
&[Step::SuccessNoOutput], &[Step::SuccessNoOutput],
|_execs| {}, |_execs| {},
"\ str![[r#"
[CHECKING] foo [..] [CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
"#]],
"// fix-count 0", "// fix-count 0",
); );
} }
@ -284,11 +284,12 @@ fn fix_one_suggestion() {
expect_fix_runs_rustc_n_times( expect_fix_runs_rustc_n_times(
&[Step::OneFix, Step::SuccessNoOutput], &[Step::OneFix, Step::SuccessNoOutput],
|_execs| {}, |_execs| {},
"\ str![[r#"
[CHECKING] foo [..] [CHECKING] foo v0.0.1 ([ROOT]/foo)
[FIXED] src/lib.rs (1 fix) [FIXED] src/lib.rs (1 fix)
[FINISHED] [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
"#]],
"// fix-count 1", "// fix-count 1",
); );
} }
@ -299,11 +300,12 @@ fn fix_one_overlapping() {
expect_fix_runs_rustc_n_times( expect_fix_runs_rustc_n_times(
&[Step::TwoFixOverlapping, Step::SuccessNoOutput], &[Step::TwoFixOverlapping, Step::SuccessNoOutput],
|_execs| {}, |_execs| {},
"\ str![[r#"
[CHECKING] foo [..] [CHECKING] foo v0.0.1 ([ROOT]/foo)
[FIXED] src/lib.rs (1 fix) [FIXED] src/lib.rs (1 fix)
[FINISHED] [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
"#]],
"// fix-count 2", "// fix-count 2",
); );
} }
@ -321,9 +323,9 @@ fn fix_overlapping_max() {
Step::TwoFixOverlapping, Step::TwoFixOverlapping,
], ],
|_execs| {}, |_execs| {},
"\ str![[r#"
[CHECKING] foo [..] [CHECKING] foo v0.0.1 ([ROOT]/foo)
warning: error applying suggestions to `src/lib.rs` [WARNING] error applying suggestions to `src/lib.rs`
The full error message was: The full error message was:
@ -341,9 +343,10 @@ fixing code with the `--broken-code` flag
[FIXED] src/lib.rs (4 fixes) [FIXED] src/lib.rs (4 fixes)
rustc fix shim comment 5 rustc fix shim comment 5
rustc fix shim comment 6 rustc fix shim comment 6
warning: `foo` (lib) generated 2 warnings (run `cargo fix --lib -p foo` to apply 2 suggestions) [WARNING] `foo` (lib) generated 2 warnings (run `cargo fix --lib -p foo` to apply 2 suggestions)
[FINISHED] [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
"#]],
"// fix-count 5", "// fix-count 5",
); );
} }
@ -355,9 +358,9 @@ fn fix_verification_failed() {
expect_fix_runs_rustc_n_times( expect_fix_runs_rustc_n_times(
&[Step::OneFix, Step::Error], &[Step::OneFix, Step::Error],
|_execs| {}, |_execs| {},
"\ str![[r#"
[CHECKING] foo [..] [CHECKING] foo v0.0.1 ([ROOT]/foo)
warning: failed to automatically apply fixes suggested by rustc to crate `foo` [WARNING] failed to automatically apply fixes suggested by rustc to crate `foo`
after fixes were automatically applied the compiler reported errors within these files: after fixes were automatically applied the compiler reported errors within these files:
@ -377,9 +380,10 @@ rustc fix shim error count=2
Original diagnostics will follow. Original diagnostics will follow.
rustc fix shim comment 1 rustc fix shim comment 1
warning: `foo` (lib) generated 1 warning (run `cargo fix --lib -p foo` to apply 1 suggestion) [WARNING] `foo` (lib) generated 1 warning (run `cargo fix --lib -p foo` to apply 1 suggestion)
[FINISHED] [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
"#]],
"// fix-count 0", "// fix-count 0",
); );
} }
@ -394,9 +398,9 @@ fn fix_verification_failed_clippy() {
|execs| { |execs| {
execs.env("RUSTC_WORKSPACE_WRAPPER", tools::wrapped_clippy_driver()); execs.env("RUSTC_WORKSPACE_WRAPPER", tools::wrapped_clippy_driver());
}, },
"\ str![[r#"
[CHECKING] foo [..] [CHECKING] foo v0.0.1 ([ROOT]/foo)
warning: failed to automatically apply fixes suggested by rustc to crate `foo` [WARNING] failed to automatically apply fixes suggested by rustc to crate `foo`
after fixes were automatically applied the compiler reported errors within these files: after fixes were automatically applied the compiler reported errors within these files:
@ -416,9 +420,10 @@ rustc fix shim error count=2
Original diagnostics will follow. Original diagnostics will follow.
rustc fix shim comment 1 rustc fix shim comment 1
warning: `foo` (lib) generated 1 warning (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion) [WARNING] `foo` (lib) generated 1 warning (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion)
[FINISHED] [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
"#]],
"// fix-count 0", "// fix-count 0",
); );
} }
@ -429,12 +434,13 @@ fn warnings() {
expect_fix_runs_rustc_n_times( expect_fix_runs_rustc_n_times(
&[Step::Warning], &[Step::Warning],
|_execs| {}, |_execs| {},
"\ str![[r#"
[CHECKING] foo [..] [CHECKING] foo v0.0.1 ([ROOT]/foo)
rustc fix shim warning count=1 rustc fix shim warning count=1
warning: `foo` (lib) generated 1 warning [WARNING] `foo` (lib) generated 1 warning
[FINISHED] [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
"#]],
"// fix-count 0", "// fix-count 0",
); );
} }
@ -447,11 +453,12 @@ fn starts_with_error() {
|execs| { |execs| {
execs.with_status(101); execs.with_status(101);
}, },
"\ str![[r#"
[CHECKING] foo [..] [CHECKING] foo v0.0.1 ([ROOT]/foo)
rustc fix shim error count=1 rustc fix shim error count=1
error: could not compile `foo` (lib) due to 1 previous error [ERROR] could not compile `foo` (lib) due to 1 previous error
",
"#]],
"// fix-count 0", "// fix-count 0",
); );
} }
@ -464,11 +471,12 @@ fn broken_code_no_suggestions() {
|execs| { |execs| {
execs.arg("--broken-code").with_status(101); execs.arg("--broken-code").with_status(101);
}, },
"\ str![[r#"
[CHECKING] foo [..] [CHECKING] foo v0.0.1 ([ROOT]/foo)
rustc fix shim error count=1 rustc fix shim error count=1
error: could not compile `foo` (lib) due to 1 previous error [ERROR] could not compile `foo` (lib) due to 1 previous error
",
"#]],
"// fix-count 0", "// fix-count 0",
); );
} }
@ -481,9 +489,9 @@ fn broken_code_one_suggestion() {
|execs| { |execs| {
execs.arg("--broken-code").with_status(101); execs.arg("--broken-code").with_status(101);
}, },
"\ str![[r#"
[CHECKING] foo [..] [CHECKING] foo v0.0.1 ([ROOT]/foo)
warning: failed to automatically apply fixes suggested by rustc to crate `foo` [WARNING] failed to automatically apply fixes suggested by rustc to crate `foo`
after fixes were automatically applied the compiler reported errors within these files: after fixes were automatically applied the compiler reported errors within these files:
@ -504,9 +512,10 @@ Original diagnostics will follow.
rustc fix shim comment 1 rustc fix shim comment 1
rustc fix shim error count=2 rustc fix shim error count=2
warning: `foo` (lib) generated 1 warning [WARNING] `foo` (lib) generated 1 warning
error: could not compile `foo` (lib) due to 1 previous error; 1 warning emitted [ERROR] could not compile `foo` (lib) due to 1 previous error; 1 warning emitted
",
"#]],
"// fix-count 1", "// fix-count 1",
); );
} }

View File

@ -7,11 +7,9 @@
//! So we pick some random lint that will likely always be the same //! So we pick some random lint that will likely always be the same
//! over time. //! over time.
#![allow(deprecated)]
use super::config::write_config_toml; use super::config::write_config_toml;
use cargo_test_support::registry::Package; use cargo_test_support::registry::Package;
use cargo_test_support::{basic_manifest, project, Project}; use cargo_test_support::{basic_manifest, project, str, Project};
// An arbitrary lint (unused_variables) that triggers a lint. // An arbitrary lint (unused_variables) that triggers a lint.
// We use a special flag to force it to generate a report. // We use a special flag to force it to generate a report.
@ -35,8 +33,13 @@ fn output_on_stable() {
p.cargo("check") p.cargo("check")
.env("RUSTFLAGS", "-Zfuture-incompat-test") .env("RUSTFLAGS", "-Zfuture-incompat-test")
.with_stderr_contains(FUTURE_OUTPUT) .with_stderr_data(str![[r#"
.with_stderr_contains("[..]cargo report[..]") ...
[WARNING] unused variable: `x`
...
[NOTE] to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 1`
"#]])
.run(); .run();
} }
@ -50,7 +53,10 @@ fn no_gate_future_incompat_report() {
.run(); .run();
p.cargo("report future-incompatibilities --id foo") p.cargo("report future-incompatibilities --id foo")
.with_stderr_contains("error: no reports are currently available") .with_stderr_data(str![[r#"
[ERROR] no reports are currently available
"#]])
.with_status(101) .with_status(101)
.run(); .run();
} }
@ -68,25 +74,24 @@ fn test_zero_future_incompat() {
// No note if --future-incompat-report is not specified. // No note if --future-incompat-report is not specified.
p.cargo("check") p.cargo("check")
.env("RUSTFLAGS", "-Zfuture-incompat-test") .env("RUSTFLAGS", "-Zfuture-incompat-test")
.with_stderr( .with_stderr_data(str![[r#"
"\ [CHECKING] foo v0.0.0 ([ROOT]/foo)
[CHECKING] foo v0.0.0 [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[FINISHED] [..]
", "#]])
)
.run(); .run();
p.cargo("check --future-incompat-report") p.cargo("check --future-incompat-report")
.env("RUSTFLAGS", "-Zfuture-incompat-test") .env("RUSTFLAGS", "-Zfuture-incompat-test")
.with_stderr( .with_stderr_data(str![[r#"
"\ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[FINISHED] [..] [NOTE] 0 dependencies had future-incompatible warnings
note: 0 dependencies had future-incompatible warnings
", "#]])
)
.run(); .run();
} }
#[allow(deprecated)]
#[cargo_test( #[cargo_test(
nightly, nightly,
reason = "-Zfuture-incompat-test requires nightly (permanently)" reason = "-Zfuture-incompat-test requires nightly (permanently)"
@ -98,8 +103,13 @@ fn test_single_crate() {
let check_has_future_compat = || { let check_has_future_compat = || {
p.cargo(command) p.cargo(command)
.env("RUSTFLAGS", "-Zfuture-incompat-test") .env("RUSTFLAGS", "-Zfuture-incompat-test")
.with_stderr_contains(FUTURE_OUTPUT) .with_stderr_data("\
.with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 [..]") ...
[WARNING] unused variable: `x`
...
[WARNING] the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 ([ROOT]/foo)
...
")
.with_stderr_does_not_contain("[..]incompatibility[..]") .with_stderr_does_not_contain("[..]incompatibility[..]")
.run(); .run();
}; };
@ -126,7 +136,12 @@ frequency = 'never'
); );
p.cargo(command) p.cargo(command)
.env("RUSTFLAGS", "-Zfuture-incompat-test") .env("RUSTFLAGS", "-Zfuture-incompat-test")
.with_stderr_contains(FUTURE_OUTPUT) .with_stderr_data(
"\
[WARNING] unused variable: `x`
...
",
)
.with_stderr_does_not_contain("[..]rejected[..]") .with_stderr_does_not_contain("[..]rejected[..]")
.with_stderr_does_not_contain("[..]incompatibility[..]") .with_stderr_does_not_contain("[..]incompatibility[..]")
.run(); .run();
@ -134,13 +149,19 @@ frequency = 'never'
// Check that passing `--future-incompat-report` overrides `frequency = 'never'` // Check that passing `--future-incompat-report` overrides `frequency = 'never'`
p.cargo(command).arg("--future-incompat-report") p.cargo(command).arg("--future-incompat-report")
.env("RUSTFLAGS", "-Zfuture-incompat-test") .env("RUSTFLAGS", "-Zfuture-incompat-test")
.with_stderr_contains(FUTURE_OUTPUT) .with_stderr_data("\
.with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 [..]") [WARNING] unused variable: `x`
.with_stderr_contains(" - foo@0.0.0[..]") ...
[WARNING] the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 ([ROOT]/foo)
...
- foo@0.0.0
...
")
.run(); .run();
} }
} }
#[allow(deprecated)]
#[cargo_test( #[cargo_test(
nightly, nightly,
reason = "-Zfuture-incompat-test requires nightly (permanently)" reason = "-Zfuture-incompat-test requires nightly (permanently)"
@ -173,7 +194,11 @@ fn test_multi_crate() {
p.cargo(command) p.cargo(command)
.env("RUSTFLAGS", "-Zfuture-incompat-test") .env("RUSTFLAGS", "-Zfuture-incompat-test")
.with_stderr_does_not_contain(FUTURE_OUTPUT) .with_stderr_does_not_contain(FUTURE_OUTPUT)
.with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: first-dep v0.0.1, second-dep v0.0.2") .with_stderr_data("\
...
[WARNING] the following packages contain code that will be rejected by a future version of Rust: first-dep v0.0.1, second-dep v0.0.2
...
")
// Check that we don't have the 'triggers' message shown at the bottom of this loop, // Check that we don't have the 'triggers' message shown at the bottom of this loop,
// and that we don't explain how to show a per-package report // and that we don't explain how to show a per-package report
.with_stderr_does_not_contain("[..]triggers[..]") .with_stderr_does_not_contain("[..]triggers[..]")
@ -183,20 +208,42 @@ fn test_multi_crate() {
p.cargo(command).arg("--future-incompat-report") p.cargo(command).arg("--future-incompat-report")
.env("RUSTFLAGS", "-Zfuture-incompat-test") .env("RUSTFLAGS", "-Zfuture-incompat-test")
.with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: first-dep v0.0.1, second-dep v0.0.2") .with_stderr_data("\
.with_stderr_contains(" - first-dep@0.0.1") ...
.with_stderr_contains(" - second-dep@0.0.2") [WARNING] the following packages contain code that will be rejected by a future version of Rust: first-dep v0.0.1, second-dep v0.0.2
...
- first-dep@0.0.1
...
- second-dep@0.0.2
...
")
.run(); .run();
p.cargo("report future-incompatibilities").arg("--package").arg("first-dep@0.0.1") p.cargo("report future-incompatibilities")
.with_stdout_contains("The package `first-dep v0.0.1` currently triggers the following future incompatibility lints:") .arg("--package")
.with_stdout_contains(FUTURE_OUTPUT) .arg("first-dep@0.0.1")
.with_stdout_data(
"\
...
The package `first-dep v0.0.1` currently triggers the following future incompatibility lints:
> [WARNING] unused variable: `x`
...
",
)
.with_stdout_does_not_contain("[..]second-dep-0.0.2/src[..]") .with_stdout_does_not_contain("[..]second-dep-0.0.2/src[..]")
.run(); .run();
p.cargo("report future-incompatibilities").arg("--package").arg("second-dep@0.0.2") p.cargo("report future-incompatibilities")
.with_stdout_contains("The package `second-dep v0.0.2` currently triggers the following future incompatibility lints:") .arg("--package")
.with_stdout_contains(FUTURE_OUTPUT) .arg("second-dep@0.0.2")
.with_stdout_data(
"\
...
The package `second-dep v0.0.2` currently triggers the following future incompatibility lints:
> [WARNING] unused variable: `x`
...
",
)
.with_stdout_does_not_contain("[..]first-dep-0.0.1/src[..]") .with_stdout_does_not_contain("[..]first-dep-0.0.1/src[..]")
.run(); .run();
} }
@ -225,8 +272,13 @@ fn test_multi_crate() {
let id: String = id.chars().take_while(|c| *c != '`').collect(); let id: String = id.chars().take_while(|c| *c != '`').collect();
p.cargo(&format!("report future-incompatibilities --id {}", id)) p.cargo(&format!("report future-incompatibilities --id {}", id))
.with_stdout_contains("The package `first-dep v0.0.1` currently triggers the following future incompatibility lints:") .with_stdout_data(str![[r#"
.with_stdout_contains("The package `second-dep v0.0.2` currently triggers the following future incompatibility lints:") ...
The package `first-dep v0.0.1` currently triggers the following future incompatibility lints:
...
The package `second-dep v0.0.2` currently triggers the following future incompatibility lints:
...
"#]])
.run(); .run();
// Test without --id, and also the full output of the report. // Test without --id, and also the full output of the report.
@ -262,6 +314,7 @@ fn test_multi_crate() {
assert_eq!(lines.next(), None); assert_eq!(lines.next(), None);
} }
#[allow(deprecated)]
#[cargo_test( #[cargo_test(
nightly, nightly,
reason = "-Zfuture-incompat-test requires nightly (permanently)" reason = "-Zfuture-incompat-test requires nightly (permanently)"
@ -293,7 +346,10 @@ fn bad_ids() {
p.cargo("report future-incompatibilities --id 1") p.cargo("report future-incompatibilities --id 1")
.with_status(101) .with_status(101)
.with_stderr("error: no reports are currently available") .with_stderr_data(str![[r#"
[ERROR] no reports are currently available
"#]])
.run(); .run();
p.cargo("check") p.cargo("check")
@ -303,17 +359,18 @@ fn bad_ids() {
p.cargo("report future-incompatibilities --id foo") p.cargo("report future-incompatibilities --id foo")
.with_status(1) .with_status(1)
.with_stderr("error: Invalid value: could not parse `foo` as a number") .with_stderr_data(str![
"[ERROR] Invalid value: could not parse `foo` as a number"
])
.run(); .run();
p.cargo("report future-incompatibilities --id 7") p.cargo("report future-incompatibilities --id 7")
.with_status(101) .with_status(101)
.with_stderr( .with_stderr_data(str![[r#"
"\ [ERROR] could not find report with ID 7
error: could not find report with ID 7
Available IDs are: 1 Available IDs are: 1
",
) "#]])
.run(); .run();
} }
@ -373,21 +430,29 @@ fn suggestions_for_updates() {
// in a long while?). // in a long while?).
p.cargo("update without_updates").run(); p.cargo("update without_updates").run();
let update_message = "\ p.cargo("check --future-incompat-report")
.masquerade_as_nightly_cargo(&["future-incompat-test"])
.env("RUSTFLAGS", "-Zfuture-incompat-test")
.with_stderr_data(str![[r#"
...
- Some affected dependencies have newer versions available. - Some affected dependencies have newer versions available.
You may want to consider updating them to a newer version to see if the issue has been fixed. You may want to consider updating them to a newer version to see if the issue has been fixed.
big_update v1.0.0 has the following newer versions available: 2.0.0 big_update v1.0.0 has the following newer versions available: 2.0.0
with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1 with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1
"; ...
"#]])
p.cargo("check --future-incompat-report")
.masquerade_as_nightly_cargo(&["future-incompat-test"])
.env("RUSTFLAGS", "-Zfuture-incompat-test")
.with_stderr_contains(update_message)
.run(); .run();
p.cargo("report future-incompatibilities") p.cargo("report future-incompatibilities")
.with_stdout_contains(update_message) .with_stdout_data(str![[r#"
...
- Some affected dependencies have newer versions available.
You may want to consider updating them to a newer version to see if the issue has been fixed.
big_update v1.0.0 has the following newer versions available: 2.0.0
with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1
...
"#]])
.run() .run()
} }