File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,21 @@ fn test_out_of_bounds_failure() {
89
89
}
90
90
~~~
91
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
+
92
107
A test runner built with the ` --test ` flag supports a limited set of
93
108
arguments to control which tests are run:
94
109
You can’t perform that action at this time.
0 commit comments