| the Compartmented Robust Posix C++ Unit Test system | hosted by |
|---|
A test and testsuite modifier to state dependencies. The test(s) will not run until all dependencies are resolved, i.e. the referred tests have succeeded.
Used in: The modifier list of a test definition or testsuite definition.
See TEST(name, ...) and
TESTSUITE(name, ...)
The parameter to DEPENDS_ON(...) is a comma
separated list of dependencies. Each dependency can be either a
the name of a test, or
ALL_TESTS(testsuitename)
When DEPENDS_ON(...) is used for a testsuite,
the dependencies applies for all tests in the testsuite. It is possible
to constrain a single test further than the testsuite it resides in,
by adding a DEPENDS_ON(...) modifier to the
test.
It is not possible to state a dependency on a
DISABLED_TEST(name, ...).
![]() | Tip |
|---|---|
| It is often a good idea to let testsuites depend on testsuites, and tests to depend on other tests inside the same testsuite. |
![]() | Note |
|---|---|
DEPENDS_ON(...) can only be included once in
the modifier list for each
TEST(name, ...) or
TESTSUITE(name, ...).
|
Example: The test program
#include <crpcut.hpp>
struct A
{
A() {}
~A() { exit(0); }
void do_something() const {}
};
TESTSUITE(basics)
{
TEST(construct)
{
(void)new A(); // intentionally leak
}
TEST(destroy, DEPENDS_ON(construct))
{
A *p = new A();
delete p;
}
}
TESTSUITE(toy, DEPENDS_ON(ALL_TESTS(basics)))
{
TEST(work)
{
A obj;
obj.do_something();
}
}
int main(int argc, char *argv[])
{
return crpcut::run(argc, argv);
}
reports one failed test, and one that did not run:
FAILED: basics::destroy
phase="post_mortem" ----------------------------------------------------------
Exited with code 0
Expected normal exit
-------------------------------------------------------------------------------
===============================================================================
The following tests were blocked from running:
toy::work
Total 3 test cases selected
UNTESTED : 1
PASSED : 1
FAILED : 1
See also the -n
command line flag.