unittest-cpp/unittest-cpp — pull request #57 by paxos1977 (2014-10-11 21:10:28+00:00)
Title: Adding REQUIRE_* versions of macros that stop the test on a failure (via exception)

Introducing additional functionality to allow client code to stop a unit test when an assert fails.

The following macros have been added:
REQUIRE_CHECK
REQUIRE_EQUAL
REQUIRE_CLOSE
REQUIRE_ARRAY_EQUAL
REQUIRE_ARRAY_CLOSE
REQUIRE_ARRAY2D_CLOSE
REQUIRE_THROW
REQUIRE_ASSERT

An example of when these type of checks are useful:

std::vector v = foo();

REQUIRE_EQUAL(3, v.size()); // test stops here on a fail
// so we don't segfault looking at
// v[0] below.
CHECK_EQUAL(1, v[0]);
CHECK_EQUAL(2, v[1]);
CHECK_EQUAL(3, v[2]);

When UNITTEST_NO_EXCEPTIONS is defined, the behavior of the REQUIRE_*
macros falls back to match their CHECK_* counterparts. This means in the
above example that we would segfault checking v[0] should v not be of
size 3.