From a20926a51add66ab67053843e244efb1a4d7ad76 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 6 Dec 2014 15:33:33 -0800 Subject: [PATCH] Mention expected in testing docs --- src/doc/guide-testing.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/doc/guide-testing.md b/src/doc/guide-testing.md index a3bf810dde1..f7cf5e5ac00 100644 --- a/src/doc/guide-testing.md +++ b/src/doc/guide-testing.md @@ -89,6 +89,21 @@ fn test_out_of_bounds_failure() { } ~~~ +`#[should_fail]` tests can be fragile as it's hard to guarantee that the test +didn't fail for an unexpected reason. To help with this, an optional `expected` +parameter can be added to the `should_fail` attribute. The test harness will +make sure that the failure message contains the provided text. A safer version +of the example above would be: + +~~~test_harness +#[test] +#[should_fail(expected = "index out of bounds")] +fn test_out_of_bounds_failure() { + let v: &[int] = &[]; + v[0]; +} +~~~ + A test runner built with the `--test` flag supports a limited set of arguments to control which tests are run: