Boost.Test, link=shared, and main

Peter Dimov via Boost <[email protected]>
Newsgroups gmane.comp.lib.boost.devel
Message-ID <[email protected]>
Some libraries (e.g. Proto until yesterday, Range, Xpressive) have test .cpp files that look like this:

#include <boost/test/unit_test.hpp>

void my_test_function()
{
    // tests here
}

boost::unit_test::test_suite*
init_unit_test_suite(int argc, char* argv[])
{
    boost::unit_test::test_suite* test
        = BOOST_TEST_SUITE( "my test suite name" );

    test->add( BOOST_TEST_CASE( &my_test_function ) );

    return test;
}

This works when Boost.Test is linked as a static library, because it then supplies a `main` function.

It doesn't link with link=shared, because then there's no `main`.

What's the easiest, least invasive, way to make this work with link=shared?
In principle, one is supposed to define BOOST_TEST_MAIN. But this doesn't
work, because when BOOST_TEST_MAIN is defined, Boost.Test defines not
just `main`, but `init_unit_test_suite` as well. And defining `main` also doesn't
work, because when using shared linking, Boost.Test automatically defines
BOOST_TEST_ALTERNATIVE_INIT_API, which changes the expected signature
of init_unit_test_suite to one returning not boost::unit_test::test_suite* but
bool.

The current tests work around this by using <link>static as a requirement in
test/Jamfile, but this has become a problem when testing with CMake since
I added these libraries there. Testing Boost with BUILD_SHARED_LIBS=ON now
doesn't work.

(I updated the Proto tests to use BOOST_AUTO_TEST_CASE instead and this
works, but is (a) too much work and (b) error prone. There should be an easier
way to support the above use.)


_______________________________________________
Boost mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.boost.org/mailman3/lists/boost.lists.boost.org/
Archived at: https://lists.boost.org/archives/list/[email protected]/message/JNGVDBMMO23HE4TYJRK27BNRVRHT23II/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.