diff options
author | Edwin Cheng <[email protected]> | 2021-02-03 14:01:09 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2021-02-03 14:01:09 +0000 |
commit | e73ffbf1e59eb05fe8ffe73ce4e1833295c588a5 (patch) | |
tree | 48f6079b55d32e13f355443aa82a5278a9c68a23 /xtask | |
parent | 85e1f0905aae762b8d64b52e76bbc6aa5915894b (diff) |
Add cargo file tidy test
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/lib.rs | 33 | ||||
-rw-r--r-- | xtask/tests/tidy.rs | 27 |
2 files changed, 48 insertions, 12 deletions
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 16b06b853..b19985fb2 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs | |||
@@ -38,19 +38,13 @@ pub fn rust_files() -> impl Iterator<Item = PathBuf> { | |||
38 | rust_files_in(&project_root().join("crates")) | 38 | rust_files_in(&project_root().join("crates")) |
39 | } | 39 | } |
40 | 40 | ||
41 | pub fn rust_files_in(path: &Path) -> impl Iterator<Item = PathBuf> { | 41 | pub fn cargo_files() -> impl Iterator<Item = PathBuf> { |
42 | let iter = WalkDir::new(path); | 42 | files_in(&project_root(), "toml") |
43 | return iter | 43 | .filter(|path| path.file_name().map(|it| it == "Cargo.toml").unwrap_or(false)) |
44 | .into_iter() | 44 | } |
45 | .filter_entry(|e| !is_hidden(e)) | ||
46 | .map(|e| e.unwrap()) | ||
47 | .filter(|e| !e.file_type().is_dir()) | ||
48 | .map(|e| e.into_path()) | ||
49 | .filter(|path| path.extension().map(|it| it == "rs").unwrap_or(false)); | ||
50 | 45 | ||
51 | fn is_hidden(entry: &DirEntry) -> bool { | 46 | pub fn rust_files_in(path: &Path) -> impl Iterator<Item = PathBuf> { |
52 | entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) | 47 | files_in(path, "rs") |
53 | } | ||
54 | } | 48 | } |
55 | 49 | ||
56 | pub fn run_rustfmt(mode: Mode) -> Result<()> { | 50 | pub fn run_rustfmt(mode: Mode) -> Result<()> { |
@@ -120,3 +114,18 @@ fn date_iso() -> Result<String> { | |||
120 | fn is_release_tag(tag: &str) -> bool { | 114 | fn is_release_tag(tag: &str) -> bool { |
121 | tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) | 115 | tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) |
122 | } | 116 | } |
117 | |||
118 | fn files_in(path: &Path, ext: &'static str) -> impl Iterator<Item = PathBuf> { | ||
119 | let iter = WalkDir::new(path); | ||
120 | return iter | ||
121 | .into_iter() | ||
122 | .filter_entry(|e| !is_hidden(e)) | ||
123 | .map(|e| e.unwrap()) | ||
124 | .filter(|e| !e.file_type().is_dir()) | ||
125 | .map(|e| e.into_path()) | ||
126 | .filter(move |path| path.extension().map(|it| it == ext).unwrap_or(false)); | ||
127 | |||
128 | fn is_hidden(entry: &DirEntry) -> bool { | ||
129 | entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) | ||
130 | } | ||
131 | } | ||
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index 9a6933b09..cb83e07fd 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs | |||
@@ -5,6 +5,7 @@ use std::{ | |||
5 | 5 | ||
6 | use xshell::{cmd, read_file}; | 6 | use xshell::{cmd, read_file}; |
7 | use xtask::{ | 7 | use xtask::{ |
8 | cargo_files, | ||
8 | codegen::{self, Mode}, | 9 | codegen::{self, Mode}, |
9 | project_root, run_rustfmt, rust_files, | 10 | project_root, run_rustfmt, rust_files, |
10 | }; | 11 | }; |
@@ -94,6 +95,32 @@ fn rust_files_are_tidy() { | |||
94 | } | 95 | } |
95 | 96 | ||
96 | #[test] | 97 | #[test] |
98 | fn cargo_files_are_tidy() { | ||
99 | for cargo in cargo_files() { | ||
100 | let mut section = None; | ||
101 | for (line_no, text) in read_file(&cargo).unwrap().lines().enumerate() { | ||
102 | let text = text.trim(); | ||
103 | if text.starts_with("[") { | ||
104 | section = Some(text); | ||
105 | continue; | ||
106 | } | ||
107 | if !section.map(|it| it.starts_with("[dependencies")).unwrap_or(false) { | ||
108 | continue; | ||
109 | } | ||
110 | let text: String = text.split_whitespace().collect(); | ||
111 | if text.contains("path=") && !text.contains("version") { | ||
112 | panic!( | ||
113 | "\ncargo internal dependencies should have version.\n\ | ||
114 | {}:{}\n", | ||
115 | cargo.display(), | ||
116 | line_no + 1 | ||
117 | ) | ||
118 | } | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | |||
123 | #[test] | ||
97 | fn check_merge_commits() { | 124 | fn check_merge_commits() { |
98 | let stdout = cmd!("git rev-list --merges --invert-grep --author 'bors\\[bot\\]' HEAD~19..") | 125 | let stdout = cmd!("git rev-list --merges --invert-grep --author 'bors\\[bot\\]' HEAD~19..") |
99 | .read() | 126 | .read() |