Skip to main content

verify_eq

Macro verify_eq 

Source
macro_rules! verify_eq {
    ($actual:expr, [ $( ( $($tuple_elt:expr),* ) ),+ $(,)? ] $(,)?) => { ... };
    ($actual:expr, { $( ( $($tuple_elt:expr),* ) ),+ $(,)?} $(,)?) => { ... };
    ($actual:expr, [$($expected:expr),+ $(,)?] $(,)?) => { ... };
    ($actual:expr, {$($expected:expr),+ $(,)?} $(,)?) => { ... };
    ($actual:expr, $expected:expr $(,)?) => { ... };
}
Expand description

Checks whether the second argument is equal to the first argument.

Evaluates to Result::Ok(()) if they are equal and Result::Err(TestAssertionFailure) if they are not. The caller must then decide how to handle the Err variant. It has a few options:

  • Abort the current function with the ? operator. This requires that the function return a suitable Result.
  • Log the test failure and continue by calling the method and_log_failure.

Of course, one can also use all other standard methods on Result.

Invoking this macro by itself does not cause a test failure to be recorded or output. The resulting Result must be handled as described above to cause the test to be recorded as a failure.

Example:

use googletest::prelude::*;

#[test]
fn should_fail() -> Result<()> {
    verify_eq!(2, 1)
}

This macro has special support for matching against container. Namely:

  • verify_eq!(actual, [e1, e2, ...]) is equivalent to verify_that!(actual, elements_are![eq(e1), eq(e2), ...])
  • verify_eq!(actual, {e1, e2, ...}) is equivalent to verify_that!(actual, unordered_elements_are![eq(e1), eq(e2), ...])