Fix items_after_test_module for non root modules, add applicable suggestion

This commit is contained in:
Alex Macleod 2023-10-04 20:24:16 +00:00
parent 331d01e2bf
commit dcc400191e
11 changed files with 177 additions and 59 deletions

View file

@ -0,0 +1,11 @@
//@aux-build:../auxiliary/proc_macros.rs
extern crate proc_macros;
proc_macros::with_span! {
span
#[cfg(test)]
mod tests {}
}
#[test]
fn f() {}

View file

@ -0,0 +1,4 @@
#[cfg(test)]
mod tests {}
fn in_submodule() {}

View file

@ -1,2 +0,0 @@
error: Option 'test' given more than once

View file

@ -0,0 +1,8 @@
#[path = "auxiliary/submodule.rs"]
mod submodule;
#[cfg(test)]
mod tests {
#[test]
fn t() {}
}

View file

@ -0,0 +1,14 @@
error: items after a test module
--> $DIR/auxiliary/submodule.rs:2:1
|
LL | mod tests {}
| ^^^^^^^^^
LL |
LL | fn in_submodule() {}
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::items-after-test-module` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::items_after_test_module)]`
error: aborting due to previous error

View file

@ -0,0 +1,11 @@
#[cfg(test)]
mod tests {
#[test]
fn f() {}
}
#[cfg(test)]
mod more_tests {
#[test]
fn g() {}
}

View file

@ -1,4 +1,3 @@
//@compile-flags: --test
#![allow(unused)]
#![warn(clippy::items_after_test_module)]
@ -6,6 +5,13 @@ fn main() {}
fn should_not_lint() {}
fn should_lint() {}
const SHOULD_ALSO_LINT: usize = 1;
macro_rules! should_lint {
() => {};
}
#[allow(dead_code)]
#[allow(unused)] // Some attributes to check that span replacement is good enough
#[allow(clippy::allow_attributes)]
@ -14,10 +20,3 @@ mod tests {
#[test]
fn hi() {}
}
fn should_lint() {}
const SHOULD_ALSO_LINT: usize = 1;
macro_rules! should_not_lint {
() => {};
}

View file

@ -0,0 +1,22 @@
#![allow(unused)]
#![warn(clippy::items_after_test_module)]
fn main() {}
fn should_not_lint() {}
#[allow(dead_code)]
#[allow(unused)] // Some attributes to check that span replacement is good enough
#[allow(clippy::allow_attributes)]
#[cfg(test)]
mod tests {
#[test]
fn hi() {}
}
fn should_lint() {}
const SHOULD_ALSO_LINT: usize = 1;
macro_rules! should_lint {
() => {};
}

View file

@ -0,0 +1,20 @@
error: items after a test module
--> $DIR/root_module.rs:12:1
|
LL | mod tests {
| ^^^^^^^^^
...
LL | fn should_lint() {}
| ^^^^^^^^^^^^^^^^
LL |
LL | const SHOULD_ALSO_LINT: usize = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! should_lint {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::items-after-test-module` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::items_after_test_module)]`
= help: move the items to before the test module was defined
error: aborting due to previous error