Skip to content

New inline_test_mod lint to encouage independent test.rs files for rebuild performance #13589

@epage

Description

@epage

What it does

Check for mod test {}s and instead encourage those being separate files.

Checking for mod test {} was to align with tests_outside_test_module. I could imagine there being other cases to key off of.

Advantage

Rebuild performance. If someone changes a "unit test", then only the test lib rebuilds and not the lib.

Drawbacks

For foo.rs files in projects that use foo/mod.rs, adding a separate test mod would require creating a directory when it wasn't needed otherwise. Except for when visibility is a concern, a parallel test_foo.rs file could be used, e.g. snapbox does this

Overall, this would increase the friction for writing tests.

Example

#[cfg(test)]
mod test {
}

Could be written as:

#[cfg(test)]
mod test;

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions