Skip to content

Commit

Permalink
improve explanation of placing tests in separate file (#1721)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuki Okushi <[email protected]>
  • Loading branch information
tshepang and JohnTitor authored Jul 8, 2023
1 parent 6d5b3db commit b10654a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/tests/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,19 @@ The standard library relies very heavily on documentation tests to cover its fun
However, unit tests and integration tests can also be used as needed.
Almost all of the compiler packages have doctests disabled.

The standard library and compiler always place all unit tests in a separate `tests` file
(this is enforced in [tidy][tidy-unit-tests]).
This approach ensures that when the test file is changed, the crate does not need to be recompiled.
All standard library and compiler unit tests are placed in separate `tests` file
(which is enforced in [tidy][tidy-unit-tests]).
This ensures that when the test file is changed, the crate does not need to be recompiled.
For example:

```rust,ignore
#[cfg(test)]
mod tests;
```

If it wasn't done this way, and the tests were placed in the same file as the source,
then changing or adding a test would cause the crate you are working on to be recompiled.
If you were working on something like `core`,
then that would require recompiling the entire standard library, and the entirety of `rustc`.
If it wasn't done this way,
and you were working on something like `core`,
that would require recompiling the entire standard library, and the entirety of `rustc`.

`./x test` includes some CLI options for controlling the behavior with these tests:

Expand Down

0 comments on commit b10654a

Please sign in to comment.