aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-15 14:54:43 +0100
committerAleksey Kladov <[email protected]>2021-06-15 14:54:43 +0100
commit067e97d149edc5eccdd0a30079f313325e87e449 (patch)
tree18d39b0aedee752543e5fdd4f73d4108694cae2b /xtask/src
parent4584868a7a23ea640694f34ed9e8c907473c66b4 (diff)
internal: enforce no #[ignore] and no #[should_panic]
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/tidy.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs
index f2ba8efef..25ddb43b2 100644
--- a/xtask/src/tidy.rs
+++ b/xtask/src/tidy.rs
@@ -89,6 +89,7 @@ fn rust_files_are_tidy() {
89 let text = read_file(&path).unwrap(); 89 let text = read_file(&path).unwrap();
90 check_todo(&path, &text); 90 check_todo(&path, &text);
91 check_dbg(&path, &text); 91 check_dbg(&path, &text);
92 check_test_attrs(&path, &text);
92 check_trailing_ws(&path, &text); 93 check_trailing_ws(&path, &text);
93 deny_clippy(&path, &text); 94 deny_clippy(&path, &text);
94 tidy_docs.visit(&path, &text); 95 tidy_docs.visit(&path, &text);
@@ -334,6 +335,36 @@ fn check_dbg(path: &Path, text: &str) {
334 } 335 }
335} 336}
336 337
338fn check_test_attrs(path: &Path, text: &str) {
339 let ignore_rule =
340 "https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#ignore";
341 let need_ignore: &[&str] = &[
342 // Special case to run `#[ignore]` tests
343 "ide/src/runnables.rs",
344 // A legit test which needs to be ignored, as it takes too long to run
345 // :(
346 "hir_def/src/nameres/collector.rs",
347 // Obviously needs ignore.
348 "ide_assists/src/handlers/toggle_ignore.rs",
349 // See above.
350 "ide_assists/src/tests/generated.rs",
351 ];
352 if text.contains("#[ignore") && !need_ignore.iter().any(|p| path.ends_with(p)) {
353 panic!("\ndon't `#[ignore]` tests, see:\n\n {}\n\n {}\n", ignore_rule, path.display(),)
354 }
355
356 let panic_rule =
357 "https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#panic";
358 let need_panic: &[&str] = &["test_utils/src/fixture.rs"];
359 if text.contains("#[should_panic") && !need_panic.iter().any(|p| path.ends_with(p)) {
360 panic!(
361 "\ndon't add `#[should_panic]` tests, see:\n\n {}\n\n {}\n",
362 panic_rule,
363 path.display(),
364 )
365 }
366}
367
337fn check_trailing_ws(path: &Path, text: &str) { 368fn check_trailing_ws(path: &Path, text: &str) {
338 if is_exclude_dir(path, &["test_data"]) { 369 if is_exclude_dir(path, &["test_data"]) {
339 return; 370 return;