aboutsummaryrefslogtreecommitdiff
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
parent4584868a7a23ea640694f34ed9e8c907473c66b4 (diff)
internal: enforce no #[ignore] and no #[should_panic]
-rw-r--r--crates/syntax/test_data/parser/ok/0011_outer_attribute.rast2
-rw-r--r--crates/syntax/test_data/parser/ok/0011_outer_attribute.rs2
-rw-r--r--xtask/src/tidy.rs31
3 files changed, 33 insertions, 2 deletions
diff --git a/crates/syntax/test_data/parser/ok/0011_outer_attribute.rast b/crates/syntax/test_data/parser/ok/0011_outer_attribute.rast
index ff5877a7b..31f76589d 100644
--- a/crates/syntax/test_data/parser/ok/0011_outer_attribute.rast
+++ b/crates/syntax/test_data/parser/ok/0011_outer_attribute.rast
@@ -21,7 +21,7 @@ [email protected]
21 [email protected] 21 [email protected]
22 [email protected] 22 [email protected]
23 [email protected] 23 [email protected]
24 [email protected] "ignore" 24 [email protected] "Ignore"
25 [email protected] "]" 25 [email protected] "]"
26 [email protected] "\n" 26 [email protected] "\n"
27 [email protected] "fn" 27 [email protected] "fn"
diff --git a/crates/syntax/test_data/parser/ok/0011_outer_attribute.rs b/crates/syntax/test_data/parser/ok/0011_outer_attribute.rs
index 3d2e01d5c..6f04cb171 100644
--- a/crates/syntax/test_data/parser/ok/0011_outer_attribute.rs
+++ b/crates/syntax/test_data/parser/ok/0011_outer_attribute.rs
@@ -1,5 +1,5 @@
1#[cfg(test)] 1#[cfg(test)]
2#[ignore] 2#[Ignore]
3fn foo() {} 3fn foo() {}
4 4
5#[path = "a.rs"] 5#[path = "a.rs"]
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;