Skip to content

Commit 07cc7d9

Browse files
committed
Change name of unit test sub-module to "tests".
Changes the style guidelines regarding unit tests to recommend using a sub-module named "tests" instead of "test" for unit tests as "test" might clash with imports of libtest.
1 parent 2214860 commit 07cc7d9

File tree

48 files changed

+59
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+59
-59
lines changed

src/doc/style/testing/unit.md

Lines changed: 4 additions & 4 deletions
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

Lines changed: 11 additions & 11 deletions
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 a `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]
@@ -279,7 +279,7 @@ $ cargo test
279279
Running target/adder-91b3e234d4ed382a
280280

281281
running 1 test
282-
test test::it_works ... ok
282+
test tests::it_works ... ok
283283

284284
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
285285

@@ -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
@@ -325,7 +325,7 @@ $ cargo test
325325
Running target/adder-91b3e234d4ed382a
326326

327327
running 1 test
328-
test test::it_works ... ok
328+
test tests::it_works ... ok
329329

330330
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
331331

@@ -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.
@@ -382,7 +382,7 @@ pub fn add_two(a: i32) -> i32 {
382382
}
383383
384384
#[cfg(test)]
385-
mod test {
385+
mod tests {
386386
use super::*;
387387
388388
#[test]
@@ -405,7 +405,7 @@ $ cargo test
405405
Running target/adder-91b3e234d4ed382a
406406

407407
running 1 test
408-
test test::it_works ... ok
408+
test tests::it_works ... ok
409409

410410
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
411411

src/liballoc/heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ mod imp {
384384
}
385385

386386
#[cfg(test)]
387-
mod test {
387+
mod tests {
388388
extern crate test;
389389
use self::test::Bencher;
390390
use boxed::Box;

src/libcollections/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ impl<A: Hash> Hash for LinkedList<A> {
933933
}
934934

935935
#[cfg(test)]
936-
mod test {
936+
mod tests {
937937
use std::clone::Clone;
938938
use std::iter::{Iterator, IntoIterator};
939939
use std::option::Option::{Some, None, self};

src/libcollections/vec_deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ impl<T: fmt::Debug> fmt::Debug for VecDeque<T> {
17721772
}
17731773

17741774
#[cfg(test)]
1775-
mod test {
1775+
mod tests {
17761776
use core::iter::{Iterator, self};
17771777
use core::option::Option::Some;
17781778

src/libcoretest/num/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn test_num<T>(ten: T, two: T) where
4545
}
4646

4747
#[cfg(test)]
48-
mod test {
48+
mod tests {
4949
use core::option::Option;
5050
use core::option::Option::{Some, None};
5151
use core::num::Float;

src/librand/chacha.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl Rand for ChaChaRng {
202202

203203

204204
#[cfg(test)]
205-
mod test {
205+
mod tests {
206206
use std::prelude::v1::*;
207207

208208
use core::iter::order;

src/librand/distributions/exponential.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl IndependentSample<f64> for Exp {
8282
}
8383

8484
#[cfg(test)]
85-
mod test {
85+
mod tests {
8686
use std::prelude::v1::*;
8787

8888
use distributions::{Sample, IndependentSample};

src/librand/distributions/gamma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl IndependentSample<f64> for StudentT {
276276
}
277277

278278
#[cfg(test)]
279-
mod test {
279+
mod tests {
280280
use std::prelude::v1::*;
281281

282282
use distributions::{Sample, IndependentSample};

src/librand/isaac.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ impl Rand for Isaac64Rng {
510510

511511

512512
#[cfg(test)]
513-
mod test {
513+
mod tests {
514514
use std::prelude::v1::*;
515515

516516
use core::iter::order;

0 commit comments

Comments
 (0)