Macro expect_that

Source
macro_rules! expect_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, marking the test as failed but continuing execution if it does not match.

This is a non-fatal assertion: the test continues execution in the event of assertion failure.

This can only be invoked inside tests with the gtest attribute. The assertion must occur in the same thread as that running the test itself.

Invoking this macro is equivalent to using and_log_failure as follows:

verify_that!(actual, expected).and_log_failure()

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";
expect_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.