Fix items_after_test_module for non root modules, add applicable suggestion
This commit is contained in:
parent
331d01e2bf
commit
dcc400191e
11 changed files with 177 additions and 59 deletions
11
tests/ui/items_after_test_module/after_proc_macros.rs
Normal file
11
tests/ui/items_after_test_module/after_proc_macros.rs
Normal 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() {}
|
||||
4
tests/ui/items_after_test_module/auxiliary/submodule.rs
Normal file
4
tests/ui/items_after_test_module/auxiliary/submodule.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#[cfg(test)]
|
||||
mod tests {}
|
||||
|
||||
fn in_submodule() {}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
error: Option 'test' given more than once
|
||||
|
||||
8
tests/ui/items_after_test_module/in_submodule.rs
Normal file
8
tests/ui/items_after_test_module/in_submodule.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#[path = "auxiliary/submodule.rs"]
|
||||
mod submodule;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn t() {}
|
||||
}
|
||||
14
tests/ui/items_after_test_module/in_submodule.stderr
Normal file
14
tests/ui/items_after_test_module/in_submodule.stderr
Normal 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
|
||||
|
||||
11
tests/ui/items_after_test_module/multiple_modules.rs
Normal file
11
tests/ui/items_after_test_module/multiple_modules.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn f() {}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod more_tests {
|
||||
#[test]
|
||||
fn g() {}
|
||||
}
|
||||
|
|
@ -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 {
|
||||
() => {};
|
||||
}
|
||||
22
tests/ui/items_after_test_module/root_module.rs
Normal file
22
tests/ui/items_after_test_module/root_module.rs
Normal 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 {
|
||||
() => {};
|
||||
}
|
||||
20
tests/ui/items_after_test_module/root_module.stderr
Normal file
20
tests/ui/items_after_test_module/root_module.stderr
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue