旧版本的 boost.test 存在问题
我正在尝试在具有 boost 1.33.1 的远程系统上使用 boost.test
。在我的电脑上,这个小例子来自 http://www.boost.org/doc/libs/1_42_0/libs/test/doc/html/tutorials/hello-the-testing-world.html 有效:
#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
}
但在远程系统上文件 unit_test.hpp
不存在。在我的电脑上,文件 unit_test_framework.hpp
很简单:
// deprecated
#include <boost/test/included/unit_test.hpp>
它存在于主系统上。所以我尝试将包含更改为:
#include <boost/test/included/unit_test_framework.hpp>
但编译器说:
main.cpp:7: error: expected constructor, destructor, or type conversion before ‘(’ token
这是什么?怎么解决呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Boost 1.33 上使用:
代替:
并在 #include add: 之前使用,
否则会出现链接器错误
On Boost 1.33 use:
in place of:
and also before the #include add:
or you'll get a linker error
如果您的 boost 版本早于 1.33,您应该尝试将
BOOST_AUTO_TEST_CASE
重命名为BOOST_AUTO_UNIT_TEST
,并且它不应该破坏较新版本的 boost 上的编译。请参阅这些 Boost.Test 1.33 发行说明:
If your version of boost is older than 1.33, you should try renaming
BOOST_AUTO_TEST_CASE
toBOOST_AUTO_UNIT_TEST
, and it shouldn't break compilation on newer versions of boost.See these Boost.Test 1.33 Release Notes :
您的目标平台上的 boost 版本是什么?你在那里使用旧版本吗?
由于您使用的是 boost.test 的仅标头版本(您包含 boost/test/included/unit_test.hpp 标头,而不是 boost/test/unit_test.hpp),您不能只从 PC 复制工作的 boost 安装吗到目标机器并指示你的编译器使用它?
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?