diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-17 21:14:31 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-17 21:14:31 +0100 |
commit | 6b9bd7bdd2712a7e85d6bfc70c231dbe36c2e585 (patch) | |
tree | 890a88741ef83c5ca0a57006c1972d0870fd86a4 /xtask/tests | |
parent | 65ab81e35868c09ac9c93cf1d53a607f5caede53 (diff) | |
parent | 5376c769f0cb6076c4862e728af042bb563a5051 (diff) |
Merge #2032
2032: rename tools -> xtask r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'xtask/tests')
-rw-r--r-- | xtask/tests/tidy-tests/cli.rs | 45 | ||||
-rw-r--r-- | xtask/tests/tidy-tests/docs.rs | 63 | ||||
-rw-r--r-- | xtask/tests/tidy-tests/main.rs | 2 |
3 files changed, 110 insertions, 0 deletions
diff --git a/xtask/tests/tidy-tests/cli.rs b/xtask/tests/tidy-tests/cli.rs new file mode 100644 index 000000000..5d8ddea83 --- /dev/null +++ b/xtask/tests/tidy-tests/cli.rs | |||
@@ -0,0 +1,45 @@ | |||
1 | use walkdir::WalkDir; | ||
2 | use xtask::{gen_tests, generate_boilerplate, project_root, run_rustfmt, Verify}; | ||
3 | |||
4 | #[test] | ||
5 | fn generated_grammar_is_fresh() { | ||
6 | if let Err(error) = generate_boilerplate(Verify) { | ||
7 | panic!("{}. Please update it by running `cargo xtask codegen`", error); | ||
8 | } | ||
9 | } | ||
10 | |||
11 | #[test] | ||
12 | fn generated_tests_are_fresh() { | ||
13 | if let Err(error) = gen_tests(Verify) { | ||
14 | panic!("{}. Please update tests by running `cargo xtask gen-tests`", error); | ||
15 | } | ||
16 | } | ||
17 | |||
18 | #[test] | ||
19 | fn check_code_formatting() { | ||
20 | if let Err(error) = run_rustfmt(Verify) { | ||
21 | panic!("{}. Please format the code by running `cargo format`", error); | ||
22 | } | ||
23 | } | ||
24 | |||
25 | #[test] | ||
26 | fn no_todo() { | ||
27 | WalkDir::new(project_root().join("crates")).into_iter().for_each(|e| { | ||
28 | let e = e.unwrap(); | ||
29 | if e.path().extension().map(|it| it != "rs").unwrap_or(true) { | ||
30 | return; | ||
31 | } | ||
32 | if e.path().ends_with("tests/cli.rs") { | ||
33 | return; | ||
34 | } | ||
35 | let text = std::fs::read_to_string(e.path()).unwrap(); | ||
36 | if text.contains("TODO") || text.contains("TOOD") { | ||
37 | panic!( | ||
38 | "\nTODO markers should not be committed to the master branch,\n\ | ||
39 | use FIXME instead\n\ | ||
40 | {}\n", | ||
41 | e.path().display(), | ||
42 | ) | ||
43 | } | ||
44 | }) | ||
45 | } | ||
diff --git a/xtask/tests/tidy-tests/docs.rs b/xtask/tests/tidy-tests/docs.rs new file mode 100644 index 000000000..fe5852bc6 --- /dev/null +++ b/xtask/tests/tidy-tests/docs.rs | |||
@@ -0,0 +1,63 @@ | |||
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 xtask::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(); | ||
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/xtask/tests/tidy-tests/main.rs b/xtask/tests/tidy-tests/main.rs new file mode 100644 index 000000000..56d1318d6 --- /dev/null +++ b/xtask/tests/tidy-tests/main.rs | |||
@@ -0,0 +1,2 @@ | |||
1 | mod cli; | ||
2 | mod docs; | ||