Skip to content

Move unit tests into separate files unconfigured during normal build #61097

Closed
@petrochenkov

Description

@petrochenkov

One of the most annoying parts of compiler refactorings is suddenly discovering that after a refactoring change some code in unit tests stops building.

Compiler unit tests are mostly old, many of them are not really "unit" and need to be migrated to regular ui testing or removed, but that's not the point of this issue.
The point of this issue is that after changing such test you have to restart the bootstrapping process from the crate that unit test belongs to (e.g. touched libsyntax -> rebuild everything).

How to fight this problem?
Exclude unit tests from the normal build!

Files included from under cfg(FALSE) are not considered crate dependencies from build system point of view (not included into dep files).
So, unit test modules included in the next way

#[cfg(test)]
mod tests;

won't cause rebuilds after changing code in them, they will be rebuilt only as a part of unit test run (so they won't participate in bootstrap).

Steps:

  • Standardize on the test module naming (currently mod test - 31 instances, mod tests - 183 instances, excluding src/tools and src/test subdirectories).
  • Outline test modules into separate files mod tests { ... } -> #[cfg(test)] mod tests;.
  • Running unit tests for my_crate: ./x.py test --stage 0 src/my_crate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-testsuiteArea: The testsuite used to check the correctness of rustcE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions