galvanic_assert

Macro assert_that

Source
macro_rules! assert_that {
    ( $actual: expr, panics ) => { ... };
    ( $actual: expr, does not panic ) => { ... };
    ( $actual: expr) => { ... };
    ( $actual: expr , otherwise $reason: expr ) => { ... };
    ( $actual: expr, $matcher: expr ) => { ... };
}
Expand description

States that the asserted value satisfies the required properties of the supplied Matcher.

The postulated assertion is verfied immediately and panics if it is not satisfied. The macro comes in three different forms:

  1. Assert that some expression is true, supplied with an optional error message.

    assert_that!(EXPRESSION);
    assert_that!(EXPRESSION, otherwise "some error message");
  2. Assert that some expression satifies the properties of some Matcher. Expressions used with Matchers must return a reference to a value. The Matcher is either predefined, a user defined type with a Matcher implementation, or a closure returning a MatchResult.

    assert_that!(&1, eq(1));
    assert_that!(&1, |&x| {
        let builder = MatchResultBuilder::for_("my_matcher");
        if x == 1 { builder.matched } else { builder.failed_because("some reason") }
    })
  3. Assert that some expression is expected to panic/not panic.

    assert_that!(panic!("panic"), panics);
    assert_that!(1+1, does not panic);