internal: enforce no #[ignore] and no #[should_panic]

This commit is contained in:
Aleksey Kladov 2021-06-15 16:54:43 +03:00
parent 4584868a7a
commit 067e97d149
3 changed files with 33 additions and 2 deletions

View File

@ -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"

View File

@ -1,5 +1,5 @@
#[cfg(test)]
#[ignore]
#[Ignore]
fn foo() {}
#[path = "a.rs"]

View File

@ -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;