the Compartmented Robust Posix C++ Unit Test system


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.

See also: VERIFY_TRUE(expr)

Example: The test program

     #include <crpcut.hpp>
     #include <string>
       std::string val;
       ASSERT_TRUE(val.length() == 0U);
       std::string val;
       ASSERT_TRUE(val.length() > 0U);
     int main(int argc, char *argv[])
       return crpcut::run(argc, argv);


reports one failed test:

     FAILED!: assert_true_fails
     phase="running"  --------------------------------------------------------------
     ASSERT_TRUE(val.length() > 0U)
       is evaluated as:
         0 > 0
     2 test cases selected
                    Sum   Critical   Non-critical
     PASSED   :       1          1              0
     FAILED   :       1          1              0