Skip to content

Style guidelines: Change name of unit test sub-module to "tests". #24783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/doc/style/testing/unit.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
% Unit testing

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

The `test` module should contain:
The `tests` module should contain:

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

#[cfg(test)]
mod test {
mod tests {
#[test]
fn test_eq() {
assert!((eq(&"".to_owned(), &"".to_owned())));
Expand Down
22 changes: 11 additions & 11 deletions src/doc/trpl/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ fn it_works() {
This is a very common use of `assert_eq!`: call some function with
some known arguments and compare it to the expected output.

# The `test` module
# The `tests` module

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

```{rust,ignore}
Expand All @@ -231,7 +231,7 @@ pub fn add_two(a: i32) -> i32 {
}

#[cfg(test)]
mod test {
mod tests {
use super::add_two;

#[test]
Expand All @@ -241,7 +241,7 @@ mod test {
}
```

There's a few changes here. The first is the introduction of a `mod test` with
There's a few changes here. The first is the introduction of a `mod tests` with
a `cfg` attribute. The module allows us to group all of our tests together, and
to also define helper functions if needed, that don't become a part of the rest
of our crate. The `cfg` attribute only compiles our test code if we're
Expand All @@ -260,7 +260,7 @@ pub fn add_two(a: i32) -> i32 {
}

#[cfg(test)]
mod test {
mod tests {
use super::*;

#[test]
Expand All @@ -279,7 +279,7 @@ $ cargo test
Running target/adder-91b3e234d4ed382a

running 1 test
test test::it_works ... ok
test tests::it_works ... ok

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

Expand All @@ -292,7 +292,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

It works!

The current convention is to use the `test` module to hold your "unit-style"
The current convention is to use the `tests` module to hold your "unit-style"
tests. Anything that just tests one small bit of functionality makes sense to
go here. But what about "integration-style" tests instead? For that, we have
the `tests` directory
Expand Down Expand Up @@ -325,7 +325,7 @@ $ cargo test
Running target/adder-91b3e234d4ed382a

running 1 test
test test::it_works ... ok
test tests::it_works ... ok

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

Expand All @@ -346,7 +346,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
Now we have three sections: our previous test is also run, as well as our new
one.

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

Let's finally check out that third section: documentation tests.
Expand Down Expand Up @@ -382,7 +382,7 @@ pub fn add_two(a: i32) -> i32 {
}

#[cfg(test)]
mod test {
mod tests {
use super::*;

#[test]
Expand All @@ -405,7 +405,7 @@ $ cargo test
Running target/adder-91b3e234d4ed382a

running 1 test
test test::it_works ... ok
test tests::it_works ... ok

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

Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ mod imp {
}

#[cfg(test)]
mod test {
mod tests {
extern crate test;
use self::test::Bencher;
use boxed::Box;
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ impl<A: Hash> Hash for LinkedList<A> {
}

#[cfg(test)]
mod test {
mod tests {
use std::clone::Clone;
use std::iter::{Iterator, IntoIterator};
use std::option::Option::{Some, None, self};
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ impl<T: fmt::Debug> fmt::Debug for VecDeque<T> {
}

#[cfg(test)]
mod test {
mod tests {
use core::iter::{Iterator, self};
use core::option::Option::Some;

Expand Down
2 changes: 1 addition & 1 deletion src/libcoretest/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn test_num<T>(ten: T, two: T) where
}

#[cfg(test)]
mod test {
mod tests {
use core::option::Option;
use core::option::Option::{Some, None};
use core::num::Float;
Expand Down
2 changes: 1 addition & 1 deletion src/librand/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl Rand for ChaChaRng {


#[cfg(test)]
mod test {
mod tests {
use std::prelude::v1::*;

use core::iter::order;
Expand Down
2 changes: 1 addition & 1 deletion src/librand/distributions/exponential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl IndependentSample<f64> for Exp {
}

#[cfg(test)]
mod test {
mod tests {
use std::prelude::v1::*;

use distributions::{Sample, IndependentSample};
Expand Down
2 changes: 1 addition & 1 deletion src/librand/distributions/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl IndependentSample<f64> for StudentT {
}

#[cfg(test)]
mod test {
mod tests {
use std::prelude::v1::*;

use distributions::{Sample, IndependentSample};
Expand Down
2 changes: 1 addition & 1 deletion src/librand/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl Rand for Isaac64Rng {


#[cfg(test)]
mod test {
mod tests {
use std::prelude::v1::*;

use core::iter::order;
Expand Down
2 changes: 1 addition & 1 deletion src/librand/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl Default for ReseedWithDefault {
}

#[cfg(test)]
mod test {
mod tests {
use std::prelude::v1::*;

use core::iter::{order, repeat};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ impl fmt::Display for CrateType {
}

#[cfg(test)]
mod test {
mod tests {

use session::config::{build_configuration, optgroups, build_session_options};
use session::build_session;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn realpath(original: &Path) -> io::Result<PathBuf> {
}

#[cfg(all(not(windows), test))]
mod test {
mod tests {
use tempdir::TempDir;
use std::fs::{self, File};
use super::realpath;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn minimize_rpaths(rpaths: &[String]) -> Vec<String> {
}

#[cfg(all(unix, test))]
mod test {
mod tests {
use super::{RPathConfig};
use super::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
use std::path::{Path, PathBuf};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use std::usize;
use snapshot_vec::{SnapshotVec, SnapshotVecDelegate};

#[cfg(test)]
mod test;
mod tests;

pub struct Graph<N,E> {
nodes: SnapshotVec<Node<N>> ,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/unify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::marker::PhantomData;
use snapshot_vec as sv;

#[cfg(test)]
mod test;
mod tests;

/// This trait is implemented by any type that can serve as a type
/// variable. We call such variables *unification keys*. For example,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/toc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl fmt::Display for Toc {
}

#[cfg(test)]
mod test {
mod tests {
use super::{TocBuilder, Toc, TocEntry};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/dynamic_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl DynamicLibrary {
}

#[cfg(all(test, not(target_os = "ios")))]
mod test {
mod tests {
use super::*;
use prelude::v1::*;
use libc;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ pub fn _print(args: fmt::Arguments) {
}

#[cfg(test)]
mod test {
mod tests {
use thread;
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Write for Sink {
}

#[cfg(test)]
mod test {
mod tests {
use prelude::v1::*;

use io::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rand/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ mod imp {
}

#[cfg(test)]
mod test {
mod tests {
use prelude::v1::*;

use sync::mpsc::channel;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rand/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<R: Read> Rng for ReaderRng<R> {
}

#[cfg(test)]
mod test {
mod tests {
use prelude::v1::*;

use super::ReaderRng;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn log_enabled() -> bool {
}

#[cfg(test)]
mod test {
mod tests {
use prelude::v1::*;
use sys_common;
macro_rules! t { ($a:expr, $b:expr) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<A:Send+'static> Future<A> {
}

#[cfg(test)]
mod test {
mod tests {
use prelude::v1::*;
use sync::mpsc::channel;
use sync::Future;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ impl error::Error for TryRecvError {
}

#[cfg(test)]
mod test {
mod tests {
use prelude::v1::*;

use std::env;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/mpsc/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl Iterator for Packets {

#[cfg(test)]
#[allow(unused_imports)]
mod test {
mod tests {
use prelude::v1::*;

use thread;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/mpsc/spsc_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<T> Drop for Queue<T> {
}

#[cfg(test)]
mod test {
mod tests {
use prelude::v1::*;

use sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ pub fn guard_poison<'a, T>(guard: &MutexGuard<'a, T>) -> &'a poison::Flag {
}

#[cfg(test)]
mod test {
mod tests {
use prelude::v1::*;

use sync::mpsc::channel;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Once {
}

#[cfg(test)]
mod test {
mod tests {
use prelude::v1::*;

use thread;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/common/remutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl<'a, T> Drop for ReentrantMutexGuard<'a, T> {


#[cfg(test)]
mod test {
mod tests {
use prelude::v1::*;
use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
use cell::RefCell;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ fn _assert_sync_and_send() {
////////////////////////////////////////////////////////////////////////////////

#[cfg(test)]
mod test {
mod tests {
use prelude::v1::*;

use any::Any;
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ pub struct MacroDef {
}

#[cfg(test)]
mod test {
mod tests {
use serialize;
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ pub fn lit_is_str(lit: &Lit) -> bool {
}

#[cfg(test)]
mod test {
mod tests {
use ast::*;
use super::*;

Expand Down
Loading