We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3246d4f commit a20926aCopy full SHA for a20926a
src/doc/guide-testing.md
@@ -89,6 +89,21 @@ fn test_out_of_bounds_failure() {
89
}
90
~~~
91
92
+`#[should_fail]` tests can be fragile as it's hard to guarantee that the test
93
+didn't fail for an unexpected reason. To help with this, an optional `expected`
94
+parameter can be added to the `should_fail` attribute. The test harness will
95
+make sure that the failure message contains the provided text. A safer version
96
+of the example above would be:
97
+
98
+~~~test_harness
99
+#[test]
100
+#[should_fail(expected = "index out of bounds")]
101
+fn test_out_of_bounds_failure() {
102
+ let v: &[int] = &[];
103
+ v[0];
104
+}
105
+~~~
106
107
A test runner built with the `--test` flag supports a limited set of
108
arguments to control which tests are run:
109
0 commit comments