| the Compartmented Robust Posix C++ Unit Test system | hosted by |
|---|
Immediately terminate a test with an customized error report.
The macro FAIL is used as an output stream
object.
Used in: A test function body, the constructor or destructor of a
fixture, or a function called from
them.
See TEST(name, ...).
To fail a test with a customized error report, use the
FAIL macro as any output stream. All information
desired in the error report must fit in one single statement.
Example: The test program
#include <crpcut.hpp>
#include <cstring>
const char *expected_string = 0;
void assert_string(const char *p)
{
if (!p) FAIL << "assert_string called with 0";
if (!expected_string) return;
if (std::strcmp(p, expected_string) != 0)
{
FAIL << "assert_string called with " << p
<< "\nwhen the expected string was " << expected_string;
}
}
TEST(fail_null)
{
assert_string(0);
}
TEST(pass_no_expect)
{
assert_string("rope");
}
TEST(fail_wrong_string)
{
expected_string = "wire";
assert_string("rope");
}
int main(int argc, char *argv[])
{
return crpcut::run(argc, argv);
}
provides two detailed failure reports:
FAILED: fail_null
phase="running" --------------------------------------------------------------
/home/bjorn/devel/crpcut/doc-src/samples/fail.cpp:35
assert_string called with 0
-------------------------------------------------------------------------------
===============================================================================
FAILED: fail_wrong_string
phase="running" --------------------------------------------------------------
/home/bjorn/devel/crpcut/doc-src/samples/fail.cpp:39
assert_string called with rope
when the expected string was wire
-------------------------------------------------------------------------------
===============================================================================
Total 3 test cases selected
UNTESTED : 0
PASSED : 1
FAILED : 2