rust-lang / rust-lang/rust-clippy

tests_outside_test_module can be triggered in integration tests

Open
#11,024 0 comments 24 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

tests_outside_test_module can be triggered in integration tests.

This actually came up because I was trying out RFC 3389 manifest-lint which helpfully applies lint configuration to all integration tests. manifest-lint isn't required to trigger the issue, though.

Applying the suggestion given by the lint does work (i.e. still runs the test and silences the warning), but is redundant since it's already in an integration test.

Lint Name

tests_outside_test_module

Reproducer

I tried this code in tests/integrations/main.rs:

#![warn(clippy::tests_outside_test_module)]

#[test]
fn it_works() {
    assert_eq!(2 + 2, 4);
}

I saw this happen when running cargo clippy --tests:

warning: this function marked with #[test] is outside a #[cfg(test)] module
 --> tests/integrations/main.rs:4:1
  |
4 | / fn it_works() {
5 | |     assert_eq!(2 + 2, 4);
6 | | }
  | |_^
  |
  = note: move it to a testing module marked with #[cfg(test)]
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tests_outside_test_module
note: the lint level is defined here
 --> tests/integrations/main.rs:1:9
  |
1 | #![warn(clippy::tests_outside_test_module)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I expected to see no warnings generated.

Version
rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the warning with tests/integrations/main.rs using cargo clippy --tests and the tests_outside_test_module lint shown in the issue. Trace the lint's handling of integration tests, then verify the existing reproducer runs without warnings while still executing the test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.