You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A function annotated with the `test`attribute that returns `()` can also be annotated with the `should_panic` attribute.
78
+
The *`should_panic`[attribute][attributes]* changes a [test function][attributes.testing.test] so that it passes only if it panics.
79
79
80
-
r[attributes.testing.should_panic.behavior]
81
-
The *`should_panic` attribute* makes the test only pass if it actually panics.
80
+
> [!EXAMPLE]
81
+
> ```rust
82
+
> #[test]
83
+
> #[should_panic(expected ="values don't match")]
84
+
> fnmytest() {
85
+
> assert_eq!(1, 2, "values don't match");
86
+
> }
87
+
> ```
82
88
83
89
r[attributes.testing.should_panic.syntax]
84
-
The `should_panic` attribute may optionally take an input string that must appear within the panic message. If the string is not found in the message, then the test will fail. The string may be passed using the [MetaNameValueStr] syntax or the [MetaListNameValueStr] syntax with an `expected` field.
90
+
The `should_panic` attributeisspecifiedwithoneofthefollowingforms:
0 commit comments