about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAdam Crume <adamcrume@gmail.com>2015-08-23 13:51:26 -0700
committerAdam Crume <adamcrume@gmail.com>2015-08-23 13:53:52 -0700
commit30fc4b765ce378d65fa0bb1472ecda45e95527da (patch)
treecf41d95562be98c69f58cfcdb3fe2b5733fbc175 /src
parent9f227ca2c2150205fcc39d7a3b1839eb592baee0 (diff)
downloadrust-30fc4b765ce378d65fa0bb1472ecda45e95527da.tar.gz
rust-30fc4b765ce378d65fa0bb1472ecda45e95527da.zip
book: Talk about ignore attribute in testing guide
Diffstat (limited to 'src')
-rw-r--r--src/doc/trpl/testing.md57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/doc/trpl/testing.md b/src/doc/trpl/testing.md
index cbf33febf87..9143d10cfa1 100644
--- a/src/doc/trpl/testing.md
+++ b/src/doc/trpl/testing.md
@@ -219,6 +219,63 @@ 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 `ignore` attribute
+
+Sometimes a few specific tests can be very time-consuming to execute.  These
+can be disabled by default by using the `ignore` attribute:
+
+```rust
+#[test]
+fn it_works() {
+    assert_eq!(4, add_two(2));
+}
+
+#[test]
+#[ignore]
+fn expensive_test() {
+    // code that takes an hour to run
+}
+```
+
+Now we run our tests and see that `it_works` is run, but `expensive_test` is
+not:
+
+```bash
+$ cargo test
+   Compiling adder v0.0.1 (file:///home/you/projects/adder)
+     Running target/adder-91b3e234d4ed382a
+
+running 2 tests
+test expensive_test ... ignored
+test it_works ... ok
+
+test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured
+
+   Doc-tests adder
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+```
+
+The expensive tests can be run explicitly using `cargo test -- --ignored`:
+
+```bash
+$ cargo test -- --ignored
+     Running target/adder-91b3e234d4ed382a
+
+running 1 test
+test expensive_test ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
+
+   Doc-tests adder
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+```
+
 # The `tests` module
 
 There is one way in which our existing example is not idiomatic: it's