From 882f3473b598d39a0d5aa46c5bd13bb86b51f7a1 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Sat, 29 Jun 2024 13:15:15 +0800 Subject: [PATCH 1/3] test: migrate fix to snapbox --- tests/testsuite/fix.rs | 600 +++++++++++++++++++++++------------------ 1 file changed, 334 insertions(+), 266 deletions(-) diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index a86acb80ea8..e6d0544ab54 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -1,11 +1,10 @@ //! Tests for the `cargo fix` command. -#![allow(deprecated)] - use cargo::core::Edition; use cargo_test_support::compare::assert_e2e; use cargo_test_support::git::{self, init}; use cargo_test_support::paths::{self, CargoPathExt}; +use cargo_test_support::prelude::*; use cargo_test_support::registry::{Dependency, Package}; use cargo_test_support::str; use cargo_test_support::tools; @@ -32,7 +31,11 @@ fn do_not_fix_broken_builds() { p.cargo("fix --allow-no-vcs") .env("__CARGO_FIX_YOLO", "1") .with_status(101) - .with_stderr_contains("[ERROR] could not compile `foo` (lib) due to 1 previous error[..]") + .with_stderr_data(str![[r#" +... +[ERROR] could not compile `foo` (lib) due to 1 previous error; 1 warning emitted +... +"#]]) .run(); assert!(p.read_file("src/lib.rs").contains("let mut x = 3;")); } @@ -98,16 +101,18 @@ fn fix_path_deps() { p.cargo("fix --allow-no-vcs -p foo -p bar") .env("__CARGO_FIX_YOLO", "1") - .with_stdout("") - .with_stderr_unordered( - "\ + .with_stdout_data("") + .with_stderr_data( + str![[r#" [LOCKING] 2 packages to latest compatible versions -[CHECKING] bar v0.1.0 ([..]) +[CHECKING] bar v0.1.0 ([ROOT]/foo/bar) [FIXED] bar/src/lib.rs (1 fix) -[CHECKING] foo v0.1.0 ([..]) +[CHECKING] foo v0.1.0 ([ROOT]/foo) [FIXED] src/lib.rs (1 fix) -[FINISHED] [..] -", +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]] + .unordered(), ) .run(); } @@ -174,16 +179,16 @@ fn prepare_for_2018() { ) .build(); - let stderr = "\ + p.cargo("fix --edition --allow-no-vcs") + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2015 edition to 2018 -[CHECKING] foo v0.0.1 ([..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2015 edition to 2018 [FIXED] src/lib.rs (2 fixes) -[FINISHED] [..] -"; - p.cargo("fix --edition --allow-no-vcs") - .with_stderr(stderr) - .with_stdout("") +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); println!("{}", p.read_file("src/lib.rs")); @@ -213,16 +218,15 @@ fn local_paths() { .build(); p.cargo("fix --edition --allow-no-vcs") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2015 edition to 2018 -[CHECKING] foo v0.0.1 ([..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2015 edition to 2018 [FIXED] src/lib.rs (1 fix) -[FINISHED] [..] -", - ) - .with_stdout("") +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); println!("{}", p.read_file("src/lib.rs")); @@ -264,17 +268,17 @@ fn upgrade_extern_crate() { .file("bar/src/lib.rs", "pub fn bar() {}") .build(); - let stderr = "\ -[LOCKING] 2 packages to latest compatible versions -[CHECKING] bar v0.1.0 ([..]) -[CHECKING] foo v0.1.0 ([..]) -[FIXED] src/lib.rs (1 fix) -[FINISHED] [..] -"; p.cargo("fix --allow-no-vcs") .env("__CARGO_FIX_YOLO", "1") - .with_stderr(stderr) - .with_stdout("") + .with_stderr_data(str![[r#" +[LOCKING] 2 packages to latest compatible versions +[CHECKING] bar v0.1.0 ([ROOT]/foo/bar) +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[FIXED] src/lib.rs (1 fix) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); println!("{}", p.read_file("src/lib.rs")); assert!(!p.read_file("src/lib.rs").contains("extern crate")); @@ -301,16 +305,15 @@ fn specify_rustflags() { p.cargo("fix --edition --allow-no-vcs") .env("RUSTFLAGS", "-C linker=cc") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2015 edition to 2018 -[CHECKING] foo v0.0.1 ([..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2015 edition to 2018 [FIXED] src/lib.rs (1 fix) -[FINISHED] [..] -", - ) - .with_stdout("") +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); } @@ -318,13 +321,13 @@ fn specify_rustflags() { fn no_changes_necessary() { let p = project().file("src/lib.rs", "").build(); - let stderr = "\ -[CHECKING] foo v0.0.1 ([..]) -[FINISHED] [..] -"; p.cargo("fix --allow-no-vcs") - .with_stderr(stderr) - .with_stdout("") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); } @@ -342,15 +345,15 @@ fn fixes_extra_mut() { ) .build(); - let stderr = "\ -[CHECKING] foo v0.0.1 ([..]) -[FIXED] src/lib.rs (1 fix) -[FINISHED] [..] -"; p.cargo("fix --allow-no-vcs") .env("__CARGO_FIX_YOLO", "1") - .with_stderr(stderr) - .with_stdout("") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FIXED] src/lib.rs (1 fix) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); } @@ -369,15 +372,15 @@ fn fixes_two_missing_ampersands() { ) .build(); - let stderr = "\ -[CHECKING] foo v0.0.1 ([..]) -[FIXED] src/lib.rs (2 fixes) -[FINISHED] [..] -"; p.cargo("fix --allow-no-vcs") .env("__CARGO_FIX_YOLO", "1") - .with_stderr(stderr) - .with_stdout("") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FIXED] src/lib.rs (2 fixes) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); } @@ -395,15 +398,15 @@ fn tricky() { ) .build(); - let stderr = "\ -[CHECKING] foo v0.0.1 ([..]) -[FIXED] src/lib.rs (2 fixes) -[FINISHED] [..] -"; p.cargo("fix --allow-no-vcs") .env("__CARGO_FIX_YOLO", "1") - .with_stderr(stderr) - .with_stdout("") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FIXED] src/lib.rs (2 fixes) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); } @@ -496,8 +499,16 @@ fn fix_two_files() { p.cargo("fix --allow-no-vcs") .env("__CARGO_FIX_YOLO", "1") - .with_stderr_contains("[FIXED] src/bar.rs (1 fix)") - .with_stderr_contains("[FIXED] src/lib.rs (1 fix)") + .with_stderr_data( + str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FIXED] src/bar.rs (1 fix) +[FIXED] src/lib.rs (1 fix) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]] + .unordered(), + ) .run(); assert!(!p.read_file("src/lib.rs").contains("let mut x = 3;")); assert!(!p.read_file("src/bar.rs").contains("let mut x = 3;")); @@ -529,19 +540,25 @@ fn fixes_missing_ampersand() { p.cargo("fix --all-targets --allow-no-vcs") .env("__CARGO_FIX_YOLO", "1") - .with_stdout("") - .with_stderr_contains("[COMPILING] foo v0.0.1 ([..])") - .with_stderr_contains("[FIXED] build.rs (1 fix)") - // Don't assert number of fixes for this one, as we don't know if we're + .with_stdout_data("") + // Don't assert number of fixes for `src/lib.rs`, as we don't know if we're // fixing it once or twice! We run this all concurrently, and if we // compile (and fix) in `--test` mode first, we get two fixes. Otherwise // we'll fix one non-test thing, and then fix another one later in // test mode. - .with_stderr_contains("[FIXED] src/lib.rs[..]") - .with_stderr_contains("[FIXED] src/main.rs (1 fix)") - .with_stderr_contains("[FIXED] examples/foo.rs (1 fix)") - .with_stderr_contains("[FIXED] tests/a.rs (1 fix)") - .with_stderr_contains("[FINISHED] [..]") + .with_stderr_data( + str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FIXED] build.rs (1 fix) +[FIXED] src/lib.rs ([..]fix[..]) +[FIXED] src/main.rs (1 fix) +[FIXED] examples/foo.rs (1 fix) +[FIXED] tests/a.rs (1 fix) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +... +"#]] + .unordered(), + ) .run(); p.cargo("check").run(); p.cargo("test").run(); @@ -589,7 +606,11 @@ fn shows_warnings() { .build(); p.cargo("fix --allow-no-vcs") - .with_stderr_contains("[..]warning: use of deprecated[..]") + .with_stderr_data(str![[r#" +... +[WARNING] use of deprecated function `bar` +... +"#]]) .run(); } @@ -599,11 +620,10 @@ fn warns_if_no_vcs_detected() { p.cargo("fix") .with_status(101) - .with_stderr( - "error: no VCS found for this package and `cargo fix` can potentially perform \ - destructive changes; if you'd like to suppress this error pass `--allow-no-vcs`\ - ", - ) + .with_stderr_data(str![[r#" +[ERROR] no VCS found for this package and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass `--allow-no-vcs` + +"#]]) .run(); p.cargo("fix --allow-no-vcs").run(); } @@ -616,18 +636,14 @@ fn warns_about_dirty_working_directory() { p.cargo("fix") .with_status(101) - .with_stderr( - "\ -error: the working directory of this package has uncommitted changes, \ -and `cargo fix` can potentially perform destructive changes; if you'd \ -like to suppress this error pass `--allow-dirty`, `--allow-staged`, or \ -commit the changes to these files: + .with_stderr_data(str![[r#" +[ERROR] the working directory of this package has uncommitted changes, and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass `--allow-dirty`, `--allow-staged`, or commit the changes to these files: * src/lib.rs (dirty) -", - ) + +"#]]) .run(); p.cargo("fix --allow-dirty").run(); } @@ -641,18 +657,14 @@ fn warns_about_staged_working_directory() { p.cargo("fix") .with_status(101) - .with_stderr( - "\ -error: the working directory of this package has uncommitted changes, \ -and `cargo fix` can potentially perform destructive changes; if you'd \ -like to suppress this error pass `--allow-dirty`, `--allow-staged`, or \ -commit the changes to these files: + .with_stderr_data(str![[r#" +[ERROR] the working directory of this package has uncommitted changes, and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass `--allow-dirty`, `--allow-staged`, or commit the changes to these files: * src/lib.rs (staged) -", - ) + +"#]]) .run(); p.cargo("fix --allow-staged").run(); } @@ -666,19 +678,15 @@ fn errors_about_untracked_files() { p.cargo("fix") .with_status(101) - .with_stderr( - "\ -error: the working directory of this package has uncommitted changes, \ -and `cargo fix` can potentially perform destructive changes; if you'd \ -like to suppress this error pass `--allow-dirty`, `--allow-staged`, or \ -commit the changes to these files: + .with_stderr_data(str![[r#" +[ERROR] the working directory of this package has uncommitted changes, and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass `--allow-dirty`, `--allow-staged`, or commit the changes to these files: * Cargo.toml (dirty) * src/ (dirty) -", - ) + +"#]]) .run(); p.cargo("fix --allow-dirty").run(); } @@ -747,8 +755,8 @@ fn prepare_for_unstable() { // -j1 to make the error more deterministic (otherwise there can be // multiple errors since they run in parallel). p.cargo("fix --edition --allow-no-vcs -j1") - .with_stderr(&format_args!("\ -[CHECKING] foo [..] + .with_stderr_data(&format!("\ +[CHECKING] foo v0.1.0 ([ROOT]/foo) [WARNING] `src/lib.rs` is on the latest edition, but trying to migrate to edition {next}. Edition {next} is unstable and not allowed in this release, consider trying the nightly release channel. @@ -763,7 +771,7 @@ process requires following these steps: More details may be found at https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html -[FINISHED] [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s ", next=next, latest_stable=latest_stable, prev=prev)) .run(); @@ -774,12 +782,12 @@ https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-proje p.cargo("fix --edition --allow-no-vcs") .masquerade_as_nightly_cargo(&["always_nightly"]) - .with_stderr(&format!( + .with_stderr_data(&format!( "\ [MIGRATING] Cargo.toml from {latest_stable} edition to {next} -[CHECKING] foo [..] +[CHECKING] foo v0.1.0 ([ROOT]/foo) [MIGRATING] src/lib.rs from {latest_stable} edition to {next} -[FINISHED] [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s ", latest_stable = latest_stable, next = next, @@ -809,12 +817,12 @@ fn prepare_for_latest_stable() { .build(); p.cargo("fix --edition --allow-no-vcs") - .with_stderr(&format!( + .with_stderr_data(&format!( "\ [MIGRATING] Cargo.toml from {previous} edition to {latest_stable} -[CHECKING] foo [..] +[CHECKING] foo v0.1.0 ([ROOT]/foo) [MIGRATING] src/lib.rs from {previous} edition to {latest_stable} -[FINISHED] [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s ", )) .run(); @@ -852,16 +860,18 @@ fn prepare_for_already_on_latest_unstable() { p.cargo("fix --edition --allow-no-vcs") .masquerade_as_nightly_cargo(&["always_nightly"]) - .with_stderr_contains("[CHECKING] foo [..]") - .with_stderr_contains(&format!( + .with_stderr_data(&format!( "\ +[CHECKING] foo v0.1.0 ([ROOT]/foo) [WARNING] `src/lib.rs` is already on the latest edition ({next_edition}), unable to migrate further +... ", next_edition = next_edition )) .run(); } +#[allow(deprecated)] #[cargo_test] fn prepare_for_already_on_latest_stable() { // Stable counterpart of prepare_for_already_on_latest_unstable. @@ -916,15 +926,14 @@ fn fix_overlapping() { .build(); p.cargo("fix --allow-no-vcs --edition --lib") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2015 edition to 2018 -[CHECKING] foo [..] +[CHECKING] foo v0.0.1 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2015 edition to 2018 [FIXED] src/lib.rs (2 fixes) -[FINISHED] `dev` profile [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); let contents = p.read_file("src/lib.rs"); @@ -955,13 +964,13 @@ fn fix_idioms() { ) .build(); - let stderr = "\ -[CHECKING] foo [..] -[FIXED] src/lib.rs (1 fix) -[FINISHED] [..] -"; p.cargo("fix --edition-idioms --allow-no-vcs") - .with_stderr(stderr) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[FIXED] src/lib.rs (1 fix) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert!(p.read_file("src/lib.rs").contains("Box")); @@ -991,11 +1000,19 @@ fn shows_warnings_on_second_run_without_changes() { .build(); p.cargo("fix --allow-no-vcs") - .with_stderr_contains("[..]warning: use of deprecated[..]") + .with_stderr_data(str![[r#" +... +[WARNING] use of deprecated function `bar` +... +"#]]) .run(); p.cargo("fix --allow-no-vcs") - .with_stderr_contains("[..]warning: use of deprecated[..]") + .with_stderr_data(str![[r#" +... +[WARNING] use of deprecated function `bar` +... +"#]]) .run(); } @@ -1062,19 +1079,42 @@ fn shows_warnings_on_second_run_without_changes_on_multiple_targets() { .build(); p.cargo("fix --allow-no-vcs --all-targets") - .with_stderr_contains(" --> examples/fooxample.rs:6:29") - .with_stderr_contains(" --> src/lib.rs:6:29") - .with_stderr_contains(" --> src/main.rs:6:29") - .with_stderr_contains(" --> tests/bar.rs:7:29") - .with_stderr_contains(" --> tests/foo.rs:7:29") + .with_stderr_data( + str![[r#" +... + --> src/lib.rs:6:29 +... + --> src/main.rs:6:29 +... + --> examples/fooxample.rs:6:29 +... + --> tests/foo.rs:7:29 +... + --> tests/bar.rs:7:29 +... + +"#]] + .unordered(), + ) .run(); p.cargo("fix --allow-no-vcs --all-targets") - .with_stderr_contains(" --> examples/fooxample.rs:6:29") - .with_stderr_contains(" --> src/lib.rs:6:29") - .with_stderr_contains(" --> src/main.rs:6:29") - .with_stderr_contains(" --> tests/bar.rs:7:29") - .with_stderr_contains(" --> tests/foo.rs:7:29") + .with_stderr_data( + str![[r#" +... + --> src/lib.rs:6:29 +... + --> src/main.rs:6:29 +... + --> examples/fooxample.rs:6:29 +... + --> tests/bar.rs:7:29 +... + --> tests/foo.rs:7:29 +... +"#]] + .unordered(), + ) .run(); } @@ -1102,26 +1142,24 @@ fn doesnt_rebuild_dependencies() { p.cargo("fix --allow-no-vcs -p foo") .env("__CARGO_FIX_YOLO", "1") - .with_stdout("") - .with_stderr( - "\ + .with_stdout_data("") + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[CHECKING] bar v0.1.0 ([..]) -[CHECKING] foo v0.1.0 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[CHECKING] bar v0.1.0 ([ROOT]/foo/bar) +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("fix --allow-no-vcs -p foo") .env("__CARGO_FIX_YOLO", "1") - .with_stdout("") - .with_stderr( - "\ -[CHECKING] foo v0.1.0 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stdout_data("") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -1166,7 +1204,11 @@ fn uses_workspace_wrapper_and_primary_wrapper_override() { p.cargo("fix --allow-no-vcs --verbose") .env("RUSTC_WORKSPACE_WRAPPER", tools::echo_wrapper()) - .with_stderr_contains("WRAPPER CALLED: rustc src/lib.rs --crate-name foo [..]") + .with_stderr_data(str![[r#" +... +WRAPPER CALLED: rustc src/lib.rs --crate-name foo [..] +... +"#]]) .run(); } @@ -1208,16 +1250,15 @@ fn only_warn_for_relevant_crates() { .build(); p.cargo("fix --allow-no-vcs --edition") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2015 edition to 2018 [LOCKING] 2 packages to latest compatible versions -[CHECKING] a v0.1.0 ([..]) -[CHECKING] foo v0.1.0 ([..]) +[CHECKING] a v0.1.0 ([ROOT]/foo/a) +[CHECKING] foo v0.1.0 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2015 edition to 2018 -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -1294,7 +1335,11 @@ fn fix_to_broken_code() { .cwd("bar") .env("RUSTC", p.root().join("foo/target/debug/foo")) .with_status(101) - .with_stderr_contains("[WARNING] failed to automatically apply fixes [..]") + .with_stderr_data(str![[r#" +... +[WARNING] failed to automatically apply fixes suggested by rustc to crate `bar` +... +"#]]) .run(); assert_e2e().eq( @@ -1342,12 +1387,16 @@ fn fix_in_existing_repo_weird_ignore() { // ignored. p.cargo("fix") .cwd("inner") - .with_stderr_contains("[ERROR] no VCS found[..]") + .with_stderr_data(str![[r#" +[ERROR] no VCS found for this package and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass `--allow-no-vcs` + +"#]]) .with_status(101) .run(); p.cargo("fix").cwd("src").run(); } +#[allow(deprecated)] #[cargo_test] fn fix_color_message() { // Check that color appears in diagnostics. @@ -1356,12 +1405,22 @@ fn fix_color_message() { .build(); p.cargo("fix --allow-no-vcs --color=always") - .with_stderr_contains("[..]\x1b[[..]") + .with_stderr_data( + "\ +... +[..]\x1b[[..] +... +", + ) .with_status(101) .run(); p.cargo("fix --allow-no-vcs --color=never") - .with_stderr_contains("error: color test") + .with_stderr_data(str![[r#" +... +[ERROR] color test +... +"#]]) .with_stderr_does_not_contain("[..]\x1b[[..]") .with_status(101) .run(); @@ -1409,15 +1468,15 @@ fn edition_v2_resolver_report() { .build(); p.cargo("fix --edition --allow-no-vcs") - .with_stderr_unordered("\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2018 edition to 2021 -[UPDATING] [..] +[UPDATING] `dummy-registry` index [LOCKING] 4 packages to latest compatible versions [DOWNLOADING] crates ... -[DOWNLOADED] common v1.0.0 [..] -[DOWNLOADED] bar v1.0.0 [..] -[DOWNLOADED] opt_dep v1.0.0 [..] -note: Switching to Edition 2021 will enable the use of the version 2 feature resolver in Cargo. +[DOWNLOADED] common v1.0.0 (registry `dummy-registry`) +[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) +[DOWNLOADED] opt_dep v1.0.0 (registry `dummy-registry`) +[NOTE] Switching to Edition 2021 will enable the use of the version 2 feature resolver in Cargo. This may cause some dependencies to be built with fewer features enabled than previously. More information about the resolver changes may be found at https://doc.rust-lang.org/nightly/edition-guide/rust-2021/default-cargo-resolver.html When building the following dependencies, the given features will no longer be used: @@ -1432,10 +1491,11 @@ The following differences only apply when building with dev-dependencies: [CHECKING] opt_dep v1.0.0 [CHECKING] common v1.0.0 [CHECKING] bar v1.0.0 -[CHECKING] foo v0.1.0 [..] +[CHECKING] foo v0.1.0 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2018 edition to 2021 -[FINISHED] [..] -") +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]].unordered()) .run(); } @@ -1488,15 +1548,14 @@ fn fix_edition_2021() { ) .build(); p.cargo("fix --edition --allow-no-vcs") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2018 edition to 2021 -[CHECKING] foo v0.1.0 [..] +[CHECKING] foo v0.1.0 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2018 edition to 2021 [FIXED] src/lib.rs (1 fix) -[FINISHED] [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert!(p.read_file("src/lib.rs").contains(r#"0..=100 => true,"#)); } @@ -1532,14 +1591,16 @@ fn fix_shared_cross_workspace() { // [FIXED] foo/src/shared.rs (2 fixes) p.cargo("fix --allow-no-vcs") .env("__CARGO_FIX_YOLO", "1") - .with_stderr_unordered( - "\ + .with_stderr_data( + str![[r#" [LOCKING] 2 packages to latest compatible versions -[CHECKING] foo v0.1.0 [..] -[CHECKING] bar v0.1.0 [..] +[CHECKING] foo v0.1.0 ([ROOT]/foo/foo) +[CHECKING] bar v0.1.0 ([ROOT]/foo/bar) [FIXED] [..]foo/src/shared.rs (2 fixes) -[FINISHED] [..] -", +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]] + .unordered(), ) .run(); @@ -1618,16 +1679,20 @@ fn abnormal_exit() { "ONCE_PATH", paths::root().join("proc-macro-run-once").to_str().unwrap(), ) - .with_stderr_contains( - "[WARNING] failed to automatically apply fixes suggested by rustc to crate `foo`", - ) - .with_stderr_contains("I'm not a diagnostic.") // "signal: 6, SIGABRT: process abort signal" on some platforms - .with_stderr_contains("rustc exited abnormally: [..]") - .with_stderr_contains("Original diagnostics will follow.") + .with_stderr_data(str![[r#" +... +[WARNING] failed to automatically apply fixes suggested by rustc to crate `foo` +... +I'm not a diagnostic. +rustc exited abnormally: [..] +Original diagnostics will follow. +... +"#]]) .run(); } +#[allow(deprecated)] #[cargo_test] fn fix_with_run_cargo_in_proc_macros() { let p = project() @@ -1705,8 +1770,13 @@ fn non_edition_lint_migration() { .build(); // Check that it complains about an unused import. p.cargo("check --lib") - .with_stderr_contains("[..]unused_imports[..]") - .with_stderr_contains("[..]std::str::from_utf8[..]") + .with_stderr_data(str![[r#" +... +[..]use std::str::from_utf8; +... + = [NOTE] `#[warn(unused_imports)]` on by default +... +"#]]) .run(); p.cargo("fix --edition --allow-no-vcs").run(); let contents = p.read_file("src/lib.rs"); @@ -1895,20 +1965,21 @@ fn fix_in_dependency() { // compiler output. p.cargo("fix --lib --allow-no-vcs") .env("RUSTC", &rustc_bin) - .with_stderr("\ + .with_stderr_data(str![[r#" [CHECKING] bar v1.0.0 -[CHECKING] foo v0.1.0 [..] -warning: unused variable: `abc` - --> [ROOT]/home/.cargo/registry/src/[..]/bar-1.0.0/src/lib.rs:5:29 +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[WARNING] unused variable: `abc` + --> [ROOT]/home/.cargo/registry/src/-[HASH]/bar-1.0.0/src/lib.rs:5:29 | 5 | let $i = 1; - | ^^ help: if this is intentional, prefix it with an underscore: `_abc` + | ^^ [HELP] if this is intentional, prefix it with an underscore: `_abc` | - = note: `#[warn(unused_variables)]` on by default + = [NOTE] `#[warn(unused_variables)]` on by default + +[WARNING] `foo` (lib) generated 1 warning (run `cargo fix --lib -p foo` to apply 1 suggestion) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s -warning: `foo` (lib) generated 1 warning (run `cargo fix --lib -p foo` to apply 1 suggestion) -[FINISHED] [..] -") +"#]]) .run(); } @@ -2205,7 +2276,8 @@ fn fix_in_rust_src() { .env("__CARGO_FIX_YOLO", "1") .env("RUSTC", &rustc_bin) .with_status(101) - .with_stderr(r#"[CHECKING] foo v0.0.0 ([..]) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.0 ([ROOT]/foo) error[E0308]: mismatched types --> lib.rs:5:9 | @@ -2217,25 +2289,26 @@ error[E0308]: mismatched types 6 | | } | |_____- expected this to be `()` | - = note: expected unit type `()` + = [NOTE] expected unit type `()` found enum `Result<(), std::fmt::Error>` - = note: this error originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider using a semicolon here + = [NOTE] this error originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info) +[HELP] consider using a semicolon here | 6 | }; | + -help: you might have meant to return this value +[HELP] you might have meant to return this value | 5 | return writeln!(w, "but not here"); | ++++++ + -help: use the `?` operator to extract the `Result<(), std::fmt::Error>` value, propagating a `Result::Err` value to the caller +[HELP] use the `?` operator to extract the `Result<(), std::fmt::Error>` value, propagating a `Result::Err` value to the caller --> [..]/lib/rustlib/src/rust/library/core/src/macros/mod.rs:670:58 | 67| $dst.write_fmt($crate::format_args_nl!($($arg)*))? | + [ERROR] could not compile `foo` (lib) due to 1 previous error -"#) + +"#]]) .run(); } @@ -2265,13 +2338,12 @@ fn fix_only_once_for_duplicates() { .build(); p.cargo("fix --allow-no-vcs") - .with_stderr( - "\ -[CHECKING] foo v0.0.1 ([CWD]) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) [FIXED] src/lib.rs (1 fix) -[FINISHED] `dev` profile [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert_eq!( @@ -2305,15 +2377,14 @@ edition = "2021" p.cargo("fix --edition --allow-no-vcs") .masquerade_as_nightly_cargo(&["edition2024"]) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2021 edition to 2024 [FIXED] Cargo.toml (1 fix) -[CHECKING] foo v0.0.0 ([CWD]) +[CHECKING] foo v0.0.0 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2021 edition to 2024 -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert_e2e().eq( p.read_file("Cargo.toml"), @@ -2360,15 +2431,14 @@ edition = "2021" p.cargo("fix --edition --allow-no-vcs") .masquerade_as_nightly_cargo(&["edition2024"]) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2021 edition to 2024 [FIXED] Cargo.toml (1 fix) -[CHECKING] foo v0.0.0 ([CWD]) +[CHECKING] foo v0.0.0 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2021 edition to 2024 -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert_e2e().eq( p.read_file("Cargo.toml"), @@ -2463,18 +2533,17 @@ a = {path = "a", default_features = false} p.cargo("fix --edition --allow-no-vcs") .masquerade_as_nightly_cargo(&["edition2024"]) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2021 edition to 2024 [FIXED] Cargo.toml (11 fixes) - Locking 2 packages to latest compatible versions - Checking a v0.0.1 ([CWD]/a) -[CHECKING] foo v0.0.0 ([CWD]) +[LOCKING] 2 packages to latest compatible versions +[CHECKING] a v0.0.1 ([ROOT]/foo/a) +[CHECKING] foo v0.0.0 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2021 edition to 2024 [MIGRATING] examples/ex.rs from 2021 edition to 2024 -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert_e2e().eq( p.read_file("Cargo.toml"), @@ -2561,17 +2630,16 @@ target-dep = { version = "0.1.0", optional = true } p.cargo("fix --edition --allow-no-vcs") .masquerade_as_nightly_cargo(&["edition2024"]) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2021 edition to 2024 [FIXED] Cargo.toml (3 fixes) [UPDATING] `dummy-registry` index [LOCKING] 4 packages to latest compatible versions -[CHECKING] foo v0.1.0 ([CWD]) +[CHECKING] foo v0.1.0 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2021 edition to 2024 -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert_e2e().eq( p.read_file("Cargo.toml"), @@ -2624,17 +2692,16 @@ existing = [] p.cargo("fix --edition --allow-no-vcs") .masquerade_as_nightly_cargo(&["edition2024"]) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2021 edition to 2024 [FIXED] Cargo.toml (1 fix) [UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest compatible versions -[CHECKING] foo v0.1.0 ([CWD]) +[CHECKING] foo v0.1.0 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2021 edition to 2024 -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert_e2e().eq( p.read_file("Cargo.toml"), @@ -2702,17 +2769,16 @@ unrelated-dep-feature = ["unrelated-feature/a", "unrelated-feature/b"] p.cargo("fix --edition --allow-no-vcs") .masquerade_as_nightly_cargo(&["edition2024"]) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [MIGRATING] Cargo.toml from 2021 edition to 2024 [FIXED] Cargo.toml (4 fixes) [UPDATING] `dummy-registry` index [LOCKING] 5 packages to latest compatible versions -[CHECKING] foo v0.1.0 ([CWD]) +[CHECKING] foo v0.1.0 ([ROOT]/foo) [MIGRATING] src/lib.rs from 2021 edition to 2024 -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert_e2e().eq( p.read_file("Cargo.toml"), @@ -2834,8 +2900,8 @@ dep_df_false = { version = "0.1.0", default-features = false } p.cargo("fix --all --edition --allow-no-vcs") .masquerade_as_nightly_cargo(&["edition2024"]) - .with_stderr_unordered( - "\ + .with_stderr_data( + str![[r#" [MIGRATING] pkg_default/Cargo.toml from 2021 edition to 2024 [MIGRATING] pkg_df_true/Cargo.toml from 2021 edition to 2024 [MIGRATING] pkg_df_false/Cargo.toml from 2021 edition to 2024 @@ -2849,14 +2915,16 @@ dep_df_false = { version = "0.1.0", default-features = false } [CHECKING] dep_df_true v0.1.0 [CHECKING] dep_df_false v0.1.0 [CHECKING] dep_simple v0.1.0 -[CHECKING] pkg_df_true v0.1.0 ([CWD]/pkg_df_true) -[CHECKING] pkg_df_false v0.1.0 ([CWD]/pkg_df_false) -[CHECKING] pkg_default v0.1.0 ([CWD]/pkg_default) +[CHECKING] pkg_df_true v0.1.0 ([ROOT]/foo/pkg_df_true) +[CHECKING] pkg_df_false v0.1.0 ([ROOT]/foo/pkg_df_false) +[CHECKING] pkg_default v0.1.0 ([ROOT]/foo/pkg_default) [MIGRATING] pkg_df_false/src/lib.rs from 2021 edition to 2024 [MIGRATING] pkg_df_true/src/lib.rs from 2021 edition to 2024 [MIGRATING] pkg_default/src/lib.rs from 2021 edition to 2024 -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -", +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]] + .unordered(), ) .run(); From 7dc940c7a90cfb1a88c72034cd82ac47cb9b59c2 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Sat, 29 Jun 2024 13:20:23 +0800 Subject: [PATCH 2/3] test: migrate fix_n_times to snapbox --- tests/testsuite/fix_n_times.rs | 117 ++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 54 deletions(-) diff --git a/tests/testsuite/fix_n_times.rs b/tests/testsuite/fix_n_times.rs index 915d741cf32..32366143414 100644 --- a/tests/testsuite/fix_n_times.rs +++ b/tests/testsuite/fix_n_times.rs @@ -14,9 +14,8 @@ //! The [`expect_fix_runs_rustc_n_times`] function handles setting everything //! up, and verifying the results. -#![allow(deprecated)] - -use cargo_test_support::{basic_manifest, paths, project, tools, Execs}; +use cargo_test_support::{basic_manifest, paths, project, str, tools, Execs}; +use snapbox::data::Inline; use std::path::PathBuf; use std::sync::{Mutex, OnceLock}; @@ -60,7 +59,7 @@ enum Step { fn expect_fix_runs_rustc_n_times( sequence: &[Step], extra_execs: impl FnOnce(&mut Execs), - expected_stderr: &str, + expected_stderr: Inline, expected_lib_rs: &str, ) { let rustc = rustc_for_cargo_fix(); @@ -73,7 +72,7 @@ fn expect_fix_runs_rustc_n_times( execs .env("RUSTC", &rustc) .env("RUSTC_FIX_SHIM_SEQUENCE", sequence_str) - .with_stderr(expected_stderr); + .with_stderr_data(expected_stderr); extra_execs(&mut execs); execs.run(); let lib_rs = p.read_file("src/lib.rs"); @@ -270,10 +269,11 @@ fn fix_no_suggestions() { expect_fix_runs_rustc_n_times( &[Step::SuccessNoOutput], |_execs| {}, - "\ -[CHECKING] foo [..] -[FINISHED] [..] -", + str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]], "// fix-count 0", ); } @@ -284,11 +284,12 @@ fn fix_one_suggestion() { expect_fix_runs_rustc_n_times( &[Step::OneFix, Step::SuccessNoOutput], |_execs| {}, - "\ -[CHECKING] foo [..] + str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) [FIXED] src/lib.rs (1 fix) -[FINISHED] [..] -", +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]], "// fix-count 1", ); } @@ -299,11 +300,12 @@ fn fix_one_overlapping() { expect_fix_runs_rustc_n_times( &[Step::TwoFixOverlapping, Step::SuccessNoOutput], |_execs| {}, - "\ -[CHECKING] foo [..] + str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) [FIXED] src/lib.rs (1 fix) -[FINISHED] [..] -", +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]], "// fix-count 2", ); } @@ -321,9 +323,9 @@ fn fix_overlapping_max() { Step::TwoFixOverlapping, ], |_execs| {}, - "\ -[CHECKING] foo [..] -warning: error applying suggestions to `src/lib.rs` + str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[WARNING] error applying suggestions to `src/lib.rs` The full error message was: @@ -341,9 +343,10 @@ fixing code with the `--broken-code` flag [FIXED] src/lib.rs (4 fixes) rustc fix shim comment 5 rustc fix shim comment 6 -warning: `foo` (lib) generated 2 warnings (run `cargo fix --lib -p foo` to apply 2 suggestions) -[FINISHED] [..] -", +[WARNING] `foo` (lib) generated 2 warnings (run `cargo fix --lib -p foo` to apply 2 suggestions) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]], "// fix-count 5", ); } @@ -355,9 +358,9 @@ fn fix_verification_failed() { expect_fix_runs_rustc_n_times( &[Step::OneFix, Step::Error], |_execs| {}, - "\ -[CHECKING] foo [..] -warning: failed to automatically apply fixes suggested by rustc to crate `foo` + str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/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: @@ -377,9 +380,10 @@ rustc fix shim error count=2 Original diagnostics will follow. rustc fix shim comment 1 -warning: `foo` (lib) generated 1 warning (run `cargo fix --lib -p foo` to apply 1 suggestion) -[FINISHED] [..] -", +[WARNING] `foo` (lib) generated 1 warning (run `cargo fix --lib -p foo` to apply 1 suggestion) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]], "// fix-count 0", ); } @@ -394,9 +398,9 @@ fn fix_verification_failed_clippy() { |execs| { execs.env("RUSTC_WORKSPACE_WRAPPER", tools::wrapped_clippy_driver()); }, - "\ -[CHECKING] foo [..] -warning: failed to automatically apply fixes suggested by rustc to crate `foo` + str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/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: @@ -416,9 +420,10 @@ rustc fix shim error count=2 Original diagnostics will follow. rustc fix shim comment 1 -warning: `foo` (lib) generated 1 warning (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion) -[FINISHED] [..] -", +[WARNING] `foo` (lib) generated 1 warning (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]], "// fix-count 0", ); } @@ -429,12 +434,13 @@ fn warnings() { expect_fix_runs_rustc_n_times( &[Step::Warning], |_execs| {}, - "\ -[CHECKING] foo [..] + str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) rustc fix shim warning count=1 -warning: `foo` (lib) generated 1 warning -[FINISHED] [..] -", +[WARNING] `foo` (lib) generated 1 warning +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]], "// fix-count 0", ); } @@ -447,11 +453,12 @@ fn starts_with_error() { |execs| { execs.with_status(101); }, - "\ -[CHECKING] foo [..] + str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) 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", ); } @@ -464,11 +471,12 @@ fn broken_code_no_suggestions() { |execs| { execs.arg("--broken-code").with_status(101); }, - "\ -[CHECKING] foo [..] + str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) 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", ); } @@ -481,9 +489,9 @@ fn broken_code_one_suggestion() { |execs| { execs.arg("--broken-code").with_status(101); }, - "\ -[CHECKING] foo [..] -warning: failed to automatically apply fixes suggested by rustc to crate `foo` + str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/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: @@ -504,9 +512,10 @@ Original diagnostics will follow. rustc fix shim comment 1 rustc fix shim error count=2 -warning: `foo` (lib) generated 1 warning -error: could not compile `foo` (lib) due to 1 previous error; 1 warning emitted -", +[WARNING] `foo` (lib) generated 1 warning +[ERROR] could not compile `foo` (lib) due to 1 previous error; 1 warning emitted + +"#]], "// fix-count 1", ); } From ef27c273af0d502af3d2bef5618b16da564dff89 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Mon, 1 Jul 2024 03:56:29 +0800 Subject: [PATCH 3/3] test: migrate future_incompat_report to snapbox --- tests/testsuite/future_incompat_report.rs | 167 +++++++++++++++------- 1 file changed, 116 insertions(+), 51 deletions(-) diff --git a/tests/testsuite/future_incompat_report.rs b/tests/testsuite/future_incompat_report.rs index 336e13c7650..7f9573d2911 100644 --- a/tests/testsuite/future_incompat_report.rs +++ b/tests/testsuite/future_incompat_report.rs @@ -7,11 +7,9 @@ //! So we pick some random lint that will likely always be the same //! over time. -#![allow(deprecated)] - use super::config::write_config_toml; 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. // We use a special flag to force it to generate a report. @@ -35,8 +33,13 @@ fn output_on_stable() { p.cargo("check") .env("RUSTFLAGS", "-Zfuture-incompat-test") - .with_stderr_contains(FUTURE_OUTPUT) - .with_stderr_contains("[..]cargo report[..]") + .with_stderr_data(str![[r#" +... +[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(); } @@ -50,7 +53,10 @@ fn no_gate_future_incompat_report() { .run(); 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) .run(); } @@ -68,25 +74,24 @@ fn test_zero_future_incompat() { // No note if --future-incompat-report is not specified. p.cargo("check") .env("RUSTFLAGS", "-Zfuture-incompat-test") - .with_stderr( - "\ -[CHECKING] foo v0.0.0 [..] -[FINISHED] [..] -", - ) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("check --future-incompat-report") .env("RUSTFLAGS", "-Zfuture-incompat-test") - .with_stderr( - "\ -[FINISHED] [..] -note: 0 dependencies had future-incompatible warnings -", - ) + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[NOTE] 0 dependencies had future-incompatible warnings + +"#]]) .run(); } +#[allow(deprecated)] #[cargo_test( nightly, reason = "-Zfuture-incompat-test requires nightly (permanently)" @@ -98,8 +103,13 @@ fn test_single_crate() { let check_has_future_compat = || { p.cargo(command) .env("RUSTFLAGS", "-Zfuture-incompat-test") - .with_stderr_contains(FUTURE_OUTPUT) - .with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 [..]") + .with_stderr_data("\ +... +[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[..]") .run(); }; @@ -126,7 +136,12 @@ frequency = 'never' ); p.cargo(command) .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("[..]incompatibility[..]") .run(); @@ -134,13 +149,19 @@ frequency = 'never' // Check that passing `--future-incompat-report` overrides `frequency = 'never'` p.cargo(command).arg("--future-incompat-report") .env("RUSTFLAGS", "-Zfuture-incompat-test") - .with_stderr_contains(FUTURE_OUTPUT) - .with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 [..]") - .with_stderr_contains(" - foo@0.0.0[..]") + .with_stderr_data("\ +[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) +... + - foo@0.0.0 +... +") .run(); } } +#[allow(deprecated)] #[cargo_test( nightly, reason = "-Zfuture-incompat-test requires nightly (permanently)" @@ -173,7 +194,11 @@ fn test_multi_crate() { p.cargo(command) .env("RUSTFLAGS", "-Zfuture-incompat-test") .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, // and that we don't explain how to show a per-package report .with_stderr_does_not_contain("[..]triggers[..]") @@ -183,20 +208,42 @@ fn test_multi_crate() { p.cargo(command).arg("--future-incompat-report") .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_contains(" - first-dep@0.0.1") - .with_stderr_contains(" - second-dep@0.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 +... + - first-dep@0.0.1 +... + - second-dep@0.0.2 +... +") .run(); - p.cargo("report future-incompatibilities").arg("--package").arg("first-dep@0.0.1") - .with_stdout_contains("The package `first-dep v0.0.1` currently triggers the following future incompatibility lints:") - .with_stdout_contains(FUTURE_OUTPUT) + p.cargo("report future-incompatibilities") + .arg("--package") + .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[..]") .run(); - p.cargo("report future-incompatibilities").arg("--package").arg("second-dep@0.0.2") - .with_stdout_contains("The package `second-dep v0.0.2` currently triggers the following future incompatibility lints:") - .with_stdout_contains(FUTURE_OUTPUT) + p.cargo("report future-incompatibilities") + .arg("--package") + .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[..]") .run(); } @@ -225,8 +272,13 @@ fn test_multi_crate() { let id: String = id.chars().take_while(|c| *c != '`').collect(); 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_contains("The package `second-dep v0.0.2` currently triggers the following future incompatibility lints:") + .with_stdout_data(str![[r#" +... +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(); // Test without --id, and also the full output of the report. @@ -262,6 +314,7 @@ fn test_multi_crate() { assert_eq!(lines.next(), None); } +#[allow(deprecated)] #[cargo_test( nightly, reason = "-Zfuture-incompat-test requires nightly (permanently)" @@ -293,7 +346,10 @@ fn bad_ids() { p.cargo("report future-incompatibilities --id 1") .with_status(101) - .with_stderr("error: no reports are currently available") + .with_stderr_data(str![[r#" +[ERROR] no reports are currently available + +"#]]) .run(); p.cargo("check") @@ -303,17 +359,18 @@ fn bad_ids() { p.cargo("report future-incompatibilities --id foo") .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(); p.cargo("report future-incompatibilities --id 7") .with_status(101) - .with_stderr( - "\ -error: could not find report with ID 7 + .with_stderr_data(str![[r#" +[ERROR] could not find report with ID 7 Available IDs are: 1 -", - ) + +"#]]) .run(); } @@ -373,21 +430,29 @@ fn suggestions_for_updates() { // in a long while?). 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. 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 -"; - - p.cargo("check --future-incompat-report") - .masquerade_as_nightly_cargo(&["future-incompat-test"]) - .env("RUSTFLAGS", "-Zfuture-incompat-test") - .with_stderr_contains(update_message) +... +"#]]) .run(); 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() }