...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
In this usage variant and in the translation unit containing the definition
of BOOST_TEST_MODULE
, you need to
define the macros BOOST_TEST_NO_MAIN
and BOOST_TEST_ALTERNATIVE_INIT_API
(their values are irrelevant) prior to including any of the framework's
headers. Next, you have to define your custom entry point, and invoke the
default test
runner unit_test_main
manually with the default initialization
function init_unit_test
as argument.
Code |
---|
#define BOOST_TEST_MODULE custom_main #define BOOST_TEST_NO_MAIN #define BOOST_TEST_ALTERNATIVE_INIT_API #include <boost/test/included/unit_test.hpp> #include <iostream> namespace utf = boost::unit_test; BOOST_AUTO_TEST_CASE(test1) { BOOST_TEST(false); } void make_use_of(char**) { std::cout << "Using custom entry point..." << std::endl; } int main(int argc, char* argv[], char* envp[]) { make_use_of(envp); return utf::unit_test_main(init_unit_test, argc, argv); } |
Output |
---|
> custom_main Using custom entry point... Running 1 test case... test.cpp(10): error: in "test1": check false has failed *** 1 failure is detected in the test module "custom_main" |
In the above example, a custom entry point was selected because the test module, in addition to command line arguments, needs to obtain also the information about environment variables.
Note | |
---|---|
The above example also illustrates that it makes sense to define both
|
Note | |
---|---|
The reason for defining |