From 30fc4b765ce378d65fa0bb1472ecda45e95527da Mon Sep 17 00:00:00 2001 From: Adam Crume Date: Sun, 23 Aug 2015 13:51:26 -0700 Subject: [PATCH 1/3] book: Talk about ignore attribute in testing guide --- src/doc/trpl/testing.md | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/doc/trpl/testing.md b/src/doc/trpl/testing.md index cbf33febf876f..9143d10cfa1bf 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 From f56a478377d3750425391b646c8fcc6c3319f941 Mon Sep 17 00:00:00 2001 From: Adam Crume Date: Mon, 24 Aug 2015 21:52:33 -0700 Subject: [PATCH 2/3] book: Fix spacing in testing section --- src/doc/trpl/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/testing.md b/src/doc/trpl/testing.md index 9143d10cfa1bf..2911cf60375f5 100644 --- a/src/doc/trpl/testing.md +++ b/src/doc/trpl/testing.md @@ -221,7 +221,7 @@ 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 +Sometimes a few specific tests can be very time-consuming to execute. These can be disabled by default by using the `ignore` attribute: ```rust From 574deb73babed08daa0a5e63f44b363282535254 Mon Sep 17 00:00:00 2001 From: Adam Crume Date: Mon, 24 Aug 2015 21:53:02 -0700 Subject: [PATCH 3/3] book: Mention that --ignored is a test binary argument --- src/doc/trpl/testing.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/doc/trpl/testing.md b/src/doc/trpl/testing.md index 2911cf60375f5..78803afd5c1ad 100644 --- a/src/doc/trpl/testing.md +++ b/src/doc/trpl/testing.md @@ -276,6 +276,9 @@ running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured ``` +The `--ignored` argument is an argument to the test binary, and not to cargo, +which is why the command is `cargo test -- --ignored`. + # The `tests` module There is one way in which our existing example is not idiomatic: it's