pub trait AssertCodePanics<'a, R> {
// Required methods
fn does_not_panic(self) -> Spec<'a, (), R>;
fn panics(self) -> Spec<'a, (), R>;
fn panics_with_message(self, message: impl Into<String>) -> Spec<'a, (), R>;
}Available on crate feature
panic only.Expand description
Assert that the code under test panics, panics with a certain message or does not panic.
§Examples
use asserting::prelude::*;
fn do_something(input: &str) {
if input.is_empty() {
panic!("input is empty");
}
}
assert_that_code!(|| {
do_something("correct input");
}).does_not_panic();
assert_that_code!(|| {
do_something("");
}).panics();
assert_that_code!(|| {
do_something("");
}).panics_with_message("input is empty");Required Methods§
Sourcefn does_not_panic(self) -> Spec<'a, (), R>
fn does_not_panic(self) -> Spec<'a, (), R>
Verifies that the actual code under test does not panic.
§Example
use asserting::prelude::*;
fn do_something(input: &str) {
if input.is_empty() {
panic!("input is empty");
}
}
assert_that_code!(|| {
do_something("correct input");
}).does_not_panic();Sourcefn panics(self) -> Spec<'a, (), R>
fn panics(self) -> Spec<'a, (), R>
Verifies that the actual code under test panics with any message.
§Example
use asserting::prelude::*;
fn do_something(input: &str) {
if input.is_empty() {
panic!("input is empty");
}
}
assert_that_code!(|| {
do_something("");
}).panics();Sourcefn panics_with_message(self, message: impl Into<String>) -> Spec<'a, (), R>
fn panics_with_message(self, message: impl Into<String>) -> Spec<'a, (), R>
Verifies that the actual code under test panics with the given message.
§Example
use asserting::prelude::*;
fn do_something(input: &str) {
if input.is_empty() {
panic!("input is empty");
}
}
assert_that_code!(|| {
do_something("");
}).panics_with_message("input is empty");Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.