-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #13880 - Muscraft:refactor-cargo-lint-tests, r=weihanglo
Refactor cargo lint tests In #13621, it was brought up that [the lints tests are nested more deeply than other UI tests](#13621 (comment)). This got me wondering if there was a better way to structure all the lint tests. What I came up with was: - Lints should not have UI tests, only parts of the diagnostic system, i.e., how warnings, errors, notes, etc., look - This is because UI tests should focus on parts of the system that make up each lint's output - We can always add UI tests for each lint if desired - All tests related to the linting system should live in `tests/testsuite/lints/` - Tests related to `[lints.cargo]` should stay in `lints_table.rs` as it is for the whole lints table - Each lint will get a file in `lints/` for all of its tests - This makes `lints/mod.rs` smaller and targeted only at tests for the linting system itself - It makes it much easier to know where to place a test
- Loading branch information
Showing
25 changed files
with
793 additions
and
914 deletions.
There are no files selected for viewing
25 changes: 12 additions & 13 deletions
25
...optional_dependencies/edition_2021/mod.rs → tests/testsuite/lints/error/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,36 @@ | ||
use cargo_test_support::prelude::*; | ||
use cargo_test_support::project; | ||
use cargo_test_support::registry::Package; | ||
use cargo_test_support::{file, str}; | ||
use cargo_test_support::str; | ||
use cargo_test_support::{file, project}; | ||
|
||
#[cargo_test] | ||
fn case() { | ||
Package::new("bar", "0.1.0").publish(); | ||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
cargo-features = ["test-dummy-unstable"] | ||
[package] | ||
name = "foo" | ||
version = "0.1.0" | ||
edition = "2021" | ||
[dependencies] | ||
bar = { version = "0.1.0", optional = true } | ||
version = "0.0.1" | ||
edition = "2015" | ||
authors = [] | ||
im-a-teapot = true | ||
[lints.cargo] | ||
implicit_features = "allow" | ||
"#, | ||
im_a_teapot = "deny" | ||
"#, | ||
) | ||
.file("src/lib.rs", "") | ||
.build(); | ||
|
||
snapbox::cmd::Command::cargo_ui() | ||
.masquerade_as_nightly_cargo(&["cargo-lints"]) | ||
.masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"]) | ||
.current_dir(p.root()) | ||
.arg("check") | ||
.arg("-Zcargo-lints") | ||
.assert() | ||
.success() | ||
.code(101) | ||
.stdout_matches(str![""]) | ||
.stderr_matches(file!["stderr.term.svg"]); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
32 changes: 0 additions & 32 deletions
32
tests/testsuite/lints/implicit_features/edition_2021/mod.rs
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
tests/testsuite/lints/implicit_features/edition_2021/stderr.term.svg
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
tests/testsuite/lints/implicit_features/edition_2021_warn/mod.rs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.