Skip to content

Commit 5d0135e

Browse files
committed
Add documentation for testing cargo lints
1 parent 1eb6adf commit 5d0135e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

doc/adding_lints.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ case), and we don't need type information so it will have an early pass type
4242
`cargo dev new_lint --name=foo_functions --pass=early --category=pedantic`
4343
(category will default to nursery if not provided). This command will create
4444
two files: `tests/ui/foo_functions.rs` and `clippy_lints/src/foo_functions.rs`,
45-
as well as run `cargo dev update_lints` to register the new lint. Next, we'll
46-
open up these files and add our lint!
45+
as well as run `cargo dev update_lints` to register the new lint. For cargo lints,
46+
two project hierarchies (fail/pass) will be created under `tests/ui-cargo`.
47+
48+
Next, we'll open up these files and add our lint!
4749

4850
## Testing
4951

@@ -105,6 +107,19 @@ our lint, we need to commit the generated `.stderr` files, too. In general, you
105107
should only commit files changed by `tests/ui/update-all-references.sh` for the
106108
specific lint you are creating/editing.
107109

110+
### Cargo lints
111+
112+
For cargo lints, the process of testing differs in that we are interested in
113+
the contents of the `Cargo.toml` files. If our new lint is named e.g. `foo_categories`,
114+
after running `cargo dev new_lint` we will find two new manifest files:
115+
116+
* `tests/ui-cargo/foo_categories/fail/Cargo.toml`: this file should cause the new lint to raise an error.
117+
* `tests/ui-cargo/foo_categories/pass/Cargo.toml`: this file should not trigger the lint.
118+
119+
The process of generating the `.stderr` file is the same, and prepending the `TESTNAME`
120+
variable to `cargo uitest` works too, but the script to update the references
121+
is in another path: `tests/ui-cargo/update-all-references.sh`.
122+
108123
## Rustfix tests
109124

110125
If the lint you are working on is making use of structured suggestions, the

0 commit comments

Comments
 (0)