Skip to content

Allow mod files within tests directory #11775

@TomFryersMidsummer

Description

@TomFryersMidsummer

Summary

Within the tests/ directory, common/mod.rs has an advantage over common.rs for shared code: it doesn't try to run common.rs as a test file, which would add noise to test runs. So, perhaps mod_module_files should exclude this case.

This Rust Book includes this recommendation: https://doc.rust-lang.org/book/ch11-03-test-organization.html#submodules-in-integration-tests.

Lint Name

mod_module_files

Reproducer

I tried this code:

├── Cargo.lock
├── Cargo.toml
├── src
│   └── lib.rs
└── tests
    ├── common
    │   └── mod.rs
    └── test.rs

with mod common; in test.rs. Other files are as generated by cargo new, or empty.

cargo clippy --tests -- -W clippy::mod-module-files

I saw this happen:

warning: `mod.rs` files are not allowed, found `tests/common/mod.rs`
 --> tests/common/mod.rs:0:1
  |
  |
  = help: move `tests/common/mod.rs` to `tests/common.rs`
  = note: requested on the command line with `-W clippy::mod-module-files`

I expected to see this happen:

[no error]

Version

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

Additional Labels

No response

Metadata

Metadata

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions