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() {
8989}
9090~~~
9191
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+
92107A test runner built with the ` --test ` flag supports a limited set of
93108arguments to control which tests are run:
94109
You can’t perform that action at this time.
0 commit comments