]> git.lizzy.rs Git - rust.git/commitdiff
Relax fs layout so that multiple pass/fail manifests are possible
authorEduardo Broto <ebroto@tutanota.com>
Thu, 21 May 2020 13:34:48 +0000 (15:34 +0200)
committerEduardo Broto <ebroto@tutanota.com>
Thu, 21 May 2020 13:34:48 +0000 (15:34 +0200)
doc/adding_lints.md
tests/compile-test.rs

index 75768681db93c7ed34a133602e403feb103f3b3d..b3f5a62d55307798298c250ae6d5524c633cc427 100644 (file)
@@ -43,7 +43,7 @@ case), and we don't need type information so it will have an early pass type
 (category will default to nursery if not provided). This command will create
 two files: `tests/ui/foo_functions.rs` and `clippy_lints/src/foo_functions.rs`,
 as well as run `cargo dev update_lints` to register the new lint. For cargo lints,
-two project hierarchies (fail/pass) will be created under `tests/ui-cargo`.
+two project hierarchies (fail/pass) will be created by default under `tests/ui-cargo`.
 
 Next, we'll open up these files and add our lint!
 
@@ -110,12 +110,17 @@ specific lint you are creating/editing.
 ### Cargo lints
 
 For cargo lints, the process of testing differs in that we are interested in
-the contents of the `Cargo.toml` files. If our new lint is named e.g. `foo_categories`,
-after running `cargo dev new_lint` we will find two new manifest files:
+the `Cargo.toml` manifest file. We also need a minimal crate associated
+with that manifest.
+
+If our new lint is named e.g. `foo_categories`, after running `cargo dev new_lint` 
+we will find by default two new crates, each with its manifest file:
 
 * `tests/ui-cargo/foo_categories/fail/Cargo.toml`: this file should cause the new lint to raise an error.
 * `tests/ui-cargo/foo_categories/pass/Cargo.toml`: this file should not trigger the lint.
 
+If you need more cases, you can copy one of those crates (under `foo_categories`) and rename it.
+
 The process of generating the `.stderr` file is the same, and prepending the `TESTNAME`
 variable to `cargo uitest` works too, but the script to update the references
 is in another path: `tests/ui-cargo/update-all-references.sh`.
index 232b966f69a1f1406dddf541553dcb5326e3e14f..a5de84293909f24c8e99b77aedb8c6e3afd8be08 100644 (file)
@@ -174,9 +174,13 @@ fn run_tests(
                 _ => {},
             }
 
-            for case in &["pass", "fail"] {
-                let tail: PathBuf = [case, "src"].iter().collect();
-                let src_path = dir_path.join(tail);
+            for case in fs::read_dir(&dir_path)? {
+                let case = case?;
+                if !case.file_type()?.is_dir() {
+                    continue;
+                }
+
+                let src_path = case.path().join("src");
                 env::set_current_dir(&src_path)?;
 
                 for file in fs::read_dir(&src_path)? {