Auto merge of #14104 - eth3lbert:snapbox-lints, r=weihanglo

test: migrate lints_table and lints/(mod|unknown_lints) to snapbox

### What does this PR try to resolve?

Part of #14039.

Migrate followings to snapbox:
- `tests/testsuite/lints/mod.rs`
- `tests/testsuite/lints/unknown_lints.rs`
- `tests/testsuite/lints_table.rs`
This commit is contained in:
bors 2024-06-21 00:41:07 +00:00
commit cabd5eb276
3 changed files with 162 additions and 191 deletions

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}