1

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
#include <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?

Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141

3 Answers3

3

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

KnucklesTheDog
  • 701
  • 6
  • 4
0

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

icecrime
  • 74,451
  • 13
  • 99
  • 111
  • I've exactly the same message. I think that `BOOST_AUTO_TEST_CASE` is defined in `boost/test/auto_unit_test.hpp`. But if I include it I got: `undefined reference to `init_unit_test_suite(int, char**)'` – Ruggero Turra Dec 06 '10 at 18:28
  • @wiso: `undefined reference` is actually a very different error ! You have to link against the boost.test library – icecrime Dec 06 '10 at 18:30
  • 1
    I'm already using `-lboost_unit_test_framework`, what do I have to link? – Ruggero Turra Dec 06 '10 at 19:38
0

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?

hillel
  • 2,343
  • 2
  • 18
  • 25