Skip to content

Commit f9013ff

Browse files
committed
Relax fs layout so that multiple pass/fail manifests are possible
1 parent 1a04686 commit f9013ff

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

doc/adding_lints.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ case), and we don't need type information so it will have an early pass type
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`,
4545
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`.
46+
two project hierarchies (fail/pass) will be created by default under `tests/ui-cargo`.
4747

4848
Next, we'll open up these files and add our lint!
4949

@@ -110,12 +110,17 @@ specific lint you are creating/editing.
110110
### Cargo lints
111111

112112
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:
113+
the `Cargo.toml` manifest file. We also need a minimal crate associated
114+
with that manifest.
115+
116+
If our new lint is named e.g. `foo_categories`, after running `cargo dev new_lint`
117+
we will find by default two new crates, each with its manifest file:
115118

116119
* `tests/ui-cargo/foo_categories/fail/Cargo.toml`: this file should cause the new lint to raise an error.
117120
* `tests/ui-cargo/foo_categories/pass/Cargo.toml`: this file should not trigger the lint.
118121

122+
If you need more cases, you can copy one of those crates (under `foo_categories`) and rename it.
123+
119124
The process of generating the `.stderr` file is the same, and prepending the `TESTNAME`
120125
variable to `cargo uitest` works too, but the script to update the references
121126
is in another path: `tests/ui-cargo/update-all-references.sh`.

tests/compile-test.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,13 @@ fn run_ui_cargo(config: &mut compiletest::Config) {
174174
_ => {},
175175
}
176176

177-
for case in &["pass", "fail"] {
178-
let tail: PathBuf = [case, "src"].iter().collect();
179-
let src_path = dir_path.join(tail);
177+
for case in fs::read_dir(&dir_path)? {
178+
let case = case?;
179+
if !case.file_type()?.is_dir() {
180+
continue;
181+
}
182+
183+
let src_path = case.path().join("src");
180184
env::set_current_dir(&src_path)?;
181185

182186
for file in fs::read_dir(&src_path)? {

0 commit comments

Comments
 (0)