[test] manual test suite initialization: linking problems
I am having a linking issue with Boost.Test on my Mac OS X 10.5.
Consider the following example:
#define BOOST_TEST_DYN_LINK
#include
I found an old thread [1] from 2007where it is advised to use the
following combination if one wants to use dynamic linking and manual
registration:
If you insist on combination of manual registration with shared library, it
should look like this:
int
main( int argc, char* argv[] )
{
return ::boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
}
Is this still the way to do it? I tried to apply the technique as
follows:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_ALTERNATIVE_INIT_API
#include
Matthias Vallentin
I found an old thread [1] from 2007where it is advised to use the following combination if one wants to use dynamic linking and manual registration:
If you insist on combination of manual registration with shared library, it should look like this:
int main( int argc, char* argv[] ) { return ::boost::unit_test::unit_test_main( &init_unit_test, argc, argv ); }
Is this still the way to do it?
Yes.
I tried to apply the technique as follows:
#define BOOST_TEST_DYN_LINK #define BOOST_TEST_ALTERNATIVE_INIT_API
Second macro should not be necessary. BOOST_TEST_DYN_LINK already causes BOOST_TEST_ALTERNATIVE_INIT_API to be defined.
That, however, gives me the following run-time error:
Running Test setup error: signal: SIGABRT ( application abort requested)
Can you see where it's aborting? Gennadiy
On Thu, Jul 16, 2009 at 05:37:01PM +0000, Gennadiy Rozental wrote:
That, however, gives me the following run-time error:
Running Test setup error: signal: SIGABRT ( application abort requested)
Can you see where it's aborting?
I found out that the Macports version of Boost is responsible for this error, as my test case works flawlessly using a manually compiled version of Boost. It has thus nothing to do with Boost or specifically Boost.Test. Matthias -- Matthias Vallentin vallentin@icsi.berkeley.edu http://www.icir.org/matthias
Matthias Vallentin
It works, however, using the automatic test module definition, e.g.
#define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE foo #include
This is fine
and works also when I remove BOOST_TEST_DYN_LINK and compile the program with the static library:
g++ test.cc /opt/local/lib/libboost_unit_test_framework-mt.a
This is fine as well.
But I can't get the first example code above to link. Does anyone see the problem lurking?
The problem is that you are missing main, which does not reside in shared library. You can either implement one yourself, or use one of two approaches above. Why do you want manual registration? Gennadiy
On Thu, Jul 16, 2009 at 05:32:51PM +0000, Gennadiy Rozental wrote:
Why do you want manual registration?
I have a similar scenario to the unary function test case function, as described in[1]. In this example, I am using BOOST_PARAM_TEST_CASE and therefore chose to register this test with one of mytest suites: suite->add(BOOST_PARAM_TEST_CASE(callback, v.begin(), v.end())); Would it be possible register such a test automatically? Then I would indeed not need manual registration. Matthias [1] http://www.boost.org/doc/libs/1_39_0/libs/test/doc/html/utf/user-guide/test-... -- Matthias Vallentin vallentin@icsi.berkeley.edu http://www.icir.org/matthias
Matthias Vallentin
On Thu, Jul 16, 2009 at 05:32:51PM +0000, Gennadiy Rozental wrote:
Why do you want manual registration?
I have a similar scenario to the unary function test case function, as described in[1]. In this example, I am using BOOST_PARAM_TEST_CASE and therefore chose to register this test with one of mytest suites:
suite->add(BOOST_PARAM_TEST_CASE(callback, v.begin(), v.end()));
Would it be possible register such a test automatically? Then I would indeed not need manual registration.
Matthias
[1]
http://www.boost.org/doc/libs/1_39_0/libs/test/doc/html/utf/user-guide/test-... No. At the moment there is no automatic registration to parameterized test cases. Note though that you can combine both manually and automatically registered test units inside the same test module, thus all other test units you can register automatically. Gennadiy
On Sun, Jul 19, 2009 at 12:42:36AM +0000, Gennadiy Rozental wrote:
Note though that you can combine both manually and automatically registered test units inside the same test module, thus all other test units you can register automatically.
That's neat. How can I specify the hierarchy of different suites? Say,
I have one master suite and would like to create a hierarchical tree
structures of suites, with tests being the leaves:
0: master
/ \
1: s1 s2
/ \
2: t_1..n s3
\
3: t_1..n
I assume I cannot switch between automatic and manual registration
within one compilation unit. How could I achieve such a structure then?
Here is the example again. First, the master test suite (test1.cc):
#define BOOST_TEST_DYN_LINK
#include
Matthias Vallentin
That's neat. How can I specify the hierarchy of different suites?
You should be able to build whatever hierarchy you want.
I assume I cannot switch between automatic and manual registration within one compilation unit. How could I achieve such a structure then?
You can in a sense. Automatic test units registered first though, thus you can't recreate them, but should be able to access appropriate test unit. Also automated test suites are "restartable" in C++ namespace sense.
Here is the example again. First, the master test suite (test1.cc):
#define BOOST_TEST_DYN_LINK #include
void test() { BOOST_CHECK_EQUAL(true, false); BOOST_REQUIRE_EQUAL(1, 1); }
bool init_unit_test() { boost::unit_test::test_suite* ts = BOOST_TEST_SUITE("test suite"); ts->add(BOOST_TEST_CASE(&test));
boost::unit_test::framework::master_test_suite().add(ts);
return true; }
This is not master test suite. Master test suite is managed by the framework. It always exists. you create test units under it.
Then, I would like to add child suite automatically (test2.cc):
You can't add automatically registered test suite to the manual one for the reasons explained above.
#define BOOST_TEST_MODULE foo test suite #include
BOOST_AUTO_TEST_SUITE(foo_suite)
BOOST_AUTO_TEST_CASE(foo) { BOOST_REQUIRE_EQUAL(42, 43); }
BOOST_AUTO_TEST_SUITE_END()
[...]
Running 2 test cases... test2.cc:8: fatal error in "foo": critical check 42 == 43 failed [42 != 43] test1.cc:6: error in "test": check true == false failed [true != false]
*** 2 failures detected in test suite "Master Test Suite"
This looks to me that test foo is part of the Master Test Suite, or am I mistaken?
No. It's part of the foo_suite test suite. Use --log_level=suite to see all the test unit enter/leave messages. Gennadiy
On Sun, Jul 19, 2009 at 07:52:35AM +0000, Gennadiy Rozental wrote:
Then, I would like to add child suite automatically (test2.cc):
You can't add automatically registered test suite to the manual one for the reasons explained above.
Thanks for clarifying, Gennadiy. I now know how to use Boost.Test according to my needs. Matthias -- Matthias Vallentin vallentin@icsi.berkeley.edu http://www.icir.org/matthias
participants (2)
-
Gennadiy Rozental
-
Matthias Vallentin