Skip to content

Commit 2d13d27

Browse files
committed
book: use mod tests consistently
Fixes rust-lang#24030 Of the four code samples with modules in TRPL: - 2 use `mod test` - 2 use `mod tests` We should be consistent here, but which is right? The stdlib is split: $ grep -r 'mod tests {' src/lib* | wc -l 63 $ grep -r 'mod test {' src/lib* | wc -l 58 Subjectively, I like the plural. Maybe you, dear reviewer, do too?
1 parent 80def6c commit 2d13d27

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/doc/reference.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,7 @@ explain, here's a few use cases and what they would entail:
18301830
the second case.
18311831

18321832
* When writing unit tests for a module, it's often a common idiom to have an
1833-
immediate child of the module to-be-tested named `mod test`. This module
1833+
immediate child of the module to-be-tested named `mod tests`. This module
18341834
could access any items of the parent module through the second case, meaning
18351835
that internal implementation details could also be seamlessly tested from the
18361836
child module.
@@ -1882,7 +1882,7 @@ pub mod submodule {
18821882
fn my_implementation() {}
18831883
18841884
#[cfg(test)]
1885-
mod test {
1885+
mod tests {
18861886
18871887
#[test]
18881888
fn test_my_implementation() {

src/doc/style/testing/unit.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
% Unit testing
22

3-
Unit tests should live in a `test` submodule at the bottom of the module they
4-
test. Mark the `test` submodule with `#[cfg(test)]` so it is only compiled when
3+
Unit tests should live in a `tests` submodule at the bottom of the module they
4+
test. Mark the `tests` submodule with `#[cfg(test)]` so it is only compiled when
55
testing.
66

7-
The `test` module should contain:
7+
The `tests` module should contain:
88

99
* Imports needed only for testing.
1010
* Functions marked with `#[test]` striving for full coverage of the parent module's
@@ -17,7 +17,7 @@ For example:
1717
// Excerpt from std::str
1818

1919
#[cfg(test)]
20-
mod test {
20+
mod tests {
2121
#[test]
2222
fn test_eq() {
2323
assert!((eq(&"".to_owned(), &"".to_owned())));

src/doc/trpl/testing.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ fn it_works() {
219219
This is a very common use of `assert_eq!`: call some function with
220220
some known arguments and compare it to the expected output.
221221

222-
# The `test` module
222+
# The `tests` module
223223

224224
There is one way in which our existing example is not idiomatic: it's
225-
missing the test module. The idiomatic way of writing our example
225+
missing the `tests` module. The idiomatic way of writing our example
226226
looks like this:
227227

228228
```{rust,ignore}
@@ -231,7 +231,7 @@ pub fn add_two(a: i32) -> i32 {
231231
}
232232
233233
#[cfg(test)]
234-
mod test {
234+
mod tests {
235235
use super::add_two;
236236
237237
#[test]
@@ -241,7 +241,7 @@ mod test {
241241
}
242242
```
243243

244-
There's a few changes here. The first is the introduction of a `mod test` with
244+
There's a few changes here. The first is the introduction of `mod tests` with
245245
a `cfg` attribute. The module allows us to group all of our tests together, and
246246
to also define helper functions if needed, that don't become a part of the rest
247247
of our crate. The `cfg` attribute only compiles our test code if we're
@@ -260,7 +260,7 @@ pub fn add_two(a: i32) -> i32 {
260260
}
261261
262262
#[cfg(test)]
263-
mod test {
263+
mod tests {
264264
use super::*;
265265
266266
#[test]
@@ -292,7 +292,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
292292

293293
It works!
294294

295-
The current convention is to use the `test` module to hold your "unit-style"
295+
The current convention is to use the `tests` module to hold your "unit-style"
296296
tests. Anything that just tests one small bit of functionality makes sense to
297297
go here. But what about "integration-style" tests instead? For that, we have
298298
the `tests` directory
@@ -346,7 +346,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
346346
Now we have three sections: our previous test is also run, as well as our new
347347
one.
348348

349-
That's all there is to the `tests` directory. The `test` module isn't needed
349+
That's all there is to the `tests` directory. The `tests` module isn't needed
350350
here, since the whole thing is focused on tests.
351351

352352
Let's finally check out that third section: documentation tests.

0 commit comments

Comments
 (0)