Auto merge of #10543 - blyxyas:tests_outside_test_module, r=flip1995

Add `tests_outside_test_module` lint

Adds `tests_outside_test_module` from #10506. This PR **doesn't** close the issue, just resolves task 1.

changelog: [`tests_outside_test_module`]: The lint has been added
This commit is contained in:
bors 2023-04-04 09:46:50 +00:00
commit 5d149c5dac
6 changed files with 104 additions and 0 deletions

View file

@ -0,0 +1,18 @@
// compile-flags: --test
#![allow(unused)]
#![warn(clippy::tests_outside_test_module)]
fn main() {
// test code goes here
}
// Should lint
#[test]
fn my_test() {}
#[cfg(test)]
mod tests {
// Should not lint
#[test]
fn my_test() {}
}

View file

@ -0,0 +1,11 @@
error: this function marked with #[test] is outside a #[cfg(test)] module
--> $DIR/tests_outside_test_module.rs:11:1
|
LL | fn my_test() {}
| ^^^^^^^^^^^^^^^
|
= note: move it to a testing module marked with #[cfg(test)]
= note: `-D clippy::tests-outside-test-module` implied by `-D warnings`
error: aborting due to previous error