macro_rules! assert_that {
($actual:expr, [ $($expected:expr),* ] $(,)?) => { ... };
($actual:expr, { $($expected:expr),* } $(,)?) => { ... };
($actual:expr, [ $($expected:expr),* ], $($format_args:expr),* $(,)?) => { ... };
($actual:expr, { $($expected:expr),* }, $($format_args:expr),* $(,)?) => { ... };
($actual:expr, $expected:expr $(,)?) => { ... };
($actual:expr, $expected:expr, $($format_args:expr),* $(,)?) => { ... };
}
Expand description
Matches the given value against the given matcher, panicking if it does not match.
ⓘ
let value = 2;
assert_that!(value, eq(3)); // Fails and panics.
This is analogous to assertions in most Rust test libraries, where a failed assertion causes a panic.
One may optionally add arguments which will be formatted and appended to a failure message. For example:
ⓘ
let value = 2;
let extra_information = "Some additional information";
assert_that!(value, eq(3), "Test failed. Extra information: {extra_information}.");
This is output as follows:
Value of: value
Expected: is equal to 3
Actual: 2,
which isn't equal to 3
at ...
Test failed. Extra information: Some additional information.
Note for users of GoogleTest for C++:
This differs from the ASSERT_THAT
macro in that it panics rather
than triggering an early return from the invoking function. To get behaviour
equivalent to ASSERT_THAT
, use verify_that!
with the ?
operator.