From c1f0c0b8d842e02714db02182045ac0fdf2c1f60 Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Wed, 8 May 2024 10:58:39 -0600 Subject: [PATCH 1/3] refactor: Move off UI tests for individual lints --- tests/testsuite/lints/implicit_features.rs | 137 +++++++++++++++ .../implicit_features/edition_2021/mod.rs | 32 ---- .../edition_2021/stderr.term.svg | 33 ---- .../edition_2021_warn/mod.rs | 45 ----- .../edition_2021_warn/stderr.term.svg | 74 -------- .../implicit_features/edition_2024/mod.rs | 43 ----- .../edition_2024/stderr.term.svg | 33 ---- .../testsuite/lints/implicit_features/mod.rs | 3 - tests/testsuite/lints/unknown_lints.rs | 91 ++++++++++ .../lints/unknown_lints/default/mod.rs | 33 ---- .../unknown_lints/default/stderr.term.svg | 47 ------ .../lints/unknown_lints/inherited/mod.rs | 43 ----- .../unknown_lints/inherited/stderr.term.svg | 59 ------- tests/testsuite/lints/unknown_lints/mod.rs | 2 - .../lints/unused_optional_dependencies.rs | 159 ++++++++++++++++++ .../edition_2021/mod.rs | 37 ---- .../edition_2021/stderr.term.svg | 33 ---- .../edition_2024/mod.rs | 56 ------ .../edition_2024/stderr.term.svg | 77 --------- .../lints/unused_optional_dependencies/mod.rs | 3 - .../renamed_deps/mod.rs | 43 ----- .../renamed_deps/stderr.term.svg | 77 --------- 22 files changed, 387 insertions(+), 773 deletions(-) create mode 100644 tests/testsuite/lints/implicit_features.rs delete mode 100644 tests/testsuite/lints/implicit_features/edition_2021/mod.rs delete mode 100644 tests/testsuite/lints/implicit_features/edition_2021/stderr.term.svg delete mode 100644 tests/testsuite/lints/implicit_features/edition_2021_warn/mod.rs delete mode 100644 tests/testsuite/lints/implicit_features/edition_2021_warn/stderr.term.svg delete mode 100644 tests/testsuite/lints/implicit_features/edition_2024/mod.rs delete mode 100644 tests/testsuite/lints/implicit_features/edition_2024/stderr.term.svg delete mode 100644 tests/testsuite/lints/implicit_features/mod.rs create mode 100644 tests/testsuite/lints/unknown_lints.rs delete mode 100644 tests/testsuite/lints/unknown_lints/default/mod.rs delete mode 100644 tests/testsuite/lints/unknown_lints/default/stderr.term.svg delete mode 100644 tests/testsuite/lints/unknown_lints/inherited/mod.rs delete mode 100644 tests/testsuite/lints/unknown_lints/inherited/stderr.term.svg delete mode 100644 tests/testsuite/lints/unknown_lints/mod.rs create mode 100644 tests/testsuite/lints/unused_optional_dependencies.rs delete mode 100644 tests/testsuite/lints/unused_optional_dependencies/edition_2021/mod.rs delete mode 100644 tests/testsuite/lints/unused_optional_dependencies/edition_2021/stderr.term.svg delete mode 100644 tests/testsuite/lints/unused_optional_dependencies/edition_2024/mod.rs delete mode 100644 tests/testsuite/lints/unused_optional_dependencies/edition_2024/stderr.term.svg delete mode 100644 tests/testsuite/lints/unused_optional_dependencies/mod.rs delete mode 100644 tests/testsuite/lints/unused_optional_dependencies/renamed_deps/mod.rs delete mode 100644 tests/testsuite/lints/unused_optional_dependencies/renamed_deps/stderr.term.svg diff --git a/tests/testsuite/lints/implicit_features.rs b/tests/testsuite/lints/implicit_features.rs new file mode 100644 index 00000000000..56d70243b96 --- /dev/null +++ b/tests/testsuite/lints/implicit_features.rs @@ -0,0 +1,137 @@ +use cargo_test_support::project; +use cargo_test_support::registry::Package; + +#[cargo_test] +fn default() { + Package::new("bar", "0.1.0").publish(); + let p = project() + .file( + "Cargo.toml", + r#" +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +[dependencies] +bar = { version = "0.1.0", optional = true } +"#, + ) + .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 +[CHECKING] foo v0.1.0 ([CWD]) +[FINISHED] [..] +", + ) + .run(); +} + +#[cargo_test] +fn warn() { + Package::new("bar", "0.1.0").publish(); + Package::new("baz", "0.1.0").publish(); + Package::new("target-dep", "0.1.0").publish(); + let p = project() + .file( + "Cargo.toml", + r#" +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +[dependencies] +bar = { version = "0.1.0", optional = true } + +[build-dependencies] +baz = { version = "0.1.0", optional = true } + +[target.'cfg(target_os = "linux")'.dependencies] +target-dep = { version = "0.1.0", optional = true } + +[lints.cargo] +implicit_features = "warn" +"#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints"]) + .with_stderr( + "\ +warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition + --> Cargo.toml:8:1 + | +8 | bar = { version = \"0.1.0\", optional = true } + | --- + | + = note: `cargo::implicit_features` is set to `warn` in `[lints]` +warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition + --> Cargo.toml:11:1 + | +11 | baz = { version = \"0.1.0\", optional = true } + | --- + | +warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition + --> Cargo.toml:14:1 + | +14 | target-dep = { version = \"0.1.0\", optional = true } + | ---------- + | +[UPDATING] [..] +[LOCKING] 4 packages to latest compatible versions +[CHECKING] foo v0.1.0 ([CWD]) +[FINISHED] [..] +", + ) + .run(); +} + +#[cargo_test(nightly, reason = "edition2024 is not stable")] +fn implicit_features_edition_2024() { + Package::new("bar", "0.1.0").publish(); + Package::new("baz", "0.1.0").publish(); + let p = project() + .file( + "Cargo.toml", + r#" +cargo-features = ["edition2024"] +[package] +name = "foo" +version = "0.1.0" +edition = "2024" + +[dependencies] +bar = { version = "0.1.0", optional = true } +baz = { version = "0.1.0", optional = true } + +[features] +baz = ["dep:baz"] + +[lints.cargo] +unused_optional_dependency = "allow" +"#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"]) + .with_stderr( + "\ +[UPDATING] [..] +[LOCKING] 2 packages to latest Rust [..] compatible versions +[CHECKING] foo v0.1.0 ([CWD]) +[FINISHED] [..] +", + ) + .run(); +} diff --git a/tests/testsuite/lints/implicit_features/edition_2021/mod.rs b/tests/testsuite/lints/implicit_features/edition_2021/mod.rs deleted file mode 100644 index 7ab75c6c7b8..00000000000 --- a/tests/testsuite/lints/implicit_features/edition_2021/mod.rs +++ /dev/null @@ -1,32 +0,0 @@ -use cargo_test_support::prelude::*; -use cargo_test_support::project; -use cargo_test_support::registry::Package; -use cargo_test_support::{file, str}; - -#[cargo_test] -fn case() { - Package::new("bar", "0.1.0").publish(); - let p = project() - .file( - "Cargo.toml", - r#" -[package] -name = "foo" -version = "0.1.0" -edition = "2021" - -[dependencies] -bar = { version = "0.1.0", optional = true } -"#, - ) - .file("src/lib.rs", "") - .build(); - - snapbox::cmd::Command::cargo_ui() - .current_dir(p.root()) - .arg("check") - .assert() - .success() - .stdout_matches(str![""]) - .stderr_matches(file!["stderr.term.svg"]); -} diff --git a/tests/testsuite/lints/implicit_features/edition_2021/stderr.term.svg b/tests/testsuite/lints/implicit_features/edition_2021/stderr.term.svg deleted file mode 100644 index f0726266833..00000000000 --- a/tests/testsuite/lints/implicit_features/edition_2021/stderr.term.svg +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - Updating `dummy-registry` index - - Locking 2 packages to latest compatible versions - - Checking foo v0.1.0 ([ROOT]/foo) - - Finished[..] - - - - - - diff --git a/tests/testsuite/lints/implicit_features/edition_2021_warn/mod.rs b/tests/testsuite/lints/implicit_features/edition_2021_warn/mod.rs deleted file mode 100644 index 45f29b029fa..00000000000 --- a/tests/testsuite/lints/implicit_features/edition_2021_warn/mod.rs +++ /dev/null @@ -1,45 +0,0 @@ -use cargo_test_support::prelude::*; -use cargo_test_support::registry::Package; -use cargo_test_support::str; -use cargo_test_support::{file, project}; - -#[cargo_test] -fn case() { - Package::new("bar", "0.1.0").publish(); - Package::new("baz", "0.1.0").publish(); - Package::new("target-dep", "0.1.0").publish(); - let p = project() - .file( - "Cargo.toml", - r#" -[package] -name = "foo" -version = "0.1.0" -edition = "2021" - -[dependencies] -bar = { version = "0.1.0", optional = true } - -[build-dependencies] -baz = { version = "0.1.0", optional = true } - -[target.'cfg(target_os = "linux")'.dependencies] -target-dep = { version = "0.1.0", optional = true } - -[lints.cargo] -implicit_features = "warn" -"#, - ) - .file("src/lib.rs", "") - .build(); - - snapbox::cmd::Command::cargo_ui() - .masquerade_as_nightly_cargo(&["cargo-lints"]) - .current_dir(p.root()) - .arg("check") - .arg("-Zcargo-lints") - .assert() - .success() - .stdout_matches(str![""]) - .stderr_matches(file!["stderr.term.svg"]); -} diff --git a/tests/testsuite/lints/implicit_features/edition_2021_warn/stderr.term.svg b/tests/testsuite/lints/implicit_features/edition_2021_warn/stderr.term.svg deleted file mode 100644 index 11affcc2ee0..00000000000 --- a/tests/testsuite/lints/implicit_features/edition_2021_warn/stderr.term.svg +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition - - --> Cargo.toml:8:1 - - | - - 8 | bar = { version = "0.1.0", optional = true } - - | --- - - | - - = note: `cargo::implicit_features` is set to `warn` in `[lints]` - - warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition - - --> Cargo.toml:11:1 - - | - - 11 | baz = { version = "0.1.0", optional = true } - - | --- - - | - - warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition - - --> Cargo.toml:14:1 - - | - - 14 | target-dep = { version = "0.1.0", optional = true } - - | ---------- - - | - - Updating `dummy-registry` index - - Locking 4 packages to latest compatible versions - - Checking foo v0.1.0 ([ROOT]/foo) - - Finished [..] - - - - - - diff --git a/tests/testsuite/lints/implicit_features/edition_2024/mod.rs b/tests/testsuite/lints/implicit_features/edition_2024/mod.rs deleted file mode 100644 index ca682aa8a5a..00000000000 --- a/tests/testsuite/lints/implicit_features/edition_2024/mod.rs +++ /dev/null @@ -1,43 +0,0 @@ -use cargo_test_support::prelude::*; -use cargo_test_support::registry::Package; -use cargo_test_support::str; -use cargo_test_support::{file, project}; - -#[cargo_test(nightly, reason = "edition2024 is not stable")] -fn case() { - Package::new("bar", "0.1.0").publish(); - Package::new("baz", "0.1.0").publish(); - let p = project() - .file( - "Cargo.toml", - r#" -cargo-features = ["edition2024"] -[package] -name = "foo" -version = "0.1.0" -edition = "2024" - -[dependencies] -bar = { version = "0.1.0", optional = true } -baz = { version = "0.1.0", optional = true } - -[features] -baz = ["dep:baz"] - -[lints.cargo] -unused_optional_dependency = "allow" -"#, - ) - .file("src/lib.rs", "") - .build(); - - snapbox::cmd::Command::cargo_ui() - .masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"]) - .current_dir(p.root()) - .arg("check") - .arg("-Zcargo-lints") - .assert() - .success() - .stdout_matches(str![""]) - .stderr_matches(file!["stderr.term.svg"]); -} diff --git a/tests/testsuite/lints/implicit_features/edition_2024/stderr.term.svg b/tests/testsuite/lints/implicit_features/edition_2024/stderr.term.svg deleted file mode 100644 index 6c0f3b67a55..00000000000 --- a/tests/testsuite/lints/implicit_features/edition_2024/stderr.term.svg +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - Updating `dummy-registry` index - - Locking 2 packages to latest Rust [..] compatible versions - - Checking foo v0.1.0 ([ROOT]/foo) - - Finished [..] - - - - - - diff --git a/tests/testsuite/lints/implicit_features/mod.rs b/tests/testsuite/lints/implicit_features/mod.rs deleted file mode 100644 index 3865b14a2ee..00000000000 --- a/tests/testsuite/lints/implicit_features/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod edition_2021; -mod edition_2021_warn; -mod edition_2024; diff --git a/tests/testsuite/lints/unknown_lints.rs b/tests/testsuite/lints/unknown_lints.rs new file mode 100644 index 00000000000..16411007539 --- /dev/null +++ b/tests/testsuite/lints/unknown_lints.rs @@ -0,0 +1,91 @@ +use cargo_test_support::project; + +#[cargo_test] +fn default() { + let p = project() + .file( + "Cargo.toml", + r#" +[package] +name = "foo" +version = "0.0.1" +edition = "2015" +authors = [] + +[lints.cargo] +this-lint-does-not-exist = "warn" +"#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints"]) + .with_stderr( + "\ +warning: unknown lint: `this-lint-does-not-exist` + --> Cargo.toml:9:1 + | +9 | this-lint-does-not-exist = \"warn\" + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `cargo::unknown_lints` is set to `warn` by default +[CHECKING] foo v0.0.1 ([CWD]) +[FINISHED] [..] +", + ) + .run(); +} + +#[cargo_test] +fn inherited() { + let p = project() + .file( + "Cargo.toml", + r#" +[workspace] +members = ["foo"] + +[workspace.lints.cargo] +this-lint-does-not-exist = "warn" +"#, + ) + .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_stderr( + "\ +warning: unknown lint: `this-lint-does-not-exist` + --> Cargo.toml:6:1 + | +6 | this-lint-does-not-exist = \"warn\" + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +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] [..] +", + ) + .run(); +} diff --git a/tests/testsuite/lints/unknown_lints/default/mod.rs b/tests/testsuite/lints/unknown_lints/default/mod.rs deleted file mode 100644 index d17596255ac..00000000000 --- a/tests/testsuite/lints/unknown_lints/default/mod.rs +++ /dev/null @@ -1,33 +0,0 @@ -use cargo_test_support::prelude::*; -use cargo_test_support::str; -use cargo_test_support::{file, project}; - -#[cargo_test] -fn case() { - let p = project() - .file( - "Cargo.toml", - r#" -[package] -name = "foo" -version = "0.0.1" -edition = "2015" -authors = [] - -[lints.cargo] -this-lint-does-not-exist = "warn" -"#, - ) - .file("src/lib.rs", "") - .build(); - - snapbox::cmd::Command::cargo_ui() - .masquerade_as_nightly_cargo(&["cargo-lints"]) - .current_dir(p.root()) - .arg("check") - .arg("-Zcargo-lints") - .assert() - .success() - .stdout_matches(str![""]) - .stderr_matches(file!["stderr.term.svg"]); -} diff --git a/tests/testsuite/lints/unknown_lints/default/stderr.term.svg b/tests/testsuite/lints/unknown_lints/default/stderr.term.svg deleted file mode 100644 index e3c89ca2cae..00000000000 --- a/tests/testsuite/lints/unknown_lints/default/stderr.term.svg +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - warning: unknown lint: `this-lint-does-not-exist` - - --> Cargo.toml:9:1 - - | - - 9 | this-lint-does-not-exist = "warn" - - | ^^^^^^^^^^^^^^^^^^^^^^^^ - - | - - = note: `cargo::unknown_lints` is set to `warn` by default - - Checking foo v0.0.1 ([ROOT]/foo) - - Finished [..] - - - - - - diff --git a/tests/testsuite/lints/unknown_lints/inherited/mod.rs b/tests/testsuite/lints/unknown_lints/inherited/mod.rs deleted file mode 100644 index 4138ab4f5f3..00000000000 --- a/tests/testsuite/lints/unknown_lints/inherited/mod.rs +++ /dev/null @@ -1,43 +0,0 @@ -use cargo_test_support::prelude::*; -use cargo_test_support::str; -use cargo_test_support::{file, project}; - -#[cargo_test] -fn case() { - let p = project() - .file( - "Cargo.toml", - r#" -[workspace] -members = ["foo"] - -[workspace.lints.cargo] -this-lint-does-not-exist = "warn" -"#, - ) - .file( - "foo/Cargo.toml", - r#" -[package] -name = "foo" -version = "0.0.1" -edition = "2015" -authors = [] - -[lints] -workspace = true - "#, - ) - .file("foo/src/lib.rs", "") - .build(); - - snapbox::cmd::Command::cargo_ui() - .masquerade_as_nightly_cargo(&["cargo-lints"]) - .current_dir(p.root()) - .arg("check") - .arg("-Zcargo-lints") - .assert() - .success() - .stdout_matches(str![""]) - .stderr_matches(file!["stderr.term.svg"]); -} diff --git a/tests/testsuite/lints/unknown_lints/inherited/stderr.term.svg b/tests/testsuite/lints/unknown_lints/inherited/stderr.term.svg deleted file mode 100644 index aef9e175faf..00000000000 --- a/tests/testsuite/lints/unknown_lints/inherited/stderr.term.svg +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - warning: unknown lint: `this-lint-does-not-exist` - - --> Cargo.toml:6:1 - - | - - 6 | this-lint-does-not-exist = "warn" - - | ^^^^^^^^^^^^^^^^^^^^^^^^ - - | - - 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 ([ROOT]/foo/foo) - - Finished [..] - - - - - - diff --git a/tests/testsuite/lints/unknown_lints/mod.rs b/tests/testsuite/lints/unknown_lints/mod.rs deleted file mode 100644 index 98324e98115..00000000000 --- a/tests/testsuite/lints/unknown_lints/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod default; -mod inherited; diff --git a/tests/testsuite/lints/unused_optional_dependencies.rs b/tests/testsuite/lints/unused_optional_dependencies.rs new file mode 100644 index 00000000000..5a60855220b --- /dev/null +++ b/tests/testsuite/lints/unused_optional_dependencies.rs @@ -0,0 +1,159 @@ +use cargo_test_support::project; +use cargo_test_support::registry::Package; + +#[cargo_test(nightly, reason = "edition2024 is not stable")] +fn default() { + Package::new("bar", "0.1.0").publish(); + Package::new("baz", "0.1.0").publish(); + Package::new("target-dep", "0.1.0").publish(); + let p = project() + .file( + "Cargo.toml", + r#" +cargo-features = ["edition2024"] +[package] +name = "foo" +version = "0.1.0" +edition = "2024" + +[dependencies] +bar = { version = "0.1.0", optional = true } + +[build-dependencies] +baz = { version = "0.1.0", optional = true } + +[target.'cfg(target_os = "linux")'.dependencies] +target-dep = { version = "0.1.0", optional = true } +"#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"]) + .with_stderr( + "\ +warning: unused optional dependency + --> Cargo.toml:9:1 + | +9 | bar = { version = \"0.1.0\", optional = true } + | --- + | + = note: `cargo::unused_optional_dependency` is set to `warn` by default + = help: remove the dependency or activate it in a feature with `dep:bar` +warning: unused optional dependency + --> Cargo.toml:12:1 + | +12 | baz = { version = \"0.1.0\", optional = true } + | --- + | + = help: remove the dependency or activate it in a feature with `dep:baz` +warning: unused optional dependency + --> Cargo.toml:15:1 + | +15 | target-dep = { version = \"0.1.0\", optional = true } + | ---------- + | + = help: remove the dependency or activate it in a feature with `dep:target-dep` +[CHECKING] foo v0.1.0 ([CWD]) +[FINISHED] [..] +", + ) + .run(); +} + +#[cargo_test] +fn edition_2021() { + Package::new("bar", "0.1.0").publish(); + let p = project() + .file( + "Cargo.toml", + r#" +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +[dependencies] +bar = { version = "0.1.0", optional = true } + +[lints.cargo] +implicit_features = "allow" +"#, + ) + .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 +[CHECKING] foo v0.1.0 ([CWD]) +[FINISHED] [..] +", + ) + .run(); +} + +#[cargo_test(nightly, reason = "edition2024 is not stable")] +fn renamed_deps() { + Package::new("bar", "0.1.0").publish(); + Package::new("bar", "0.2.0").publish(); + Package::new("target-dep", "0.1.0").publish(); + let p = project() + .file( + "Cargo.toml", + r#" +cargo-features = ["edition2024"] +[package] +name = "foo" +version = "0.1.0" +edition = "2024" + +[dependencies] +bar = { version = "0.1.0", optional = true } + +[build-dependencies] +baz = { version = "0.2.0", package = "bar", optional = true } + +[target.'cfg(target_os = "linux")'.dependencies] +target-dep = { version = "0.1.0", optional = true } +"#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"]) + .with_stderr( + "\ +warning: unused optional dependency + --> Cargo.toml:9:1 + | +9 | bar = { version = \"0.1.0\", optional = true } + | --- + | + = note: `cargo::unused_optional_dependency` is set to `warn` by default + = help: remove the dependency or activate it in a feature with `dep:bar` +warning: unused optional dependency + --> Cargo.toml:12:1 + | +12 | baz = { version = \"0.2.0\", package = \"bar\", optional = true } + | --- + | + = help: remove the dependency or activate it in a feature with `dep:baz` +warning: unused optional dependency + --> Cargo.toml:15:1 + | +15 | target-dep = { version = \"0.1.0\", optional = true } + | ---------- + | + = help: remove the dependency or activate it in a feature with `dep:target-dep` +[CHECKING] foo v0.1.0 ([CWD]) +[FINISHED] [..] +", + ) + .run(); +} diff --git a/tests/testsuite/lints/unused_optional_dependencies/edition_2021/mod.rs b/tests/testsuite/lints/unused_optional_dependencies/edition_2021/mod.rs deleted file mode 100644 index 9a454b19131..00000000000 --- a/tests/testsuite/lints/unused_optional_dependencies/edition_2021/mod.rs +++ /dev/null @@ -1,37 +0,0 @@ -use cargo_test_support::prelude::*; -use cargo_test_support::project; -use cargo_test_support::registry::Package; -use cargo_test_support::{file, str}; - -#[cargo_test] -fn case() { - Package::new("bar", "0.1.0").publish(); - let p = project() - .file( - "Cargo.toml", - r#" -[package] -name = "foo" -version = "0.1.0" -edition = "2021" - -[dependencies] -bar = { version = "0.1.0", optional = true } - -[lints.cargo] -implicit_features = "allow" -"#, - ) - .file("src/lib.rs", "") - .build(); - - snapbox::cmd::Command::cargo_ui() - .masquerade_as_nightly_cargo(&["cargo-lints"]) - .current_dir(p.root()) - .arg("check") - .arg("-Zcargo-lints") - .assert() - .success() - .stdout_matches(str![""]) - .stderr_matches(file!["stderr.term.svg"]); -} diff --git a/tests/testsuite/lints/unused_optional_dependencies/edition_2021/stderr.term.svg b/tests/testsuite/lints/unused_optional_dependencies/edition_2021/stderr.term.svg deleted file mode 100644 index ccbdeac1b7b..00000000000 --- a/tests/testsuite/lints/unused_optional_dependencies/edition_2021/stderr.term.svg +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - Updating `dummy-registry` index - - Locking 2 packages to latest compatible versions - - Checking foo v0.1.0 ([ROOT]/foo) - - Finished [..] - - - - - - diff --git a/tests/testsuite/lints/unused_optional_dependencies/edition_2024/mod.rs b/tests/testsuite/lints/unused_optional_dependencies/edition_2024/mod.rs deleted file mode 100644 index 3ff9504035d..00000000000 --- a/tests/testsuite/lints/unused_optional_dependencies/edition_2024/mod.rs +++ /dev/null @@ -1,56 +0,0 @@ -use cargo_test_support::compare::assert_match_exact; -use cargo_test_support::prelude::*; -use cargo_test_support::registry::Package; -use cargo_test_support::str; -use cargo_test_support::{file, project}; - -#[cargo_test(nightly, reason = "edition2024 is not stable")] -fn case() { - Package::new("bar", "0.1.0").publish(); - Package::new("baz", "0.1.0").publish(); - Package::new("target-dep", "0.1.0").publish(); - let p = project() - .file( - "Cargo.toml", - r#" -cargo-features = ["edition2024"] -[package] -name = "foo" -version = "0.1.0" -edition = "2024" - -[dependencies] -bar = { version = "0.1.0", optional = true } - -[build-dependencies] -baz = { version = "0.1.0", optional = true } - -[target.'cfg(target_os = "linux")'.dependencies] -target-dep = { version = "0.1.0", optional = true } -"#, - ) - .file("src/lib.rs", "") - .build(); - - snapbox::cmd::Command::cargo_ui() - .masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"]) - .current_dir(p.root()) - .arg("check") - .arg("-Zcargo-lints") - .assert() - .success() - .stdout_matches(str![""]) - .stderr_matches(file!["stderr.term.svg"]); - - let expected_lockfile = r#"# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "foo" -version = "0.1.0" -"#; - - let lock = p.read_lockfile(); - assert_match_exact(expected_lockfile, &lock); -} diff --git a/tests/testsuite/lints/unused_optional_dependencies/edition_2024/stderr.term.svg b/tests/testsuite/lints/unused_optional_dependencies/edition_2024/stderr.term.svg deleted file mode 100644 index 84eddf6de57..00000000000 --- a/tests/testsuite/lints/unused_optional_dependencies/edition_2024/stderr.term.svg +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - warning: unused optional dependency - - --> Cargo.toml:9:1 - - | - - 9 | bar = { version = "0.1.0", optional = true } - - | --- - - | - - = note: `cargo::unused_optional_dependency` is set to `warn` by default - - = help: remove the dependency or activate it in a feature with `dep:bar` - - warning: unused optional dependency - - --> Cargo.toml:12:1 - - | - - 12 | baz = { version = "0.1.0", optional = true } - - | --- - - | - - = help: remove the dependency or activate it in a feature with `dep:baz` - - warning: unused optional dependency - - --> Cargo.toml:15:1 - - | - - 15 | target-dep = { version = "0.1.0", optional = true } - - | ---------- - - | - - = help: remove the dependency or activate it in a feature with `dep:target-dep` - - Checking foo v0.1.0 ([ROOT]/foo) - - Finished [..] - - - - - - diff --git a/tests/testsuite/lints/unused_optional_dependencies/mod.rs b/tests/testsuite/lints/unused_optional_dependencies/mod.rs deleted file mode 100644 index 9a22119becf..00000000000 --- a/tests/testsuite/lints/unused_optional_dependencies/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod edition_2021; -mod edition_2024; -mod renamed_deps; diff --git a/tests/testsuite/lints/unused_optional_dependencies/renamed_deps/mod.rs b/tests/testsuite/lints/unused_optional_dependencies/renamed_deps/mod.rs deleted file mode 100644 index 08e871df2fc..00000000000 --- a/tests/testsuite/lints/unused_optional_dependencies/renamed_deps/mod.rs +++ /dev/null @@ -1,43 +0,0 @@ -use cargo_test_support::prelude::*; -use cargo_test_support::registry::Package; -use cargo_test_support::str; -use cargo_test_support::{file, project}; - -#[cargo_test(nightly, reason = "edition2024 is not stable")] -fn case() { - Package::new("bar", "0.1.0").publish(); - Package::new("bar", "0.2.0").publish(); - Package::new("target-dep", "0.1.0").publish(); - let p = project() - .file( - "Cargo.toml", - r#" -cargo-features = ["edition2024"] -[package] -name = "foo" -version = "0.1.0" -edition = "2024" - -[dependencies] -bar = { version = "0.1.0", optional = true } - -[build-dependencies] -baz = { version = "0.2.0", package = "bar", optional = true } - -[target.'cfg(target_os = "linux")'.dependencies] -target-dep = { version = "0.1.0", optional = true } -"#, - ) - .file("src/lib.rs", "") - .build(); - - snapbox::cmd::Command::cargo_ui() - .masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"]) - .current_dir(p.root()) - .arg("check") - .arg("-Zcargo-lints") - .assert() - .success() - .stdout_matches(str![""]) - .stderr_matches(file!["stderr.term.svg"]); -} diff --git a/tests/testsuite/lints/unused_optional_dependencies/renamed_deps/stderr.term.svg b/tests/testsuite/lints/unused_optional_dependencies/renamed_deps/stderr.term.svg deleted file mode 100644 index 2f1c99bec30..00000000000 --- a/tests/testsuite/lints/unused_optional_dependencies/renamed_deps/stderr.term.svg +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - warning: unused optional dependency - - --> Cargo.toml:9:1 - - | - - 9 | bar = { version = "0.1.0", optional = true } - - | --- - - | - - = note: `cargo::unused_optional_dependency` is set to `warn` by default - - = help: remove the dependency or activate it in a feature with `dep:bar` - - warning: unused optional dependency - - --> Cargo.toml:12:1 - - | - - 12 | baz = { version = "0.2.0", package = "bar", optional = true } - - | --- - - | - - = help: remove the dependency or activate it in a feature with `dep:baz` - - warning: unused optional dependency - - --> Cargo.toml:15:1 - - | - - 15 | target-dep = { version = "0.1.0", optional = true } - - | ---------- - - | - - = help: remove the dependency or activate it in a feature with `dep:target-dep` - - Checking foo v0.1.0 ([ROOT]/foo) - - Finished [..] - - - - - - From 6f81cff16c3e63972944a09e9c384db7c7d6dabc Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Wed, 8 May 2024 15:18:49 -0600 Subject: [PATCH 2/3] refactor: Move lint specific tests to lints/mod.rs --- tests/testsuite/lints/mod.rs | 327 +++++++++++++++++++++++++++++++++ tests/testsuite/lints_table.rs | 324 -------------------------------- 2 files changed, 327 insertions(+), 324 deletions(-) diff --git a/tests/testsuite/lints/mod.rs b/tests/testsuite/lints/mod.rs index 1daa7b7a340..9a450aef96f 100644 --- a/tests/testsuite/lints/mod.rs +++ b/tests/testsuite/lints/mod.rs @@ -1,3 +1,330 @@ +use cargo_test_support::project; +use cargo_test_support::registry::Package; + mod implicit_features; mod unknown_lints; mod unused_optional_dependencies; + +#[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_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 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/lints_table.rs b/tests/testsuite/lints_table.rs index 6ebdda1a35b..cb376b18213 100644 --- a/tests/testsuite/lints_table.rs +++ b/tests/testsuite/lints_table.rs @@ -856,327 +856,3 @@ warning: `im_a_teapot` is specified ) .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(); -} From b79fd591ce1bb95b4de672fd8a833da097120618 Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Wed, 8 May 2024 22:42:35 -0600 Subject: [PATCH 3/3] test: Add UI tests showing parts of diagnostic system --- tests/testsuite/lints/error/mod.rs | 36 ++++++++++++ tests/testsuite/lints/error/stderr.term.svg | 41 +++++++++++++ tests/testsuite/lints/inherited/mod.rs | 43 ++++++++++++++ .../testsuite/lints/inherited/stderr.term.svg | 57 +++++++++++++++++++ tests/testsuite/lints/mod.rs | 3 + tests/testsuite/lints/warning/mod.rs | 36 ++++++++++++ tests/testsuite/lints/warning/stderr.term.svg | 46 +++++++++++++++ 7 files changed, 262 insertions(+) create mode 100644 tests/testsuite/lints/error/mod.rs create mode 100644 tests/testsuite/lints/error/stderr.term.svg create mode 100644 tests/testsuite/lints/inherited/mod.rs create mode 100644 tests/testsuite/lints/inherited/stderr.term.svg create mode 100644 tests/testsuite/lints/warning/mod.rs create mode 100644 tests/testsuite/lints/warning/stderr.term.svg diff --git a/tests/testsuite/lints/error/mod.rs b/tests/testsuite/lints/error/mod.rs new file mode 100644 index 00000000000..c80c38313ca --- /dev/null +++ b/tests/testsuite/lints/error/mod.rs @@ -0,0 +1,36 @@ +use cargo_test_support::prelude::*; +use cargo_test_support::str; +use cargo_test_support::{file, project}; + +#[cargo_test] +fn case() { + 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 = "deny" + "#, + ) + .file("src/lib.rs", "") + .build(); + + snapbox::cmd::Command::cargo_ui() + .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) + .current_dir(p.root()) + .arg("check") + .arg("-Zcargo-lints") + .assert() + .code(101) + .stdout_matches(str![""]) + .stderr_matches(file!["stderr.term.svg"]); +} diff --git a/tests/testsuite/lints/error/stderr.term.svg b/tests/testsuite/lints/error/stderr.term.svg new file mode 100644 index 00000000000..1dba018ceac --- /dev/null +++ b/tests/testsuite/lints/error/stderr.term.svg @@ -0,0 +1,41 @@ + + + + + + + error: `im_a_teapot` is specified + + --> Cargo.toml:9:1 + + | + + 9 | im-a-teapot = true + + | ^^^^^^^^^^^^^^^^^^ + + | + + = note: `cargo::im_a_teapot` is set to `deny` in `[lints]` + + + + + + diff --git a/tests/testsuite/lints/inherited/mod.rs b/tests/testsuite/lints/inherited/mod.rs new file mode 100644 index 00000000000..5085bea3748 --- /dev/null +++ b/tests/testsuite/lints/inherited/mod.rs @@ -0,0 +1,43 @@ +use cargo_test_support::prelude::*; +use cargo_test_support::str; +use cargo_test_support::{file, project}; + +#[cargo_test] +fn case() { + let p = project() + .file( + "Cargo.toml", + r#" +[workspace] +members = ["foo"] + +[workspace.lints.cargo] +im_a_teapot = { level = "warn", priority = 10 } +"#, + ) + .file( + "foo/Cargo.toml", + r#" +[package] +name = "foo" +version = "0.0.1" +edition = "2015" +authors = [] + +[lints] +workspace = true +"#, + ) + .file("foo/src/lib.rs", "") + .build(); + + snapbox::cmd::Command::cargo_ui() + .masquerade_as_nightly_cargo(&["cargo-lints"]) + .current_dir(p.root()) + .arg("check") + .arg("-Zcargo-lints") + .assert() + .code(101) + .stdout_matches(str![""]) + .stderr_matches(file!["stderr.term.svg"]); +} diff --git a/tests/testsuite/lints/inherited/stderr.term.svg b/tests/testsuite/lints/inherited/stderr.term.svg new file mode 100644 index 00000000000..a37bba4c1c7 --- /dev/null +++ b/tests/testsuite/lints/inherited/stderr.term.svg @@ -0,0 +1,57 @@ + + + + + + + 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: encountered 1 errors(s) while verifying lints + + + + + + diff --git a/tests/testsuite/lints/mod.rs b/tests/testsuite/lints/mod.rs index 9a450aef96f..ea1dc25b70f 100644 --- a/tests/testsuite/lints/mod.rs +++ b/tests/testsuite/lints/mod.rs @@ -1,9 +1,12 @@ use cargo_test_support::project; use cargo_test_support::registry::Package; +mod error; mod implicit_features; +mod inherited; mod unknown_lints; mod unused_optional_dependencies; +mod warning; #[cargo_test] fn dashes_dont_get_rewritten() { diff --git a/tests/testsuite/lints/warning/mod.rs b/tests/testsuite/lints/warning/mod.rs new file mode 100644 index 00000000000..503261056e1 --- /dev/null +++ b/tests/testsuite/lints/warning/mod.rs @@ -0,0 +1,36 @@ +use cargo_test_support::prelude::*; +use cargo_test_support::str; +use cargo_test_support::{file, project}; + +#[cargo_test] +fn case() { + 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(); + + snapbox::cmd::Command::cargo_ui() + .masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) + .current_dir(p.root()) + .arg("check") + .arg("-Zcargo-lints") + .assert() + .success() + .stdout_matches(str![""]) + .stderr_matches(file!["stderr.term.svg"]); +} diff --git a/tests/testsuite/lints/warning/stderr.term.svg b/tests/testsuite/lints/warning/stderr.term.svg new file mode 100644 index 00000000000..91ac9abde01 --- /dev/null +++ b/tests/testsuite/lints/warning/stderr.term.svg @@ -0,0 +1,46 @@ + + + + + + + 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 ([ROOT]/foo) + + Finished [..] + + + + + +