From c310fcb57a47a60be650c66af7a007c6d6233c74 Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Wed, 1 May 2024 11:07:56 -0600 Subject: [PATCH] refactor: Move cargo lint tests to their own file --- tests/testsuite/cargo_lints.rs | 434 +++++++++++++++++++++++++++++++++ tests/testsuite/lints_table.rs | 432 -------------------------------- tests/testsuite/main.rs | 1 + 3 files changed, 435 insertions(+), 432 deletions(-) create mode 100644 tests/testsuite/cargo_lints.rs diff --git a/tests/testsuite/cargo_lints.rs b/tests/testsuite/cargo_lints.rs new file mode 100644 index 000000000000..ed0fea3720ee --- /dev/null +++ b/tests/testsuite/cargo_lints.rs @@ -0,0 +1,434 @@ +use cargo_test_support::project; +use cargo_test_support::registry::Package; + +#[cargo_test] +fn cargo_lints_nightly_required() { + let foo = project() + .file( + "Cargo.toml", + r#" +[package] +name = "foo" +version = "0.0.1" +edition = "2015" +authors = [] + +[lints.cargo] + "#, + ) + .file("src/lib.rs", "") + .build(); + + foo.cargo("check") + .with_stderr( + "\ +[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] [..] +", + ) + .run(); +} + +#[cargo_test] +fn cargo_lints_no_z_flag() { + let foo = project() + .file( + "Cargo.toml", + r#" +cargo-features = ["test-dummy-unstable"] + +[package] +name = "foo" +version = "0.0.1" +edition = "2015" +authors = [] +im-a-teapot = true + +[lints.cargo] + "#, + ) + .file("src/lib.rs", "") + .build(); + + foo.cargo("check") + .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) + .with_stderr( + "\ +[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] [..] +", + ) + .run(); +} + +#[cargo_test] +fn cargo_lints_success() { + let p = project() + .file( + "Cargo.toml", + r#" +cargo-features = ["test-dummy-unstable"] + +[package] +name = "foo" +version = "0.0.1" +edition = "2015" +authors = [] +im-a-teapot = true + +[lints.cargo] +im_a_teapot = "warn" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) + .with_stderr( + "\ +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] [..] +", + ) + .run(); +} + +#[cargo_test] +fn dashes_dont_get_rewritten() { + let foo = project() + .file( + "Cargo.toml", + r#" +cargo-features = ["test-dummy-unstable"] + +[package] +name = "foo" +version = "0.0.1" +edition = "2015" +authors = [] +im-a-teapot = true + +[lints.cargo] +im-a-teapot = "warn" + "#, + ) + .file("src/lib.rs", "") + .build(); + + foo.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) + .with_stderr( + "\ +warning: unknown lint: `im-a-teapot` + --> Cargo.toml:12:1 + | +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] [..] +", + ) + .run(); +} + +#[cargo_test] +fn forbid_not_overridden() { + let p = project() + .file( + "Cargo.toml", + r#" +cargo-features = ["test-dummy-unstable"] + +[package] +name = "foo" +version = "0.0.1" +edition = "2015" +authors = [] +im-a-teapot = true + +[lints.cargo] +im_a_teapot = { level = "warn", priority = 10 } +test_dummy_unstable = { level = "forbid", priority = -1 } + "#, + ) + .file("src/lib.rs", "") + .build(); + + 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 + --> Cargo.toml:9:1 + | +9 | im-a-teapot = true + | ^^^^^^^^^^^^^^^^^^ + | + = note: `cargo::im_a_teapot` is set to `forbid` in `[lints]` +", + ) + .run(); +} + +#[cargo_test] +fn workspace_supported() { + let p = project() + .file( + "Cargo.toml", + r#" +cargo-features = ["test-dummy-unstable"] + +[workspace.lints.cargo] +im_a_teapot = { level = "warn", priority = 10 } +test_dummy_unstable = { level = "forbid", priority = -1 } + +[package] +name = "foo" +version = "0.0.1" +edition = "2015" +authors = [] +im-a-teapot = true + +[lints] +workspace = true + "#, + ) + .file("src/lib.rs", "") + .build(); + + 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 + --> Cargo.toml:13:1 + | +13 | im-a-teapot = true + | ^^^^^^^^^^^^^^^^^^ + | + = note: `cargo::im_a_teapot` is set to `forbid` in `[lints]` +", + ) + .run(); +} + +#[cargo_test] +fn dont_always_inherit_workspace_lints() { + let p = project() + .file( + "Cargo.toml", + r#" +[workspace] +members = ["foo"] + +[workspace.lints.cargo] +im_a_teapot = "warn" +"#, + ) + .file( + "foo/Cargo.toml", + r#" +cargo-features = ["test-dummy-unstable"] + +[package] +name = "foo" +version = "0.0.1" +edition = "2015" +authors = [] +im-a-teapot = true +"#, + ) + .file("foo/src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints"]) + .with_stderr( + "\ +[CHECKING] foo v0.0.1 ([CWD]/foo) +[FINISHED] [..] +", + ) + .run(); +} + +#[cargo_test] +fn cap_lints_works() { + Package::new("baz", "0.1.0").publish(); + Package::new("bar", "0.1.0") + .file( + "Cargo.toml", + r#" +[package] +name = "bar" +version = "0.1.0" +edition = "2021" + +[dependencies] +baz = { version = "0.1.0", optional = true } + +[lints.cargo] +implicit_features = "warn" +"#, + ) + .file("src/lib.rs", "") + .publish(); + let p = project() + .file( + "Cargo.toml", + r#" +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +[dependencies] +bar = "0.1.0" + +[lints.cargo] +implicit_features = "warn" +"#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints"]) + .with_stderr( + "\ +[UPDATING] [..] +[LOCKING] 2 packages to latest compatible versions +[DOWNLOADING] crates ... +[DOWNLOADED] bar v0.1.0 ([..]) +[CHECKING] bar v0.1.0 +[CHECKING] foo v0.1.0 ([CWD]) +[FINISHED] [..] +", + ) + .run(); +} + +#[cargo_test] +fn check_feature_gated() { + let p = project() + .file( + "Cargo.toml", + r#" +[package] +name = "foo" +version = "0.0.1" +edition = "2015" +authors = [] + +[lints.cargo] +im_a_teapot = "warn" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints"]) + .with_status(101) + .with_stderr( + "\ +error: use of unstable lint `im_a_teapot` + --> Cargo.toml:9:1 + | +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 +", + ) + .run(); +} + +#[cargo_test] +fn check_feature_gated_workspace() { + let p = project() + .file( + "Cargo.toml", + r#" +[workspace] +members = ["foo"] + +[workspace.lints.cargo] +im_a_teapot = { level = "warn", priority = 10 } +test_dummy_unstable = { level = "forbid", priority = -1 } + "#, + ) + .file( + "foo/Cargo.toml", + r#" +[package] +name = "foo" +version = "0.0.1" +edition = "2015" +authors = [] + +[lints] +workspace = true + "#, + ) + .file("foo/src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints"]) + .with_status(101) + .with_stderr( + "\ +error: use of unstable lint `im_a_teapot` + --> Cargo.toml:6:1 + | +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 + --> 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` + --> Cargo.toml:7: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 + --> 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 +", + ) + .run(); +} diff --git a/tests/testsuite/lints_table.rs b/tests/testsuite/lints_table.rs index 6ebdda1a35b7..3e6d4ff72811 100644 --- a/tests/testsuite/lints_table.rs +++ b/tests/testsuite/lints_table.rs @@ -748,435 +748,3 @@ pub const Ĕ: i32 = 2; ) .run(); } - -#[cargo_test] -fn cargo_lints_nightly_required() { - let foo = project() - .file( - "Cargo.toml", - r#" -[package] -name = "foo" -version = "0.0.1" -edition = "2015" -authors = [] - -[lints.cargo] - "#, - ) - .file("src/lib.rs", "") - .build(); - - foo.cargo("check") - .with_stderr( - "\ -[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] [..] -", - ) - .run(); -} - -#[cargo_test] -fn cargo_lints_no_z_flag() { - let foo = project() - .file( - "Cargo.toml", - r#" -cargo-features = ["test-dummy-unstable"] - -[package] -name = "foo" -version = "0.0.1" -edition = "2015" -authors = [] -im-a-teapot = true - -[lints.cargo] - "#, - ) - .file("src/lib.rs", "") - .build(); - - foo.cargo("check") - .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) - .with_stderr( - "\ -[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] [..] -", - ) - .run(); -} - -#[cargo_test] -fn cargo_lints_success() { - let p = project() - .file( - "Cargo.toml", - r#" -cargo-features = ["test-dummy-unstable"] - -[package] -name = "foo" -version = "0.0.1" -edition = "2015" -authors = [] -im-a-teapot = true - -[lints.cargo] -im_a_teapot = "warn" - "#, - ) - .file("src/lib.rs", "") - .build(); - - p.cargo("check -Zcargo-lints") - .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) - .with_stderr( - "\ -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] [..] -", - ) - .run(); -} - -#[cargo_test] -fn cargo_lints_dashes_dont_get_rewritten() { - let foo = project() - .file( - "Cargo.toml", - r#" -cargo-features = ["test-dummy-unstable"] - -[package] -name = "foo" -version = "0.0.1" -edition = "2015" -authors = [] -im-a-teapot = true - -[lints.cargo] -im-a-teapot = "warn" - "#, - ) - .file("src/lib.rs", "") - .build(); - - foo.cargo("check -Zcargo-lints") - .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) - .with_stderr( - "\ -warning: unknown lint: `im-a-teapot` - --> Cargo.toml:12:1 - | -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] [..] -", - ) - .run(); -} - -#[cargo_test] -fn forbid_not_overridden() { - let p = project() - .file( - "Cargo.toml", - r#" -cargo-features = ["test-dummy-unstable"] - -[package] -name = "foo" -version = "0.0.1" -edition = "2015" -authors = [] -im-a-teapot = true - -[lints.cargo] -im_a_teapot = { level = "warn", priority = 10 } -test_dummy_unstable = { level = "forbid", priority = -1 } - "#, - ) - .file("src/lib.rs", "") - .build(); - - 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 - --> Cargo.toml:9:1 - | -9 | im-a-teapot = true - | ^^^^^^^^^^^^^^^^^^ - | - = note: `cargo::im_a_teapot` is set to `forbid` in `[lints]` -", - ) - .run(); -} - -#[cargo_test] -fn workspace_cargo_lints() { - let p = project() - .file( - "Cargo.toml", - r#" -cargo-features = ["test-dummy-unstable"] - -[workspace.lints.cargo] -im_a_teapot = { level = "warn", priority = 10 } -test_dummy_unstable = { level = "forbid", priority = -1 } - -[package] -name = "foo" -version = "0.0.1" -edition = "2015" -authors = [] -im-a-teapot = true - -[lints] -workspace = true - "#, - ) - .file("src/lib.rs", "") - .build(); - - 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 - --> Cargo.toml:13:1 - | -13 | im-a-teapot = true - | ^^^^^^^^^^^^^^^^^^ - | - = note: `cargo::im_a_teapot` is set to `forbid` in `[lints]` -", - ) - .run(); -} - -#[cargo_test] -fn dont_always_inherit_workspace_lints() { - let p = project() - .file( - "Cargo.toml", - r#" -[workspace] -members = ["foo"] - -[workspace.lints.cargo] -im_a_teapot = "warn" -"#, - ) - .file( - "foo/Cargo.toml", - r#" -cargo-features = ["test-dummy-unstable"] - -[package] -name = "foo" -version = "0.0.1" -edition = "2015" -authors = [] -im-a-teapot = true -"#, - ) - .file("foo/src/lib.rs", "") - .build(); - - p.cargo("check -Zcargo-lints") - .masquerade_as_nightly_cargo(&["cargo-lints"]) - .with_stderr( - "\ -[CHECKING] foo v0.0.1 ([CWD]/foo) -[FINISHED] [..] -", - ) - .run(); -} - -#[cargo_test] -fn cargo_lints_cap_lints() { - Package::new("baz", "0.1.0").publish(); - Package::new("bar", "0.1.0") - .file( - "Cargo.toml", - r#" -[package] -name = "bar" -version = "0.1.0" -edition = "2021" - -[dependencies] -baz = { version = "0.1.0", optional = true } - -[lints.cargo] -implicit_features = "warn" -"#, - ) - .file("src/lib.rs", "") - .publish(); - let p = project() - .file( - "Cargo.toml", - r#" -[package] -name = "foo" -version = "0.1.0" -edition = "2021" - -[dependencies] -bar = "0.1.0" - -[lints.cargo] -implicit_features = "warn" -"#, - ) - .file("src/lib.rs", "") - .build(); - - p.cargo("check -Zcargo-lints") - .masquerade_as_nightly_cargo(&["cargo-lints"]) - .with_stderr( - "\ -[UPDATING] [..] -[LOCKING] 2 packages to latest compatible versions -[DOWNLOADING] crates ... -[DOWNLOADED] bar v0.1.0 ([..]) -[CHECKING] bar v0.1.0 -[CHECKING] foo v0.1.0 ([CWD]) -[FINISHED] [..] -", - ) - .run(); -} - -#[cargo_test] -fn check_feature_gated() { - let p = project() - .file( - "Cargo.toml", - r#" -[package] -name = "foo" -version = "0.0.1" -edition = "2015" -authors = [] - -[lints.cargo] -im_a_teapot = "warn" - "#, - ) - .file("src/lib.rs", "") - .build(); - - p.cargo("check -Zcargo-lints") - .masquerade_as_nightly_cargo(&["cargo-lints"]) - .with_status(101) - .with_stderr( - "\ -error: use of unstable lint `im_a_teapot` - --> Cargo.toml:9:1 - | -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 -", - ) - .run(); -} - -#[cargo_test] -fn check_feature_gated_workspace() { - let p = project() - .file( - "Cargo.toml", - r#" -[workspace] -members = ["foo"] - -[workspace.lints.cargo] -im_a_teapot = { level = "warn", priority = 10 } -test_dummy_unstable = { level = "forbid", priority = -1 } - "#, - ) - .file( - "foo/Cargo.toml", - r#" -[package] -name = "foo" -version = "0.0.1" -edition = "2015" -authors = [] - -[lints] -workspace = true - "#, - ) - .file("foo/src/lib.rs", "") - .build(); - - p.cargo("check -Zcargo-lints") - .masquerade_as_nightly_cargo(&["cargo-lints"]) - .with_status(101) - .with_stderr( - "\ -error: use of unstable lint `im_a_teapot` - --> Cargo.toml:6:1 - | -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 - --> 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` - --> Cargo.toml:7: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 - --> 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 -", - ) - .run(); -} diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 3e6b07c7ccf9..9a6e682d8228 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -38,6 +38,7 @@ mod cargo_git_checkout; mod cargo_help; mod cargo_init; mod cargo_install; +mod cargo_lints; mod cargo_locate_project; mod cargo_login; mod cargo_logout;