|
Boost Users : |
Subject: Re: [Boost-users] [test] Init framework before dataset generation
From: Raffi Enficiaud (raffi.enficiaud_at_[hidden])
Date: 2016-08-28 11:00:12
Le 24/08/16 à 13:04, Florian Lindner a écrit :
> Hello,
>
> I try to use boost test with data test cases:
>
> std::vector<float> fibonacci() {
> std::cout << "Data Set" << std::endl;
> [...]
> }
>
> BOOST_DATA_TEST_CASE(datatest, boost::unit_test::data::make(fibonacci()), mapping)
> {
> std::cout << "Datatype" << typeid(mapping).name() << std::endl;
> }
>
> The problem of that is, that fibonacci is initialized before anything else. The order of initializations is:
>
> Data Set
> main
> init_unit_test
> Global Fixture
>
> That works fine here, but my fibonacci uses MPI which needs to initialized by MPI_Init. I want to do that initialization in the global fixture or int main or init_unit_tests, once for the entire test runner.
>
> Is there anything I can do about that and belay initialization of Data Set after one of the others?
>
> Thanks,
> Florian
>
The macro BOOST_DATA_TEST_CASE is expanded at compilation time, and the
object passed to it (the dataset) is then evaluated before main.
However, you can define your own dataset. In the case of the Fibonacci,
there is an example [1] that is quite simple here:
https://github.com/boostorg/test/blob/develop/doc/examples/dataset_example68.run-fail.cpp
I am not 100% sure, but I believe that your need can be adapted to this
interface.
Let me know if this helps, and if it doesn't, please open a
ticket/feature request on trac (https://svn.boost.org/trac/).
Raffi
[1] Apparently this example was /inadvertently/ removed from the doc, I
am resurrecting it as well as the definition of a dataset interface.
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