aboutsummaryrefslogtreecommitdiff
path: root/xtask/tests
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/tests')
-rw-r--r--xtask/tests/tidy-tests/main.rs47
1 files changed, 31 insertions, 16 deletions
diff --git a/xtask/tests/tidy-tests/main.rs b/xtask/tests/tidy-tests/main.rs
index 2d2d88bec..5ae86c87c 100644
--- a/xtask/tests/tidy-tests/main.rs
+++ b/xtask/tests/tidy-tests/main.rs
@@ -14,6 +14,7 @@ fn rust_files_are_tidy() {
14 for path in rust_files() { 14 for path in rust_files() {
15 let text = fs2::read_to_string(&path).unwrap(); 15 let text = fs2::read_to_string(&path).unwrap();
16 check_todo(&path, &text); 16 check_todo(&path, &text);
17 check_trailing_ws(&path, &text);
17 tidy_docs.visit(&path, &text); 18 tidy_docs.visit(&path, &text);
18 } 19 }
19 tidy_docs.finish(); 20 tidy_docs.finish();
@@ -33,6 +34,17 @@ fn check_todo(path: &Path, text: &str) {
33 } 34 }
34} 35}
35 36
37fn check_trailing_ws(path: &Path, text: &str) {
38 if is_exclude_dir(path, &["test_data"]) {
39 return;
40 }
41 for line in text.lines() {
42 if line.chars().last().map(char::is_whitespace) == Some(true) {
43 panic!("Trailing whitespace in {}", path.display())
44 }
45 }
46}
47
36#[derive(Default)] 48#[derive(Default)]
37struct TidyDocs { 49struct TidyDocs {
38 missing_docs: Vec<String>, 50 missing_docs: Vec<String>,
@@ -41,7 +53,13 @@ struct TidyDocs {
41 53
42impl TidyDocs { 54impl TidyDocs {
43 fn visit(&mut self, path: &Path, text: &str) { 55 fn visit(&mut self, path: &Path, text: &str) {
44 if is_exclude_dir(path) || is_exclude_file(path) { 56 // Test hopefully don't really need comments, and for assists we already
57 // have special comments which are source of doc tests and user docs.
58 if is_exclude_dir(path, &["tests", "test_data", "handlers"]) {
59 return;
60 }
61
62 if is_exclude_file(path) {
45 return; 63 return;
46 } 64 }
47 65
@@ -58,21 +76,6 @@ impl TidyDocs {
58 self.missing_docs.push(path.display().to_string()); 76 self.missing_docs.push(path.display().to_string());
59 } 77 }
60 78
61 fn is_exclude_dir(p: &Path) -> bool {
62 // Test hopefully don't really need comments, and for assists we already
63 // have special comments which are source of doc tests and user docs.
64 let exclude_dirs = ["tests", "test_data", "handlers"];
65 let mut cur_path = p;
66 while let Some(path) = cur_path.parent() {
67 if exclude_dirs.iter().any(|dir| path.ends_with(dir)) {
68 return true;
69 }
70 cur_path = path;
71 }
72
73 false
74 }
75
76 fn is_exclude_file(d: &Path) -> bool { 79 fn is_exclude_file(d: &Path) -> bool {
77 let file_names = ["tests.rs"]; 80 let file_names = ["tests.rs"];
78 81
@@ -128,6 +131,18 @@ impl TidyDocs {
128 } 131 }
129} 132}
130 133
134fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool {
135 let mut cur_path = p;
136 while let Some(path) = cur_path.parent() {
137 if dirs_to_exclude.iter().any(|dir| path.ends_with(dir)) {
138 return true;
139 }
140 cur_path = path;
141 }
142
143 false
144}
145
131fn rust_files() -> impl Iterator<Item = PathBuf> { 146fn rust_files() -> impl Iterator<Item = PathBuf> {
132 let crates = project_root().join("crates"); 147 let crates = project_root().join("crates");
133 let iter = WalkDir::new(crates); 148 let iter = WalkDir::new(crates);