diff options
Diffstat (limited to 'crates/ra_tools/tests')
-rw-r--r-- | crates/ra_tools/tests/cli.rs | 5 | ||||
-rw-r--r-- | crates/ra_tools/tests/docs.rs | 67 | ||||
-rw-r--r-- | crates/ra_tools/tests/main.rs | 2 |
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 @@ | |||
1 | use walkdir::WalkDir; | ||
2 | |||
3 | use ra_tools::{gen_tests, generate_boilerplate, project_root, run_rustfmt, Verify}; | 1 | use ra_tools::{gen_tests, generate_boilerplate, project_root, run_rustfmt, Verify}; |
2 | use walkdir::WalkDir; | ||
4 | 3 | ||
5 | #[test] | 4 | #[test] |
6 | fn generated_grammar_is_fresh() { | 5 | fn 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 @@ | |||
1 | use std::fs; | ||
2 | use std::io::prelude::*; | ||
3 | use std::io::BufReader; | ||
4 | use std::path::Path; | ||
5 | |||
6 | use walkdir::{DirEntry, WalkDir}; | ||
7 | |||
8 | use ra_tools::project_root; | ||
9 | |||
10 | fn 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 | |||
23 | fn 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 | |||
29 | fn is_hidden(entry: &DirEntry) -> bool { | ||
30 | entry.file_name().to_str().map(|s| s.starts_with(".")).unwrap_or(false) | ||
31 | } | ||
32 | |||
33 | #[test] | ||
34 | fn 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 @@ | |||
1 | mod cli; | ||
2 | mod docs; | ||