Macro galvanic_assert::assert_that [] [src]

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

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.

    Be careful when using this code, it's not being tested!
    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.

    Be careful when using this code, it's not being tested!
    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.

    Be careful when using this code, it's not being tested!
    assert_that!(panic!("panic"), panics);
    assert_that!(1+1, does not panic);