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 ff5877a7be8..31f76589dea 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 @@ SOURCE_FILE@0..60 PATH@15..21 PATH_SEGMENT@15..21 NAME_REF@15..21 - IDENT@15..21 "ignore" + IDENT@15..21 "Ignore" R_BRACK@21..22 "]" WHITESPACE@22..23 "\n" FN_KW@23..25 "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 3d2e01d5c6f..6f04cb1717f 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 @@ #[cfg(test)] -#[ignore] +#[Ignore] fn foo() {} #[path = "a.rs"] diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs index f2ba8efef5f..25ddb43b20f 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;