the Compartmented Robust Posix C++ Unit Test system

INFO

Provide information that can be useful in determining in why a test failed.

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

Use INFO as an output stream object to provide information to test reports. Each INFO statement gives a separate report item. The output from an INFO statement is only shown if the test fails (or if the test is runs in verbose mode, see the -v / --verbose command line flag.)

If the data to be printed has an output stream operator, it will be used for the formatting, otherwise a hex-dump of the object memory will be shown.

[Note]Note
Since INFO uses a templated operator<<, it only works with types defined in global/namespace scope.

Example: The test program

     
     #include <crpcut.hpp>
     #include <cstring>
     
     const char *expected_string = 0;
     
     bool check_string(const char *p)
     {
       if (!expected_string) return false;
       INFO << "expected string = " << expected_string;
     
       return std::strcmp(p, expected_string) != 0;
     }
     
     TEST(pass_null)
     {
       check_string(0);
     }
     
     TEST(pass_no_init)
     {
       check_string("rope");
     }
     
     TEST(fail_null)
     {
       expected_string = "wire";
       check_string(0);
     }
     
     TEST(pass_wrong_string)
     {
       expected_string = "wire";
       check_string("rope");
     }
     
     int main(int argc, char *argv[])
     {
       return crpcut::run(argc, argv);
     }

        

provides one detailed failure report:


     FAILED!: fail_null
     info---------------------------------------------------------------------------
     samples/info.cpp:36
     expected string = wire
     -------------------------------------------------------------------------------
     /tmp/crpcutLQY1ic/fail_null is not empty!
     phase="running"  --------------------------------------------------------------
     samples/info.cpp:51
     Died with core dump
     -------------------------------------------------------------------------------
     ===============================================================================
     Files remain under /tmp/crpcutLQY1ic
     4 test cases selected
     
                    Sum   Critical   Non-critical
     PASSED   :       3          3              0
     FAILED   :       1          1              0