Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Test] Unable to perform init at startup
From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2014-01-12 17:40:46


Adam Nielsen <a.nielsen <at> shikadi.net> writes:

> This works fine, except that I need to create the factory class before
> the tests can be run. In case the factory class fails, I want to use
> some of the Boost.Test checks in the initialisation function.
>
> However when I do this, I get this runtime error:

Indeed you can't access Boost.Test facilities before its own initialization
is run.
 
> terminate called after throwing an instance of 'std::runtime_error'
> what(): can't use testing tools before framework is initialized
>
> I am assuming this means I need to wait with the construction of my
> factory class until Boost.Test is ready, but I am unsure how to do this.

One way or another you need to postpone your assertions till after
Boost.Test init.

> I am #defining BOOST_TEST_MODULE, and when I try to declare a function

What usage variant of boost.test you employ? static/shared/included?

> called init_unit_test() as suggested in the docs it tells me the
> function already exists. If I remove the BOOST_TEST_MODULE #define,
> then it complains that main() is not implemented.

It appears you are using shared library.

In this case you can define BOOST_TEST_MODULE and BOOST_TEST_NO_MAIN. In
this case you can define your own main like this:

int BOOST_TEST_CALL_DECL
main( int argc, char* argv[] )
{
   // do my own init

   return ::boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
}

or you can skip BOOST_TEST_MODULE and define both main and init_test_module
routines.

Would you be using static lib, main will always be present, but
init_unit_test will depend on BOOST_TEST_MODULE.

HTH,
Gennadiy


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net