Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

items-after-test-module: false positive with test-case and regular tests #11153

Closed
jamesbornholt opened this issue Jul 13, 2023 · 0 comments · Fixed by #11611
Closed

items-after-test-module: false positive with test-case and regular tests #11153

jamesbornholt opened this issue Jul 13, 2023 · 0 comments · Fixed by #11611
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@jamesbornholt
Copy link

Summary

#10992 fixed some of the interaction between the items-after-test-module lint and the test-case crate by ignoring proc macros. That works, but it still gets confused if you have non-test-case tests after test-case tests in the same file.

Lint Name

items-after-test-module

Reproducer

I tried this code:

use test_case::test_case;

#[test_case(1)]
#[test_case(2)]
fn test_the_thing(n: usize) {
    assert!(n < 5);
}

#[test]
fn other_test() {
    assert!(5 < 6);
}

I saw this happen:

warning: items were found after the testing module
  --> tests/stuff.rs:3:1
   |
3  |   #[test_case(1)]
   |   ^--------------
   |   |
   |  _in this procedural macro expansion
   | |
4  | | #[test_case(2)]
5  | | fn test_the_thing(n: usize) {
6  | |     assert!(n < 5);
...  |
11 | |     assert!(5 < 6);
12 | | }
   | |_^
   |
   = help: move the items to before the testing module was defined
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module
   = note: `-W clippy::items-after-test-module` implied by `-W clippy::all`
   = note: this warning originates in the attribute macro `test_case` (in Nightly builds, run with -Z macro-backtrace for more info)

Version

rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: aarch64-apple-darwin
release: 1.71.0
LLVM version: 16.0.5

Additional Labels

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant