aboutsummaryrefslogtreecommitdiff
path: root/xtask/tests/tidy.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/tests/tidy.rs')
-rw-r--r--xtask/tests/tidy.rs47
1 files changed, 38 insertions, 9 deletions
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs
index b3bb9d543..9de60c76c 100644
--- a/xtask/tests/tidy.rs
+++ b/xtask/tests/tidy.rs
@@ -3,9 +3,9 @@ use std::{
3 path::{Path, PathBuf}, 3 path::{Path, PathBuf},
4}; 4};
5 5
6use xshell::{cmd, read_file};
6use xtask::{ 7use xtask::{
7 codegen::{self, Mode}, 8 codegen::{self, Mode},
8 not_bash::{fs2, run},
9 project_root, run_rustfmt, rust_files, 9 project_root, run_rustfmt, rust_files,
10}; 10};
11 11
@@ -42,20 +42,20 @@ fn smoke_test_docs_generation() {
42 // We don't commit docs to the repo, so we can just overwrite in tests. 42 // We don't commit docs to the repo, so we can just overwrite in tests.
43 codegen::generate_assists_docs(Mode::Overwrite).unwrap(); 43 codegen::generate_assists_docs(Mode::Overwrite).unwrap();
44 codegen::generate_feature_docs(Mode::Overwrite).unwrap(); 44 codegen::generate_feature_docs(Mode::Overwrite).unwrap();
45 codegen::generate_diagnostic_docs(Mode::Overwrite).unwrap();
45} 46}
46 47
47#[test] 48#[test]
48fn check_lsp_extensions_docs() { 49fn check_lsp_extensions_docs() {
49 let expected_hash = { 50 let expected_hash = {
50 let lsp_ext_rs = 51 let lsp_ext_rs =
51 fs2::read_to_string(project_root().join("crates/rust-analyzer/src/lsp_ext.rs")) 52 read_file(project_root().join("crates/rust-analyzer/src/lsp_ext.rs")).unwrap();
52 .unwrap();
53 stable_hash(lsp_ext_rs.as_str()) 53 stable_hash(lsp_ext_rs.as_str())
54 }; 54 };
55 55
56 let actual_hash = { 56 let actual_hash = {
57 let lsp_extensions_md = 57 let lsp_extensions_md =
58 fs2::read_to_string(project_root().join("docs/dev/lsp-extensions.md")).unwrap(); 58 read_file(project_root().join("docs/dev/lsp-extensions.md")).unwrap();
59 let text = lsp_extensions_md 59 let text = lsp_extensions_md
60 .lines() 60 .lines()
61 .find_map(|line| line.strip_prefix("lsp_ext.rs hash:")) 61 .find_map(|line| line.strip_prefix("lsp_ext.rs hash:"))
@@ -83,7 +83,7 @@ Please adjust docs/dev/lsp-extensions.md.
83fn rust_files_are_tidy() { 83fn rust_files_are_tidy() {
84 let mut tidy_docs = TidyDocs::default(); 84 let mut tidy_docs = TidyDocs::default();
85 for path in rust_files(&project_root().join("crates")) { 85 for path in rust_files(&project_root().join("crates")) {
86 let text = fs2::read_to_string(&path).unwrap(); 86 let text = read_file(&path).unwrap();
87 check_todo(&path, &text); 87 check_todo(&path, &text);
88 check_trailing_ws(&path, &text); 88 check_trailing_ws(&path, &text);
89 deny_clippy(&path, &text); 89 deny_clippy(&path, &text);
@@ -94,8 +94,10 @@ fn rust_files_are_tidy() {
94 94
95#[test] 95#[test]
96fn check_merge_commits() { 96fn check_merge_commits() {
97 let stdout = run!("git rev-list --merges --invert-grep --author 'bors\\[bot\\]' HEAD~19.."; echo = false) 97 let stdout =
98 .unwrap(); 98 dbg!(cmd!("git rev-list --merges --invert-grep --author 'bors\\[bot\\]' HEAD~19.."))
99 .read()
100 .unwrap();
99 if !stdout.is_empty() { 101 if !stdout.is_empty() {
100 panic!( 102 panic!(
101 " 103 "
@@ -129,6 +131,14 @@ https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/#redo-after-
129} 131}
130 132
131fn deny_clippy(path: &PathBuf, text: &String) { 133fn deny_clippy(path: &PathBuf, text: &String) {
134 let ignore = &[
135 // The documentation in string literals may contain anything for its own purposes
136 "completion/src/generated_lint_completions.rs",
137 ];
138 if ignore.iter().any(|p| path.ends_with(p)) {
139 return;
140 }
141
132 if text.contains("[\u{61}llow(clippy") { 142 if text.contains("[\u{61}llow(clippy") {
133 panic!( 143 panic!(
134 "\n\nallowing lints is forbidden: {}. 144 "\n\nallowing lints is forbidden: {}.
@@ -168,7 +178,7 @@ Zlib OR Apache-2.0 OR MIT
168 .filter(|it| !it.is_empty()) 178 .filter(|it| !it.is_empty())
169 .collect::<Vec<_>>(); 179 .collect::<Vec<_>>();
170 180
171 let meta = run!("cargo metadata --format-version 1"; echo = false).unwrap(); 181 let meta = cmd!("cargo metadata --format-version 1").read().unwrap();
172 let mut licenses = meta 182 let mut licenses = meta
173 .split(|c| c == ',' || c == '{' || c == '}') 183 .split(|c| c == ',' || c == '{' || c == '}')
174 .filter(|it| it.contains(r#""license""#)) 184 .filter(|it| it.contains(r#""license""#))
@@ -177,6 +187,25 @@ Zlib OR Apache-2.0 OR MIT
177 .collect::<Vec<_>>(); 187 .collect::<Vec<_>>();
178 licenses.sort(); 188 licenses.sort();
179 licenses.dedup(); 189 licenses.dedup();
190 if licenses != expected {
191 let mut diff = String::new();
192
193 diff += &format!("New Licenses:\n");
194 for &l in licenses.iter() {
195 if !expected.contains(&l) {
196 diff += &format!(" {}\n", l)
197 }
198 }
199
200 diff += &format!("\nMissing Licenses:\n");
201 for &l in expected.iter() {
202 if !licenses.contains(&l) {
203 diff += &format!(" {}\n", l)
204 }
205 }
206
207 panic!("different set of licenses!\n{}", diff);
208 }
180 assert_eq!(licenses, expected); 209 assert_eq!(licenses, expected);
181} 210}
182 211
@@ -193,7 +222,7 @@ fn check_todo(path: &Path, text: &str) {
193 // `ast::make`. 222 // `ast::make`.
194 "ast/make.rs", 223 "ast/make.rs",
195 // The documentation in string literals may contain anything for its own purposes 224 // The documentation in string literals may contain anything for its own purposes
196 "completion/generated_features.rs", 225 "completion/src/generated_lint_completions.rs",
197 ]; 226 ];
198 if need_todo.iter().any(|p| path.ends_with(p)) { 227 if need_todo.iter().any(|p| path.ends_with(p)) {
199 return; 228 return;