From 676e97affd491065de5ec5265f9714759eb86d2b Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Wed, 19 Jun 2024 14:18:32 +0800 Subject: [PATCH 1/3] test: migrate lints/mod to snapbox --- tests/testsuite/lints/mod.rs | 110 ++++++++++++++++------------------- 1 file changed, 51 insertions(+), 59 deletions(-) diff --git a/tests/testsuite/lints/mod.rs b/tests/testsuite/lints/mod.rs index 52fa5ad9f6c4..5bab5bca4040 100644 --- a/tests/testsuite/lints/mod.rs +++ b/tests/testsuite/lints/mod.rs @@ -1,7 +1,6 @@ -#![allow(deprecated)] - use cargo_test_support::project; use cargo_test_support::registry::Package; +use cargo_test_support::str; mod error; mod implicit_features; @@ -34,20 +33,19 @@ im-a-teapot = "warn" foo.cargo("check -Zcargo-lints") .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) - .with_stderr( - "\ -warning: unknown lint: `im-a-teapot` + .with_stderr_data(str![[r#" +[WARNING] unknown lint: `im-a-teapot` --> Cargo.toml:12:1 | -12 | im-a-teapot = \"warn\" +12 | im-a-teapot = "warn" | ^^^^^^^^^^^ | - = note: `cargo::unknown_lints` is set to `warn` by default - = help: there is a lint with a similar name: `im_a_teapot` -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", - ) + = [NOTE] `cargo::unknown_lints` is set to `warn` by default + = [HELP] there is a lint with a similar name: `im_a_teapot` +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -77,17 +75,16 @@ test_dummy_unstable = { level = "forbid", priority = -1 } p.cargo("check -Zcargo-lints") .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) .with_status(101) - .with_stderr( - "\ -error: `im_a_teapot` is specified + .with_stderr_data(str![[r#" +[ERROR] `im_a_teapot` is specified --> Cargo.toml:9:1 | 9 | im-a-teapot = true | ^^^^^^^^^^^^^^^^^^ | - = note: `cargo::im_a_teapot` is set to `forbid` in `[lints]` -", - ) + = [NOTE] `cargo::im_a_teapot` is set to `forbid` in `[lints]` + +"#]]) .run(); } @@ -120,17 +117,16 @@ workspace = true p.cargo("check -Zcargo-lints") .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) .with_status(101) - .with_stderr( - "\ -error: `im_a_teapot` is specified + .with_stderr_data(str![[r#" +[ERROR] `im_a_teapot` is specified --> Cargo.toml:13:1 | 13 | im-a-teapot = true | ^^^^^^^^^^^^^^^^^^ | - = note: `cargo::im_a_teapot` is set to `forbid` in `[lints]` -", - ) + = [NOTE] `cargo::im_a_teapot` is set to `forbid` in `[lints]` + +"#]]) .run(); } @@ -165,12 +161,11 @@ im-a-teapot = true p.cargo("check -Zcargo-lints") .masquerade_as_nightly_cargo(&["cargo-lints"]) - .with_stderr( - "\ -[CHECKING] foo v0.0.1 ([CWD]/foo) -[FINISHED] [..] -", - ) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -216,17 +211,16 @@ implicit_features = "warn" p.cargo("check -Zcargo-lints") .masquerade_as_nightly_cargo(&["cargo-lints"]) - .with_stderr( - "\ -[UPDATING] [..] + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest compatible versions [DOWNLOADING] crates ... -[DOWNLOADED] bar v0.1.0 ([..]) +[DOWNLOADED] bar v0.1.0 (registry `dummy-registry`) [CHECKING] bar v0.1.0 -[CHECKING] foo v0.1.0 ([CWD]) -[FINISHED] [..] -", - ) +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -252,18 +246,17 @@ im_a_teapot = "warn" p.cargo("check -Zcargo-lints") .masquerade_as_nightly_cargo(&["cargo-lints"]) .with_status(101) - .with_stderr( - "\ -error: use of unstable lint `im_a_teapot` + .with_stderr_data(str![[r#" +[ERROR] use of unstable lint `im_a_teapot` --> Cargo.toml:9:1 | -9 | im_a_teapot = \"warn\" +9 | im_a_teapot = "warn" | ^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled | - = help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest -error: encountered 1 errors(s) while verifying lints -", - ) + = [HELP] consider adding `cargo-features = ["test-dummy-unstable"]` to the top of the manifest +[ERROR] encountered 1 errors(s) while verifying lints + +"#]]) .run(); } @@ -300,36 +293,35 @@ workspace = true p.cargo("check -Zcargo-lints") .masquerade_as_nightly_cargo(&["cargo-lints"]) .with_status(101) - .with_stderr( - "\ -error: use of unstable lint `im_a_teapot` + .with_stderr_data(str![[r#" +[ERROR] use of unstable lint `im_a_teapot` --> Cargo.toml:6:1 | -6 | im_a_teapot = { level = \"warn\", priority = 10 } +6 | im_a_teapot = { level = "warn", priority = 10 } | ^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled | -note: `cargo::im_a_teapot` was inherited +[NOTE] `cargo::im_a_teapot` was inherited --> foo/Cargo.toml:9:1 | 9 | workspace = true | ---------------- | - = help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest -error: use of unstable lint `test_dummy_unstable` + = [HELP] consider adding `cargo-features = ["test-dummy-unstable"]` to the top of the manifest +[ERROR] use of unstable lint `test_dummy_unstable` --> Cargo.toml:7:1 | -7 | test_dummy_unstable = { level = \"forbid\", priority = -1 } +7 | test_dummy_unstable = { level = "forbid", priority = -1 } | ^^^^^^^^^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled | -note: `cargo::test_dummy_unstable` was inherited +[NOTE] `cargo::test_dummy_unstable` was inherited --> foo/Cargo.toml:9:1 | 9 | workspace = true | ---------------- | - = help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest -error: encountered 2 errors(s) while verifying lints -", - ) + = [HELP] consider adding `cargo-features = ["test-dummy-unstable"]` to the top of the manifest +[ERROR] encountered 2 errors(s) while verifying lints + +"#]]) .run(); } From f75b4d708d5b31ad02b61c54abd1f9e6be81b25a Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Wed, 19 Jun 2024 14:21:16 +0800 Subject: [PATCH 2/3] test: migrate lints/unknown_lints to snapbox --- tests/testsuite/lints/unknown_lints.rs | 39 ++++++++++++-------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/tests/testsuite/lints/unknown_lints.rs b/tests/testsuite/lints/unknown_lints.rs index 707719ca4d10..3c745217da95 100644 --- a/tests/testsuite/lints/unknown_lints.rs +++ b/tests/testsuite/lints/unknown_lints.rs @@ -1,6 +1,5 @@ -#![allow(deprecated)] - use cargo_test_support::project; +use cargo_test_support::str; #[cargo_test] fn default() { @@ -23,19 +22,18 @@ this-lint-does-not-exist = "warn" p.cargo("check -Zcargo-lints") .masquerade_as_nightly_cargo(&["cargo-lints"]) - .with_stderr( - "\ -warning: unknown lint: `this-lint-does-not-exist` + .with_stderr_data(str![[r#" +[WARNING] unknown lint: `this-lint-does-not-exist` --> Cargo.toml:9:1 | -9 | this-lint-does-not-exist = \"warn\" +9 | this-lint-does-not-exist = "warn" | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `cargo::unknown_lints` is set to `warn` by default -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", - ) + = [NOTE] `cargo::unknown_lints` is set to `warn` by default +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -70,24 +68,23 @@ workspace = true p.cargo("check -Zcargo-lints") .masquerade_as_nightly_cargo(&["cargo-lints"]) - .with_stderr( - "\ -warning: unknown lint: `this-lint-does-not-exist` + .with_stderr_data(str![[r#" +[WARNING] unknown lint: `this-lint-does-not-exist` --> Cargo.toml:6:1 | -6 | this-lint-does-not-exist = \"warn\" +6 | this-lint-does-not-exist = "warn" | ^^^^^^^^^^^^^^^^^^^^^^^^ | -note: `cargo::this-lint-does-not-exist` was inherited +[NOTE] `cargo::this-lint-does-not-exist` was inherited --> foo/Cargo.toml:9:1 | 9 | workspace = true | ---------------- | - = note: `cargo::unknown_lints` is set to `warn` by default -[CHECKING] foo v0.0.1 ([CWD]/foo) -[FINISHED] [..] -", - ) + = [NOTE] `cargo::unknown_lints` is set to `warn` by default +[CHECKING] foo v0.0.1 ([ROOT]/foo/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } From 6c4d59c296416591f6e84b2d33def3e0059bc6ff Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Wed, 19 Jun 2024 14:29:28 +0800 Subject: [PATCH 3/3] test: migrate lints_table to snapbox --- tests/testsuite/lints_table.rs | 204 +++++++++++++++------------------ 1 file changed, 93 insertions(+), 111 deletions(-) diff --git a/tests/testsuite/lints_table.rs b/tests/testsuite/lints_table.rs index 8b6e5cccdce8..8c4e66aea31a 100644 --- a/tests/testsuite/lints_table.rs +++ b/tests/testsuite/lints_table.rs @@ -1,9 +1,8 @@ //! Tests for `[lints]` -#![allow(deprecated)] - use cargo_test_support::project; use cargo_test_support::registry::Package; +use cargo_test_support::str; #[cargo_test] fn dependency_warning_ignored() { @@ -43,14 +42,13 @@ fn dependency_warning_ignored() { .build(); foo.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[CHECKING] [..] -[CHECKING] [..] -[FINISHED] [..] -", - ) +[CHECKING] bar v0.0.1 ([ROOT]/bar) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -74,16 +72,15 @@ fn malformed_on_stable() { foo.cargo("check") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [ERROR] invalid type: integer `20`, expected a lints table --> Cargo.toml:2:25 | 2 | lints = 20 | ^^ | -", - ) + +"#]]) .run(); } @@ -106,16 +103,13 @@ fn fail_on_invalid_tool() { .file("src/lib.rs", "") .build(); - foo.cargo("check") - .with_stderr( - "\ -[WARNING] [CWD]/Cargo.toml: unrecognized lint tool `lints.super-awesome-linter`, specifying unrecognized tools may break in the future. + foo.cargo("check").with_stderr_data(str![[r#" +[WARNING] [ROOT]/foo/Cargo.toml: unrecognized lint tool `lints.super-awesome-linter`, specifying unrecognized tools may break in the future. supported tools: cargo, clippy, rust, rustdoc -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", - ) - .run(); +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]).run(); } #[cargo_test] @@ -138,16 +132,15 @@ fn invalid_type_in_lint_value() { foo.cargo("check") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [ERROR] invalid type: integer `-1`, expected a string or map --> Cargo.toml:8:36 | 8 | rust-2018-idioms = -1 | ^^ | -", - ) + +"#]]) .run(); } @@ -172,14 +165,13 @@ fn warn_on_unused_key() { .build(); foo.cargo("check") - .with_stderr( - "\ -[WARNING][..]unused manifest key: `lints.rust.rust-2018-idioms.unused` -[WARNING][..]unused manifest key: `lints.rust.rust-2018-idioms.unused` -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -", - ) + .with_stderr_data(str![[r#" +[WARNING] [ROOT]/foo/Cargo.toml: unused manifest key: `lints.rust.rust-2018-idioms.unused` +[WARNING] [ROOT]/foo/Cargo.toml: unused manifest key: `lints.rust.rust-2018-idioms.unused` +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -204,14 +196,13 @@ fn fail_on_tool_injection() { foo.cargo("check") .with_status(101) - .with_stderr( - "\ -[..] + .with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: `lints.rust.clippy::cyclomatic_complexity` is not valid lint name; try `lints.clippy.cyclomatic_complexity` -", - ) + +"#]]) .run(); } @@ -236,14 +227,13 @@ fn fail_on_redundant_tool() { foo.cargo("check") .with_status(101) - .with_stderr( - "\ -[..] + .with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: `lints.rust.rust::unsafe_code` is not valid lint name; try `lints.rust.unsafe_code` -", - ) + +"#]]) .run(); } @@ -268,14 +258,13 @@ fn fail_on_conflicting_tool() { foo.cargo("check") .with_status(101) - .with_stderr( - "\ -[..] + .with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: `lints.rust.super-awesome-tool::unsafe_code` is not a valid lint name -", - ) + +"#]]) .run(); } @@ -307,11 +296,11 @@ pub fn foo(num: i32) -> u32 { foo.cargo("check") .with_status(101) - .with_stderr_contains( - "\ -error: usage of an `unsafe` block -", - ) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[ERROR] usage of an `unsafe` block +... +"#]]) .run(); } @@ -346,16 +335,15 @@ pub fn foo(num: i32) -> u32 { foo.cargo("check") .with_status(101) - .with_stderr_contains( - "\ -error: `workspace` cannot be false + .with_stderr_data(str![[r#" +[ERROR] `workspace` cannot be false --> Cargo.toml:9:29 | 9 | workspace = false | ^^^^^ | -", - ) + +"#]]) .run(); } @@ -390,11 +378,11 @@ pub fn foo(num: i32) -> u32 { foo.cargo("check") .with_status(101) - .with_stderr_contains( - "\ -error: usage of an `unsafe` block -", - ) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[ERROR] usage of an `unsafe` block +... +"#]]) .run(); } @@ -431,14 +419,13 @@ pub fn foo(num: i32) -> u32 { foo.cargo("check") .with_status(101) - .with_stderr( - "\ -[ERROR] failed to parse manifest at `[CWD]/Cargo.toml` + .with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: cannot override `workspace.lints` in `lints`, either remove the overrides or `lints.workspace = true` and manually specify the lints -", - ) + +"#]]) .run(); } @@ -616,11 +603,11 @@ pub fn foo() -> u32 { foo.cargo("check") .with_status(101) - .with_stderr_contains( - "\ -error: unused extern crate -", - ) + .with_stderr_data(str![[r#" +... +[ERROR] unused extern crate +... +"#]]) .run(); } @@ -689,11 +676,11 @@ pub fn foo() -> u32 { foo.cargo("doc") .with_status(101) - .with_stderr_contains( - "\ -error: unresolved link to `bar` -", - ) + .with_stderr_data(str![[r#" +[DOCUMENTING] foo v0.0.1 ([ROOT]/foo) +[ERROR] unresolved link to `bar` +... +"#]]) .run(); } @@ -732,22 +719,20 @@ pub const Ĕ: i32 = 2; .build(); foo.cargo("check") - .with_stderr( - "\ -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -", - ) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); foo.cargo("test --doc") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]s + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s [DOCTEST] foo -", - ) + +"#]]) .run(); } @@ -770,17 +755,16 @@ authors = [] .build(); foo.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [WARNING] unused manifest key `lints.cargo` (may be supported in a future version) this Cargo does not support nightly features, but if you switch to nightly channel you can pass `-Zcargo-lints` to enable this feature. -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", - ) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -807,15 +791,14 @@ im-a-teapot = true foo.cargo("check") .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [WARNING] unused manifest key `lints.cargo` (may be supported in a future version) consider passing `-Zcargo-lints` to enable this feature. -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", - ) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -843,18 +826,17 @@ im_a_teapot = "warn" p.cargo("check -Zcargo-lints") .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) - .with_stderr( - "\ -warning: `im_a_teapot` is specified + .with_stderr_data(str![[r#" +[WARNING] `im_a_teapot` is specified --> Cargo.toml:9:1 | 9 | im-a-teapot = true | ------------------ | - = note: `cargo::im_a_teapot` is set to `warn` in `[lints]` -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", - ) + = [NOTE] `cargo::im_a_teapot` is set to `warn` in `[lints]` +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); }