我在OS X El Capitan中使用CTest和Boost 1.61.0的最近创建的项目中遇到此错误。

这是我测试的CMakeLists.txt,位于core/tests/CMakeLists.txt中:

find_package(Boost 1.32 REQUIRED COMPONENTS unit_test_framework)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(EntryTest entry.spec.cpp)
target_link_libraries(EntryTest core ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_test(EntryTest EntryTest)

和实际的虚拟测试,位于core/tests/entry.spec.cpp中:
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_SUITE (EntryTest)

BOOST_AUTO_TEST_CASE(ShouldPass) {
  BOOST_CHECK_EQUAL(1, 1);
}

BOOST_AUTO_TEST_SUITE_END()

CTest报告:
$ cat Testing/Temporary/LastTest.log
Start testing: Aug 26 13:05 BOT
----------------------------------------------------------
1/1 Testing: EntryTest
1/1 Test: EntryTest
Command: "/Users/jviotti/Projects/timetrack/build/core/tests/EntryTest"
Directory: /Users/jviotti/Projects/timetrack/build/core/tests
"EntryTest" start time: Aug 26 13:05 BOT
Output:
----------------------------------------------------------
Test setup error: boost::runtime::access_to_missing_argument: There is no argument provided for parameter color_output
<end of output>
Test time =   0.01 sec
----------------------------------------------------------
Test Failed.
"EntryTest" end time: Aug 26 13:05 BOT
"EntryTest" time elapsed: 00:00:00
----------------------------------------------------------

End testing: Aug 26 13:05 BOT

我尝试使用color_output选项和--color_output环境变量(没有运气(see this documentation page))来调整BOOST_TEST_COLOR_OUTPUT。尽管我为此类选项传递了任何值,但错误仍然存​​在。

奇怪的是,如果我手动编译测试文件,则测试运行正常,这可能表示CMake配置问题:
$ clang++ -L/usr/local/Cellar/boost/1.61.0_1/lib -I/usr/local/Cellar/boost/1.61.0_1/include core/tests/entry.spec.cpp
$ ./a.out
Running 1 test case...

*** No errors detected

我究竟做错了什么?

最佳答案

通过使用单元测试框架的动态链接变体,我能够解决missing_argument问题,如下所示:

#define BOOST_TEST_MODULE my_unit_tests
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

代替使用的单头变体:
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>

其余代码和CMake脚本保持完全相同。

关于c++ - Boost.Test和CTest没有为参数color_output提供参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39171467/

10-13 07:04