Skip to content

Commit e3d00a4

Browse files
committed
Auto merge of #24783 - jooert:unittestguidelines, r=alexcrichton
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 (see #23870, #24030 and http://users.rust-lang.org/t/guidelines-naming-of-unit-test-module/1078 for previous discussions). r? @alexcrichton
2 parents 54d6509 + 07cc7d9 commit e3d00a4

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

+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

+11-11
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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;

src/librand/reseeding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Default for ReseedWithDefault {
120120
}
121121

122122
#[cfg(test)]
123-
mod test {
123+
mod tests {
124124
use std::prelude::v1::*;
125125

126126
use core::iter::{order, repeat};

src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ impl fmt::Display for CrateType {
11111111
}
11121112

11131113
#[cfg(test)]
1114-
mod test {
1114+
mod tests {
11151115

11161116
use session::config::{build_configuration, optgroups, build_session_options};
11171117
use session::build_session;

src/librustc_back/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn realpath(original: &Path) -> io::Result<PathBuf> {
4141
}
4242

4343
#[cfg(all(not(windows), test))]
44-
mod test {
44+
mod tests {
4545
use tempdir::TempDir;
4646
use std::fs::{self, File};
4747
use super::realpath;

src/librustc_back/rpath.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn minimize_rpaths(rpaths: &[String]) -> Vec<String> {
171171
}
172172

173173
#[cfg(all(unix, test))]
174-
mod test {
174+
mod tests {
175175
use super::{RPathConfig};
176176
use super::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
177177
use std::path::{Path, PathBuf};

src/librustc_data_structures/graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use std::usize;
3636
use snapshot_vec::{SnapshotVec, SnapshotVecDelegate};
3737

3838
#[cfg(test)]
39-
mod test;
39+
mod tests;
4040

4141
pub struct Graph<N,E> {
4242
nodes: SnapshotVec<Node<N>> ,

src/librustc_data_structures/unify/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::marker::PhantomData;
1414
use snapshot_vec as sv;
1515

1616
#[cfg(test)]
17-
mod test;
17+
mod tests;
1818

1919
/// This trait is implemented by any type that can serve as a type
2020
/// variable. We call such variables *unification keys*. For example,

src/librustdoc/html/toc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl fmt::Display for Toc {
198198
}
199199

200200
#[cfg(test)]
201-
mod test {
201+
mod tests {
202202
use super::{TocBuilder, Toc, TocEntry};
203203

204204
#[test]

src/libstd/dynamic_lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl DynamicLibrary {
117117
}
118118

119119
#[cfg(all(test, not(target_os = "ios")))]
120-
mod test {
120+
mod tests {
121121
use super::*;
122122
use prelude::v1::*;
123123
use libc;

src/libstd/io/stdio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ pub fn _print(args: fmt::Arguments) {
418418
}
419419

420420
#[cfg(test)]
421-
mod test {
421+
mod tests {
422422
use thread;
423423
use super::*;
424424

src/libstd/io/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Write for Sink {
102102
}
103103

104104
#[cfg(test)]
105-
mod test {
105+
mod tests {
106106
use prelude::v1::*;
107107

108108
use io::prelude::*;

src/libstd/rand/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ mod imp {
346346
}
347347

348348
#[cfg(test)]
349-
mod test {
349+
mod tests {
350350
use prelude::v1::*;
351351

352352
use sync::mpsc::channel;

src/libstd/rand/reader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<R: Read> Rng for ReaderRng<R> {
6363
}
6464

6565
#[cfg(test)]
66-
mod test {
66+
mod tests {
6767
use prelude::v1::*;
6868

6969
use super::ReaderRng;

src/libstd/rt/backtrace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn log_enabled() -> bool {
3838
}
3939

4040
#[cfg(test)]
41-
mod test {
41+
mod tests {
4242
use prelude::v1::*;
4343
use sys_common;
4444
macro_rules! t { ($a:expr, $b:expr) => ({

src/libstd/sync/future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<A:Send+'static> Future<A> {
155155
}
156156

157157
#[cfg(test)]
158-
mod test {
158+
mod tests {
159159
use prelude::v1::*;
160160
use sync::mpsc::channel;
161161
use sync::Future;

src/libstd/sync/mpsc/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ impl error::Error for TryRecvError {
10651065
}
10661066

10671067
#[cfg(test)]
1068-
mod test {
1068+
mod tests {
10691069
use prelude::v1::*;
10701070

10711071
use std::env;

src/libstd/sync/mpsc/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl Iterator for Packets {
346346

347347
#[cfg(test)]
348348
#[allow(unused_imports)]
349-
mod test {
349+
mod tests {
350350
use prelude::v1::*;
351351

352352
use thread;

src/libstd/sync/mpsc/spsc_queue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<T> Drop for Queue<T> {
241241
}
242242

243243
#[cfg(test)]
244-
mod test {
244+
mod tests {
245245
use prelude::v1::*;
246246

247247
use sync::Arc;

src/libstd/sync/mutex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ pub fn guard_poison<'a, T>(guard: &MutexGuard<'a, T>) -> &'a poison::Flag {
361361
}
362362

363363
#[cfg(test)]
364-
mod test {
364+
mod tests {
365365
use prelude::v1::*;
366366

367367
use sync::mpsc::channel;

src/libstd/sync/once.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Once {
121121
}
122122

123123
#[cfg(test)]
124-
mod test {
124+
mod tests {
125125
use prelude::v1::*;
126126

127127
use thread;

src/libstd/sys/common/remutex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<'a, T> Drop for ReentrantMutexGuard<'a, T> {
151151

152152

153153
#[cfg(test)]
154-
mod test {
154+
mod tests {
155155
use prelude::v1::*;
156156
use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
157157
use cell::RefCell;

src/libstd/thread/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ fn _assert_sync_and_send() {
722722
////////////////////////////////////////////////////////////////////////////////
723723

724724
#[cfg(test)]
725-
mod test {
725+
mod tests {
726726
use prelude::v1::*;
727727

728728
use any::Any;

src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ pub struct MacroDef {
18691869
}
18701870

18711871
#[cfg(test)]
1872-
mod test {
1872+
mod tests {
18731873
use serialize;
18741874
use super::*;
18751875

src/libsyntax/ast_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ pub fn lit_is_str(lit: &Lit) -> bool {
632632
}
633633

634634
#[cfg(test)]
635-
mod test {
635+
mod tests {
636636
use ast::*;
637637
use super::*;
638638

0 commit comments

Comments
 (0)