Bug #6630
cet_test does not set BOOST_TEST_MAIN definition
Description
When using USE_BOOST_UNIT
parameter, cet_test
fails to define the compiler definition BOOST_TEST_MAIN
.
Lines 280-281 of Modules/CetTest.cmake should be merged into
COMPILE_DEFINITIONS "BOOST_TEST_MAIN;BOOST_TEST_DYN_LINK"
(my code seems to need
BOOST_TEST_MAIN
, but I don't understand Boost magic)
I am reporting about cetbuildtools
v3_11_00
, used with LArSoft 2.2.1 and art
1.9.3 (there should be a "affected version"-like box in this report form...).
History
#1 Updated by Lynn Garren almost 7 years ago
Please provide a working example of the problem. There may be a different solution.
#2 Updated by Gianluca Petrillo almost 7 years ago
The problem with Boost unit test suite is that there are too many solutions.
One if BOOST_TEST_MAIN
is set, one if BOOST_TEST_DYN_LINK
is set instead.
Since the documentation of cet_test
does not say which one is supported when USE_BOOST_UNIT
is set, I looked at the macro itself and it seems to define both.
Matter of fact, the first one, BOOST_TEST_MAIN
, is ignored since a different COMPILE_DEFINITIONS
is specified immediately after that (line 281).
Lines 280 and 281 should not coexist.
I redesigned my test to fit the BOOST_TEST_DYN_LINK
model and now it works (no missing main()
complaint, no empty test tree any more).
Still the spurious line 280 should be removed by cet_test
(with no effect on any build).
#3 Updated by Christopher Green almost 7 years ago
- Status changed from New to Feedback
- Assignee set to Christopher Green
- Target version set to 1.11.00
- Estimated time set to 4.00 h
It looks at first glance that you may be correct, but I need understand more about what you were trying to do originally and what didn't work. Could you please provide information about your original attempts that triggered the problem so that we can reproduce it and reconcile with what we believe we understand about BOOST_UNIT?
#4 Updated by Gianluca Petrillo almost 7 years ago
Being my first attempt to use Boost unit tests, my goal was to put together a test, in any way I could.
The idea was that I could optionally specify from command line the random seed to be used.
So I was trying to use
boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] );
to fill the tests based on optional command line parameters.
I tried something like:
#include "boost/test/unit_test.hpp" boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] ) { std::cout << "Initializing tests..." << std::endl; return nullptr; } // init_unit_test_suite()
At that, I am told no
main()
is defined.Adding "#define BOOST_TEST_MAIN", I am informed that no test is registered (which is true, but I should see the "Initializing tests..." message too).
Since I was using the
USE_BOOST_TEST
option in CMakeFiles.txt
, I went to look what was happening in there and I found the two definitions I reported about, one hindered by the other.I have since then given up and used the automatic test registration, loosing the ability to pass parameters by command line.
#5 Updated by Christopher Green over 6 years ago
- Target version changed from 1.11.00 to 1.13.00
#6 Updated by Christopher Green about 6 years ago
- Status changed from Feedback to Assigned
#7 Updated by Christopher Green about 6 years ago
- Status changed from Assigned to Resolved
- % Done changed from 0 to 100
The problem you mention in CetTest.cmake
has been resolved with 91fcd05.
For a demonstration of an executable invoking BOOST Test functionality and defining its own main (and accepting command-line options), please see art:source:art/Framework/Art/art_ut.cc.in. Let us know if you have any questions about it.
Sorry for the long delay on such a simple issue.
#8 Updated by Christopher Green about 6 years ago
- Status changed from Resolved to Closed