the Compartmented Robust Posix C++ Unit Test system

TESTSUITE(name, ...)

Define a testsuite for grouping of tests.

Used in: Global or testsuite scope

A testsuite has a name and a scope. The scope of a testsuite is defined by the curly brace pair. Tests defined inside a testsuite gets a scoped name testsuitename::testname. Testsuites can be nested.

Example. The following test program:

     
     #include <crpcut.hpp>
     
     TESTSUITE(outer)
     {
       TESTSUITE(inner)
       {
         TEST(fail)
         {
           FAIL << "just for show";
         }
       }
     }
     
     int main(int argc, char *argv[])
     {
       return crpcut::run(argc, argv);
     }

        

Shows the failure of a test in a testsuite.


     FAILED!: outer::inner::fail
     phase="running"  --------------------------------------------------------------
     samples/simple_testsuite.cpp:36
     just for show
     -------------------------------------------------------------------------------
     ===============================================================================
     1 test cases selected
     
                    Sum   Critical   Non-critical
     FAILED   :       1          1              0

        

A test can depend on a testsuite, and a testsuite can depend on both tests and other testsuites. Dependency requirements for a testsuite are expressed using the DEPENDS_ON(...) modifier as the second argument to the TESTSUITE(name, ...) macro.

A testsuite is a C++ namespace. It is possible to declare a dependency for a testsuite implemented in another source file.

Example: Cross-file testsuite dependency

     
     #include <crpcut.hpp>
     
     TESTSUITE(external_pass)
     {
       TEST(passes)
       {
       }
     }
     
     TESTSUITE(external_fail)
     {
       TEST(fails)
       {
         FAIL << "Just for show";
       }
     }
     

     
     #include <crpcut.hpp>
     
     TESTSUITE(external_pass) // defined in other source file
     {
     }
     
     TESTSUITE(external_fail) // defined in other source file
     {
     }
     
     TESTSUITE(depend_pass, DEPENDS_ON(ALL_TESTS(external_pass)))
     {
       TEST(will_pass)
       {
       }
     }
     
     TESTSUITE(depend_fail, DEPENDS_ON(ALL_TESTS(external_fail)))
     {
       TEST(will_not_run)
       {
       }
     }
     
     int main(int argc, char *argv[])
     {
       return crpcut::run(argc, argv);
     }

reports one failed test, and one that did not run:


     FAILED!: external_fail::fails
     phase="running"  --------------------------------------------------------------
     /home/bjorn/devel/crpcut/doc-src/samples/suite_define.cpp:41
     Just for show
     -------------------------------------------------------------------------------
     ===============================================================================
     The following tests were blocked from running:
       !depend_fail::will_not_run
     4 test cases selected
     
                    Sum   Critical   Non-critical
     PASSED   :       2          2              0
     FAILED   :       1          1              0
     UNTESTED :       1

Defining tests in testsuites distributed over several files is ill advised.