我在 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()
C测试报告:
$ 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
选项和 BOOST_TEST_COLOR_OUTPUT
环境变量调整 color_output
,但没有成功 ( see this documentation page )。尽管我为此类选项传递了任何值,但错误仍然存在。
奇怪的是,如果我手动编译测试文件,测试运行正常,可能表明 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>
而不是您使用的单 header 变体:
#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/