pub trait GoogleTestSupport {
    // Required methods
    fn and_log_failure(self);
    fn failure_message(self, message: impl Into<String>) -> Self;
    fn with_failure_message(self, provider: impl FnOnce() -> String) -> Self;
}
Expand description

Adds to Result support for GoogleTest Rust functionality.

Required Methods§

source

fn and_log_failure(self)

If self is a Result::Err, writes to stdout a failure report and marks the test failed. Otherwise, does nothing.

This can be used for non-fatal test assertions, for example:

let actual = 42;
verify_that!(actual, eq(42)).and_log_failure();
                                 // Test still passing; nothing happens
verify_that!(actual, eq(10)).and_log_failure();
                         // Test now fails and failure output to stdout
verify_that!(actual, eq(100)).and_log_failure();
              // Test still fails and new failure also output to stdout
source

fn failure_message(self, message: impl Into<String>) -> Self

Adds message to the logged failure message if self is a Result::Err. Otherwise, does nothing.

If this method is called more than once, only message from the last invocation is output.

For example:

let actual = 0;
verify_that!(actual, eq(42)).failure_message("Actual was wrong!")?;

results in the following failure message:

Expected: actual equal to 42
  but was: 0
Actual was wrong!

One can pass a String too:

let actual = 0;
verify_that!(actual, eq(42))
   .failure_message(format!("Actual {} was wrong!", actual))?;

However, consider using GoogleTestSupport::with_failure_message instead in that case to avoid unnecessary memory allocation when the message is not needed.

source

fn with_failure_message(self, provider: impl FnOnce() -> String) -> Self

Adds the output of the closure provider to the logged failure message if self is a Result::Err. Otherwise, does nothing.

This is analogous to GoogleTestSupport::failure_message but only executes the closure provider if it actually produces the message, thus saving possible memory allocation.

let actual = 0;
verify_that!(actual, eq(42))
   .with_failure_message(|| format!("Actual {} was wrong!", actual))?;

Object Safety§

This trait is not object safe.

Implementors§