]> git.lizzy.rs Git - rust.git/commitdiff
Mention expected in testing docs
authorSteven Fackler <sfackler@gmail.com>
Sat, 6 Dec 2014 23:33:33 +0000 (15:33 -0800)
committerSteven Fackler <sfackler@gmail.com>
Mon, 8 Dec 2014 00:04:56 +0000 (16:04 -0800)
src/doc/guide-testing.md

index a3bf810dde180f46081420ab0d21c8931d7b54df..f7cf5e5ac0019c9dd6e847625a2d8024b0e92d90 100644 (file)
@@ -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: