aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tools/tests
diff options
context:
space:
mode:
authorAlexander Andreev <[email protected]>2019-09-30 09:58:53 +0100
committerAlexander Andreev <[email protected]>2019-09-30 09:58:53 +0100
commitfdbd6bb11a0c47bf9ba1428e6bd432cd2ce72045 (patch)
treee5325e7642552b1902428eb4577e6c9d4f2e1260 /crates/ra_tools/tests
parent2b69c84396cf376b496e7de3c954400e51b5fc24 (diff)
Added test for check doc strings in crates.
#1856
Diffstat (limited to 'crates/ra_tools/tests')
-rw-r--r--crates/ra_tools/tests/cli.rs5
-rw-r--r--crates/ra_tools/tests/docs.rs67
-rw-r--r--crates/ra_tools/tests/main.rs2
3 files changed, 71 insertions, 3 deletions
diff --git a/crates/ra_tools/tests/cli.rs b/crates/ra_tools/tests/cli.rs
index 91b19c8f8..609fd4d8b 100644
--- a/crates/ra_tools/tests/cli.rs
+++ b/crates/ra_tools/tests/cli.rs
@@ -1,6 +1,5 @@
1use walkdir::WalkDir;
2
3use ra_tools::{gen_tests, generate_boilerplate, project_root, run_rustfmt, Verify}; 1use ra_tools::{gen_tests, generate_boilerplate, project_root, run_rustfmt, Verify};
2use walkdir::WalkDir;
4 3
5#[test] 4#[test]
6fn generated_grammar_is_fresh() { 5fn generated_grammar_is_fresh() {
@@ -36,7 +35,7 @@ fn no_todo() {
36 let text = std::fs::read_to_string(e.path()).unwrap(); 35 let text = std::fs::read_to_string(e.path()).unwrap();
37 if text.contains("TODO") || text.contains("TOOD") { 36 if text.contains("TODO") || text.contains("TOOD") {
38 panic!( 37 panic!(
39 "\nTODO markers should not be commited to the master branch,\n\ 38 "\nTODO markers should not be committed to the master branch,\n\
40 use FIXME instead\n\ 39 use FIXME instead\n\
41 {}\n", 40 {}\n",
42 e.path().display(), 41 e.path().display(),
diff --git a/crates/ra_tools/tests/docs.rs b/crates/ra_tools/tests/docs.rs
new file mode 100644
index 000000000..1629247da
--- /dev/null
+++ b/crates/ra_tools/tests/docs.rs
@@ -0,0 +1,67 @@
1use std::fs;
2use std::io::prelude::*;
3use std::io::BufReader;
4use std::path::Path;
5
6use walkdir::{DirEntry, WalkDir};
7
8use ra_tools::project_root;
9
10fn is_exclude_dir(p: &Path) -> bool {
11 let exclude_dirs = ["tests", "test_data"];
12 let mut cur_path = p;
13 while let Some(path) = cur_path.parent() {
14 if exclude_dirs.iter().any(|dir| path.ends_with(dir)) {
15 return true;
16 }
17 cur_path = path;
18 }
19
20 false
21}
22
23fn is_exclude_file(d: &DirEntry) -> bool {
24 let file_names = ["tests.rs"];
25
26 d.file_name().to_str().map(|f_n| file_names.iter().any(|name| *name == f_n)).unwrap_or(false)
27}
28
29fn is_hidden(entry: &DirEntry) -> bool {
30 entry.file_name().to_str().map(|s| s.starts_with(".")).unwrap_or(false)
31}
32
33#[test]
34fn no_docs_comments() {
35 let crates = project_root().join("crates");
36 let iter = WalkDir::new(crates);
37 for f in iter.into_iter().filter_entry(|e| !is_hidden(e)) {
38 let f = f.unwrap(); //dbg!(f.unwrap());
39 if f.file_type().is_dir() {
40 continue;
41 }
42 if f.path().extension().map(|it| it != "rs").unwrap_or(false) {
43 //dbg!(f.path());
44 continue;
45 }
46 if is_exclude_dir(f.path()) {
47 //dbg!(f.path());
48 continue;
49 }
50 if is_exclude_file(&f) {
51 //dbg!(f.path());
52 continue;
53 }
54 let mut reader = BufReader::new(fs::File::open(f.path()).unwrap());
55 let mut line = String::new();
56 reader.read_line(&mut line).unwrap();
57 if !line.starts_with("//!") {
58 //dbg!(line);
59 panic!(
60 "\nMissing docs strings\n\
61 module: {}\n\
62 Need add doc for module or this string \"//! FIXME: write short doc here\"\n",
63 f.path().display()
64 )
65 }
66 }
67}
diff --git a/crates/ra_tools/tests/main.rs b/crates/ra_tools/tests/main.rs
new file mode 100644
index 000000000..56d1318d6
--- /dev/null
+++ b/crates/ra_tools/tests/main.rs
@@ -0,0 +1,2 @@
1mod cli;
2mod docs;