我有一个Boost测试用例,如下所示:
#define BOOST_TEST_MODULE my_test
#include <cstdio>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(my_test_case)
{
printf("123");
}
我尝试使用cmake
cmake_minimum_required(VERSION 3.5)
project(my_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
enable_testing()
file(GLOB TEST_SRCS main.cpp)
foreach(TEST_SRC ${TEST_SRCS})
get_filename_component(TEST_NAME ${TEST_SRC} NAME_WE)
add_executable(${TEST_NAME} ${TEST_SRC})
# Boost
ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
target_link_libraries(${TEST_NAME} PUBLIC ${Boost_LIBRARIES})
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
endforeach(TEST_SRC)
当我仅使用命令make test
时,输出如下:
Running tests...
Test project xxx
Start 1: main
1/1 Test #1: main ............................. Passed 0.00 sec
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 0.00 sec
未显示任何内容(使用CTEST_OUTPUT_ON_FAILURE
无济于事,因为即使所有测试都通过,我也想查看输出)。我也尝试过ctest -V
,但必须比我期望的更为详细
UpdateCTestConfiguration from :xxx
UpdateCTestConfiguration from :xxx
Test project xxx
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
Start 1: main
1: Test command: xxx
1: Test timeout computed to be: 10000000
1: Running 1 test case...
1: 123
1: *** No errors detected
1/1 Test #1: main ............................. Passed 0.00 sec
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 0.00 sec
我真正想要的是比make test
更详细,但比ctest -V
更干净,例如下面的输出(我通过直接运行二进制文件{{ 1}}):
./main