aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tools
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-30 11:46:13 +0100
committerGitHub <[email protected]>2019-09-30 11:46:13 +0100
commitebfba461123928363da55e75195d76314c51fa7e (patch)
treea1eecf37856e82e6a858de330ffdec9e1a0327f5 /crates/ra_tools
parent733f1d8b709788225bd06f8c0aee1819db92620b (diff)
parenta47bca636cec350cf29c296dafd0c1bec51cd654 (diff)
Merge #1937
1937: Added test for check doc strings in directory crates/ r=andreevlex a=andreevlex #1856 Co-authored-by: Alexander Andreev <[email protected]>
Diffstat (limited to 'crates/ra_tools')
-rw-r--r--crates/ra_tools/src/bin/pre-commit.rs2
-rw-r--r--crates/ra_tools/src/boilerplate_gen.rs4
-rw-r--r--crates/ra_tools/src/help.rs2
-rw-r--r--crates/ra_tools/src/lib.rs2
-rw-r--r--crates/ra_tools/src/main.rs2
-rw-r--r--crates/ra_tools/tests/cli.rs5
-rw-r--r--crates/ra_tools/tests/docs.rs63
-rw-r--r--crates/ra_tools/tests/main.rs2
8 files changed, 78 insertions, 4 deletions
diff --git a/crates/ra_tools/src/bin/pre-commit.rs b/crates/ra_tools/src/bin/pre-commit.rs
index a628f64b2..16bbf9cb2 100644
--- a/crates/ra_tools/src/bin/pre-commit.rs
+++ b/crates/ra_tools/src/bin/pre-commit.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use std::process::Command; 3use std::process::Command;
2 4
3use ra_tools::{project_root, run, run_rustfmt, Overwrite, Result}; 5use ra_tools::{project_root, run, run_rustfmt, Overwrite, Result};
diff --git a/crates/ra_tools/src/boilerplate_gen.rs b/crates/ra_tools/src/boilerplate_gen.rs
index 1d112c0af..39f1cae66 100644
--- a/crates/ra_tools/src/boilerplate_gen.rs
+++ b/crates/ra_tools/src/boilerplate_gen.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use std::{ 3use std::{
2 collections::BTreeMap, 4 collections::BTreeMap,
3 fs, 5 fs,
@@ -282,7 +284,7 @@ fn reformat(text: impl std::fmt::Display) -> Result<String> {
282 let output = rustfmt.wait_with_output()?; 284 let output = rustfmt.wait_with_output()?;
283 let stdout = String::from_utf8(output.stdout)?; 285 let stdout = String::from_utf8(output.stdout)?;
284 let preamble = "Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`"; 286 let preamble = "Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`";
285 Ok(format!("// {}\n\n{}", preamble, stdout)) 287 Ok(format!("//! {}\n\n{}", preamble, stdout))
286} 288}
287 289
288#[derive(Deserialize, Debug)] 290#[derive(Deserialize, Debug)]
diff --git a/crates/ra_tools/src/help.rs b/crates/ra_tools/src/help.rs
index 9eb4dfbe4..72dfabacd 100644
--- a/crates/ra_tools/src/help.rs
+++ b/crates/ra_tools/src/help.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1pub const GLOBAL_HELP: &str = "tasks 3pub const GLOBAL_HELP: &str = "tasks
2 4
3USAGE: 5USAGE:
diff --git a/crates/ra_tools/src/lib.rs b/crates/ra_tools/src/lib.rs
index 9ba23caaa..aa993a38a 100644
--- a/crates/ra_tools/src/lib.rs
+++ b/crates/ra_tools/src/lib.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1mod boilerplate_gen; 3mod boilerplate_gen;
2 4
3use std::{ 5use std::{
diff --git a/crates/ra_tools/src/main.rs b/crates/ra_tools/src/main.rs
index a951ce427..161871ccf 100644
--- a/crates/ra_tools/src/main.rs
+++ b/crates/ra_tools/src/main.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1mod help; 3mod help;
2 4
3use core::fmt::Write; 5use core::fmt::Write;
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..ea3330175
--- /dev/null
+++ b/crates/ra_tools/tests/docs.rs
@@ -0,0 +1,63 @@
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();
39 if f.file_type().is_dir() {
40 continue;
41 }
42 if f.path().extension().map(|it| it != "rs").unwrap_or(false) {
43 continue;
44 }
45 if is_exclude_dir(f.path()) {
46 continue;
47 }
48 if is_exclude_file(&f) {
49 continue;
50 }
51 let mut reader = BufReader::new(fs::File::open(f.path()).unwrap());
52 let mut line = String::new();
53 reader.read_line(&mut line).unwrap();
54 if !line.starts_with("//!") {
55 panic!(
56 "\nMissing docs strings\n\
57 module: {}\n\
58 Need add doc for module\n",
59 f.path().display()
60 )
61 }
62 }
63}
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;