the Compartmented Robust Posix C++ Unit Test system

VERIFY_TRUE(expr)

Verify 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 check 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 marked as failed, but continues execution 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: ASSERT_TRUE(expr)

Example: The test program

     
     #include <crpcut.hpp>
     #include <string>
     
     TEST(verify_true_succeeds)
     {
       std::string val;
       VERIFY_TRUE(val.length() == 0U);
     }
     
     TEST(verify_true_fails)
     {
       std::string val;
       VERIFY_TRUE(val.length() > 0U);
       VERIFY_TRUE(!val.empty());
     }
     
     int main(int argc, char *argv[])
     {
       return crpcut::run(argc, argv);
     }

        

reports one failed test with two reported violations:


     FAILED!: verify_true_fails
     fail---------------------------------------------------------------------------
     samples/verify_true_fails.cpp:40
     VERIFY_TRUE(val.length() > 0U)
       is evaluated as:
         0 > 0
     -------------------------------------------------------------------------------
     fail---------------------------------------------------------------------------
     samples/verify_true_fails.cpp:41
     VERIFY_TRUE(!val.empty())
       is evaluated as:
         0
     -------------------------------------------------------------------------------
     phase="running"  --------------------------------------------------------------
     samples/verify_true_fails.cpp:37
     Earlier VERIFY failed
     -------------------------------------------------------------------------------
     ===============================================================================
     2 test cases selected
     
                    Sum   Critical   Non-critical
     PASSED   :       1          1              0
     FAILED   :       1          1              0