I'm trying to use boost.test
on a remote system with boost 1.33.1. On my pc this little example from http://www.boost.org/doc/libs/1_42_0/libs/test/doc/html/tutorials/hello-the-testing-world.html works:
#define BOOST_TEST_MODULE MyTest
#include <boost/test/included/unit_test.hpp> // I've changed here
int add( int i, int j ) { return i+j; }
BOOST_AUTO_TEST_CASE( my_test ) // <--- line 7
{
// seven ways to detect and report the same error:
BOOST_CHECK( add( 2,2 ) == 4 ); // #1 continues on error
BOOST_REQUIRE( add( 2,2 ) == 4 ); // #2 throws on error
if( add( 2,2 ) != 4 )
BOOST_ERROR( "Ouch..." ); // #3 continues on error
if( add( 2,2 ) != 4 )
BOOST_FAIL( "Ouch..." ); // #4 throws on error
if( add( 2,2 ) != 4 ) throw "Ouch..."; // #5 throws on error
BOOST_CHECK_MESSAGE( add( 2,2 ) == 4, // #6 continues on error
"add(..) result: " << add( 2,2 ) );
BOOST_CHECK_EQUAL( add( 2,2 ), 4 ); // #7 continues on error
}
but on the remote system the file unit_test.hpp
doesn't exist. On my pc the file unit_test_framework.hpp
is simply:
// deprecated
#inclu开发者_Go百科de <boost/test/included/unit_test.hpp>
and it is present on the main system. So I tried to change the include to:
#include <boost/test/included/unit_test_framework.hpp>
but the compiler says:
main.cpp:7: error: expected constructor, destructor, or type conversion before ‘(’ token
what's this? How to solve it?
On Boost 1.33 use:
#include <boost/test/auto_unit_test.hpp>
in place of:
#include <boost/test/unit_test.hpp>
and also before the #include add:
#define BOOST_AUTO_TEST_MAIN
or you'll get a linker error
If your version of boost is older than 1.33, you should try renaming BOOST_AUTO_TEST_CASE
to BOOST_AUTO_UNIT_TEST
, and it shouldn't break compilation on newer versions of boost.
See these Boost.Test 1.33 Release Notes :
BOOST_AUTO_UNIT_TEST renamed to BOOST_AUTO_TEST_CASE. Old name still provided but deprecated
What's the boost version on your target platform? Are you using an old version there?
Since you are using a header only version of boost.test (you include the boost/test/included/unit_test.hpp header and not boost/test/unit_test.hpp), can't you just copy the working boost installation from your PC to the target machine and instruct your compiler to use it?
精彩评论