the Compartmented Robust Posix C++ Unit Test system

ASSERT_TRUE(expr)

Assert that an expression evaluates to true.

Used in: A test function body, the constructor or destructor of a fixture, or a function called from them. See TEST(name, ...).

Requirement: The expression expr can be evaluated as a bool.

The assertion succeeds if, and only if, bool(expr) evaluates to equal to true.

On success the test continues without side effects.

On failure the test is terminated with an error report. The report includes the exact expression text, and if the value is output streamable, a text representation of the expression value, otherwise a byte by byte hex dump is used.

Example: The test program

     
     #include <crpcut.hpp>
     #include <string>
     
     TEST(assert_true_succeeds)
     {
       std::string val;
       ASSERT_TRUE(val.empty());
     }
     
     TEST(assert_true_fails)
     {
       std::string val;
       ASSERT_TRUE(val.length());
     }
     
     int main(int argc, char *argv[])
     {
       return crpcut::run(argc, argv);
     }

        

reports one failed test:


     FAILED: assert_true_fails
     phase="running"  --------------------------------------------------------------
     /home/bjorn/devel/crpcut/doc-src/samples/assert_true_fails.cpp:40
     ASSERT_TRUE(val.length())
       where val.length() = 0
     -------------------------------------------------------------------------------
     ===============================================================================
     Total 2 test cases selected
     UNTESTED : 0
     PASSED   : 1
     FAILED   : 1