From 067e97d149edc5eccdd0a30079f313325e87e449 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jun 2021 16:54:43 +0300 Subject: internal: enforce no #[ignore] and no #[should_panic] --- xtask/src/tidy.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'xtask/src/tidy.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() { let text = read_file(&path).unwrap(); check_todo(&path, &text); check_dbg(&path, &text); + check_test_attrs(&path, &text); check_trailing_ws(&path, &text); deny_clippy(&path, &text); tidy_docs.visit(&path, &text); @@ -334,6 +335,36 @@ fn check_dbg(path: &Path, text: &str) { } } +fn check_test_attrs(path: &Path, text: &str) { + let ignore_rule = + "https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#ignore"; + let need_ignore: &[&str] = &[ + // Special case to run `#[ignore]` tests + "ide/src/runnables.rs", + // A legit test which needs to be ignored, as it takes too long to run + // :( + "hir_def/src/nameres/collector.rs", + // Obviously needs ignore. + "ide_assists/src/handlers/toggle_ignore.rs", + // See above. + "ide_assists/src/tests/generated.rs", + ]; + if text.contains("#[ignore") && !need_ignore.iter().any(|p| path.ends_with(p)) { + panic!("\ndon't `#[ignore]` tests, see:\n\n {}\n\n {}\n", ignore_rule, path.display(),) + } + + let panic_rule = + "https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#panic"; + let need_panic: &[&str] = &["test_utils/src/fixture.rs"]; + if text.contains("#[should_panic") && !need_panic.iter().any(|p| path.ends_with(p)) { + panic!( + "\ndon't add `#[should_panic]` tests, see:\n\n {}\n\n {}\n", + panic_rule, + path.display(), + ) + } +} + fn check_trailing_ws(path: &Path, text: &str) { if is_exclude_dir(path, &["test_data"]) { return; -- cgit v1.2.3