aboutsummaryrefslogtreecommitdiff
path: root/xtask/tests/tidy-tests/docs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/tests/tidy-tests/docs.rs')
-rw-r--r--xtask/tests/tidy-tests/docs.rs106
1 files changed, 0 insertions, 106 deletions
diff --git a/xtask/tests/tidy-tests/docs.rs b/xtask/tests/tidy-tests/docs.rs
deleted file mode 100644
index 62c4f8441..000000000
--- a/xtask/tests/tidy-tests/docs.rs
+++ /dev/null
@@ -1,106 +0,0 @@
1use std::{collections::HashMap, fs, io::prelude::*, io::BufReader, path::Path};
2
3use anyhow::Context;
4use walkdir::{DirEntry, WalkDir};
5use xtask::project_root;
6
7fn is_exclude_dir(p: &Path) -> bool {
8 // Test hopefully don't really need comments, and for assists we already
9 // have special comments which are source of doc tests and user docs.
10 let exclude_dirs = ["tests", "test_data", "handlers"];
11 let mut cur_path = p;
12 while let Some(path) = cur_path.parent() {
13 if exclude_dirs.iter().any(|dir| path.ends_with(dir)) {
14 return true;
15 }
16 cur_path = path;
17 }
18
19 false
20}
21
22fn is_exclude_file(d: &DirEntry) -> bool {
23 let file_names = ["tests.rs"];
24
25 d.file_name().to_str().map(|f_n| file_names.iter().any(|name| *name == f_n)).unwrap_or(false)
26}
27
28fn is_hidden(entry: &DirEntry) -> bool {
29 entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false)
30}
31
32#[test]
33fn no_docs_comments() {
34 let crates = project_root().join("crates");
35 let iter = WalkDir::new(crates);
36 let mut missing_docs = Vec::new();
37 let mut contains_fixme = Vec::new();
38 for f in iter.into_iter().filter_entry(|e| !is_hidden(e)) {
39 let f = f.unwrap();
40 if f.file_type().is_dir() {
41 continue;
42 }
43 if f.path().extension().map(|it| it != "rs").unwrap_or(false) {
44 continue;
45 }
46 if is_exclude_dir(f.path()) {
47 continue;
48 }
49 if is_exclude_file(&f) {
50 continue;
51 }
52 let mut reader = BufReader::new(fs::File::open(f.path()).unwrap());
53 let mut line = String::new();
54 reader
55 .read_line(&mut line)
56 .with_context(|| format!("Failed to read {}", f.path().display()))
57 .unwrap();
58
59 if line.starts_with("//!") {
60 if line.contains("FIXME") {
61 contains_fixme.push(f.path().to_path_buf())
62 }
63 } else {
64 missing_docs.push(f.path().display().to_string());
65 }
66 }
67 if !missing_docs.is_empty() {
68 panic!(
69 "\nMissing docs strings\n\n\
70 modules:\n{}\n\n",
71 missing_docs.join("\n")
72 )
73 }
74
75 let whitelist = [
76 "ra_db",
77 "ra_hir",
78 "ra_hir_expand",
79 "ra_ide",
80 "ra_mbe",
81 "ra_parser",
82 "ra_prof",
83 "ra_project_model",
84 "ra_syntax",
85 "ra_text_edit",
86 "ra_tt",
87 "ra_hir_ty",
88 ];
89
90 let mut has_fixmes = whitelist.iter().map(|it| (*it, false)).collect::<HashMap<&str, bool>>();
91 'outer: for path in contains_fixme {
92 for krate in whitelist.iter() {
93 if path.components().any(|it| it.as_os_str() == *krate) {
94 has_fixmes.insert(krate, true);
95 continue 'outer;
96 }
97 }
98 panic!("FIXME doc in a fully-documented crate: {}", path.display())
99 }
100
101 for (krate, has_fixme) in has_fixmes.iter() {
102 if !has_fixme {
103 panic!("crate {} is fully documented, remove it from the white list", krate)
104 }
105 }
106}