Skip to main content

verify_false

Macro verify_false 

Source
macro_rules! verify_false {
    ($condition:expr) => { ... };
}
Expand description

Verify if the condition evaluates to false and returns Result.

Evaluates to Result::Ok(()) if the condition is false and Result::Err(TestAssertionFailure) if it evaluates to true. 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 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_false!(2 + 2 == 4)
}