From ef6bda5321bb900cc3b929a9f4e625f0d78449a4 Mon Sep 17 00:00:00 2001 From: philsquared Date: Wed, 28 Mar 2012 11:14:06 -0700 Subject: [PATCH] First draft --- Assertion-Macros.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Assertion-Macros.md diff --git a/Assertion-Macros.md b/Assertion-Macros.md new file mode 100644 index 0000000..a6af092 --- /dev/null +++ b/Assertion-Macros.md @@ -0,0 +1,42 @@ + +# Assertion Macros + +Most test frameworks have a large collection of assertion macros to capture all possible conditional forms (_EQUALS, _NOTEQUALS, _GREATER_THAN etc). + +CATCH is different. Because it decomposes natural C-style conditional expressions most of these forms are reduced to one or two that you will use all the time. That said there are a rich set of auxilliary macros as well. We'll describe all of these here. + +Most of these macros come in two forms: + +## Natural Expressions + +The REQUIRE family of macros tests an expression and aborts the test case if it fails. +The CHECK family are equivalent but execution continues in the same test case even if the assertion fails. This is useful if you have a series of essentially orthoginal assertions and it is useful to see all the results rather than stopping at the first failure. + +**REQUIRE(** _expression_ **)** and +**CHECK(** _expression_ **)** +Evaluates the expression and records the result. If an exception is thrown it is caught, reported, and counted as a failure. These are the macros you will use most of the time +

+ +**REQUIRE_FALSE(** _expression_ **)** and +**CHECK_FALSE(** _expression_ **)** +Evaluates the expression and records the _logical NOT_ of the result. If an exception is thrown it is caught, reported, and counted as a failure. +(these forms exist as a workaround for the fact that ! prefixed expressions cannot be decomposed). + +**REQUIRE_THROWS(** _expression_ **)** and +**CHECK_THROWS(** _expression_ **)** +Expects that an exception (of any type) is be thrown during evaluation of the expression. + +**REQUIRE_THROWS_AS(** _expression_ and _exception type_ **)** and +**CHECK_THROWS_AS(** _expression_, _exception type_ **)** +Excepts that an exception of the _specified type_ is thrown during evaluation of the expression. + +**REQUIRE_NOTHROWS(** _expression_ **)** and +**CHECK_NOTHROWS(** _expression_ **)** +Excepts that no exception is thrown during evaluation of the expression. + +## Matcher expressions + +To support Matchers a slightly different form is used. Matchers will be more fully documented elsewhere. + +**REQUIRE_THAT(** _lhs_, __matcher call__ **)** and +**CHECK_THAT(** _lhs_, __matcher call__ **)**