diff options
Diffstat (limited to 'xtask/tests')
-rw-r--r-- | xtask/tests/tidy.rs | 87 |
1 files changed, 59 insertions, 28 deletions
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index 4ac5d929f..72088e414 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs | |||
@@ -5,7 +5,7 @@ use std::{ | |||
5 | 5 | ||
6 | use xtask::{ | 6 | use xtask::{ |
7 | codegen::{self, Mode}, | 7 | codegen::{self, Mode}, |
8 | not_bash::fs2, | 8 | not_bash::{fs2, run}, |
9 | project_root, run_rustfmt, rust_files, | 9 | project_root, run_rustfmt, rust_files, |
10 | }; | 10 | }; |
11 | 11 | ||
@@ -25,19 +25,12 @@ fn generated_tests_are_fresh() { | |||
25 | 25 | ||
26 | #[test] | 26 | #[test] |
27 | fn generated_assists_are_fresh() { | 27 | fn generated_assists_are_fresh() { |
28 | if let Err(error) = codegen::generate_assists_docs(Mode::Verify) { | 28 | if let Err(error) = codegen::generate_assists_tests(Mode::Verify) { |
29 | panic!("{}. Please update assists by running `cargo xtask codegen`", error); | 29 | panic!("{}. Please update assists by running `cargo xtask codegen`", error); |
30 | } | 30 | } |
31 | } | 31 | } |
32 | 32 | ||
33 | #[test] | 33 | #[test] |
34 | fn generated_features_are_fresh() { | ||
35 | if let Err(error) = codegen::generate_feature_docs(Mode::Verify) { | ||
36 | panic!("{}. Please update features by running `cargo xtask codegen`", error); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | #[test] | ||
41 | fn check_code_formatting() { | 34 | fn check_code_formatting() { |
42 | if let Err(error) = run_rustfmt(Mode::Verify) { | 35 | if let Err(error) = run_rustfmt(Mode::Verify) { |
43 | panic!("{}. Please format the code by running `cargo format`", error); | 36 | panic!("{}. Please format the code by running `cargo format`", error); |
@@ -56,19 +49,59 @@ fn rust_files_are_tidy() { | |||
56 | tidy_docs.finish(); | 49 | tidy_docs.finish(); |
57 | } | 50 | } |
58 | 51 | ||
52 | #[test] | ||
53 | fn check_licenses() { | ||
54 | let expected = " | ||
55 | 0BSD OR MIT OR Apache-2.0 | ||
56 | Apache-2.0 | ||
57 | Apache-2.0 / MIT | ||
58 | Apache-2.0 OR BSL-1.0 | ||
59 | Apache-2.0 OR MIT | ||
60 | Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT | ||
61 | Apache-2.0/MIT | ||
62 | BSD-2-Clause | ||
63 | BSD-3-Clause | ||
64 | CC0-1.0 | ||
65 | ISC | ||
66 | MIT | ||
67 | MIT / Apache-2.0 | ||
68 | MIT OR Apache-2.0 | ||
69 | MIT/Apache-2.0 | ||
70 | MIT/Apache-2.0 AND BSD-2-Clause | ||
71 | Unlicense OR MIT | ||
72 | Unlicense/MIT | ||
73 | Zlib | ||
74 | " | ||
75 | .lines() | ||
76 | .filter(|it| !it.is_empty()) | ||
77 | .collect::<Vec<_>>(); | ||
78 | |||
79 | let meta = run!("cargo metadata --format-version 1"; echo = false).unwrap(); | ||
80 | let mut licenses = meta | ||
81 | .split(|c| c == ',' || c == '{' || c == '}') | ||
82 | .filter(|it| it.contains(r#""license""#)) | ||
83 | .map(|it| it.trim()) | ||
84 | .map(|it| it[r#""license":"#.len()..].trim_matches('"')) | ||
85 | .collect::<Vec<_>>(); | ||
86 | licenses.sort(); | ||
87 | licenses.dedup(); | ||
88 | assert_eq!(licenses, expected); | ||
89 | } | ||
90 | |||
59 | fn check_todo(path: &Path, text: &str) { | 91 | fn check_todo(path: &Path, text: &str) { |
60 | let whitelist = &[ | 92 | let need_todo = &[ |
61 | // This file itself is whitelisted since this test itself contains matches. | 93 | // This file itself obviously needs to use todo (<- like this!). |
62 | "tests/cli.rs", | 94 | "tests/cli.rs", |
63 | // Some of our assists generate `todo!()` so those files are whitelisted. | 95 | // Some of our assists generate `todo!()`. |
64 | "tests/generated.rs", | 96 | "tests/generated.rs", |
65 | "handlers/add_missing_impl_members.rs", | 97 | "handlers/add_missing_impl_members.rs", |
66 | "handlers/add_function.rs", | ||
67 | "handlers/add_turbo_fish.rs", | 98 | "handlers/add_turbo_fish.rs", |
68 | // To support generating `todo!()` in assists, we have `expr_todo()` in ast::make. | 99 | "handlers/generate_function.rs", |
100 | // To support generating `todo!()` in assists, we have `expr_todo()` in | ||
101 | // `ast::make`. | ||
69 | "ast/make.rs", | 102 | "ast/make.rs", |
70 | ]; | 103 | ]; |
71 | if whitelist.iter().any(|p| path.ends_with(p)) { | 104 | if need_todo.iter().any(|p| path.ends_with(p)) { |
72 | return; | 105 | return; |
73 | } | 106 | } |
74 | if text.contains("TODO") || text.contains("TOOD") || text.contains("todo!") { | 107 | if text.contains("TODO") || text.contains("TOOD") || text.contains("todo!") { |
@@ -146,7 +179,7 @@ impl TidyDocs { | |||
146 | ) | 179 | ) |
147 | } | 180 | } |
148 | 181 | ||
149 | let whitelist = [ | 182 | let poorly_documented = [ |
150 | "ra_hir", | 183 | "ra_hir", |
151 | "ra_hir_expand", | 184 | "ra_hir_expand", |
152 | "ra_ide", | 185 | "ra_ide", |
@@ -160,9 +193,9 @@ impl TidyDocs { | |||
160 | ]; | 193 | ]; |
161 | 194 | ||
162 | let mut has_fixmes = | 195 | let mut has_fixmes = |
163 | whitelist.iter().map(|it| (*it, false)).collect::<HashMap<&str, bool>>(); | 196 | poorly_documented.iter().map(|it| (*it, false)).collect::<HashMap<&str, bool>>(); |
164 | 'outer: for path in self.contains_fixme { | 197 | 'outer: for path in self.contains_fixme { |
165 | for krate in whitelist.iter() { | 198 | for krate in poorly_documented.iter() { |
166 | if path.components().any(|it| it.as_os_str() == *krate) { | 199 | if path.components().any(|it| it.as_os_str() == *krate) { |
167 | has_fixmes.insert(krate, true); | 200 | has_fixmes.insert(krate, true); |
168 | continue 'outer; | 201 | continue 'outer; |
@@ -173,20 +206,18 @@ impl TidyDocs { | |||
173 | 206 | ||
174 | for (krate, has_fixme) in has_fixmes.iter() { | 207 | for (krate, has_fixme) in has_fixmes.iter() { |
175 | if !has_fixme { | 208 | if !has_fixme { |
176 | panic!("crate {} is fully documented, remove it from the white list", krate) | 209 | panic!("crate {} is fully documented :tada:, remove it from the list of poorly documented crates", krate) |
177 | } | 210 | } |
178 | } | 211 | } |
179 | } | 212 | } |
180 | } | 213 | } |
181 | 214 | ||
182 | fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool { | 215 | fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool { |
183 | let mut cur_path = p; | 216 | p.strip_prefix(project_root()) |
184 | while let Some(path) = cur_path.parent() { | 217 | .unwrap() |
185 | if dirs_to_exclude.iter().any(|dir| path.ends_with(dir)) { | 218 | .components() |
186 | return true; | 219 | .rev() |
187 | } | 220 | .skip(1) |
188 | cur_path = path; | 221 | .filter_map(|it| it.as_os_str().to_str()) |
189 | } | 222 | .any(|it| dirs_to_exclude.contains(&it)) |
190 | |||
191 | false | ||
192 | } | 223 | } |