I currently have this ingenious code that adds my single-source-file tests to my CMake project:
function(runtime_test test_dir test_name)
add_executable(${test_name} EXCLUDE_FROM_ALL ${TEST_ROOT}/${test_dir}/${test_name}.c++ ${TEST_ROOT}/test.h++)
set_target_properties(${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY test/${test_dir})
#add_test(remove/${test_dir}/${test_name} ${CMAKE_COMMAND} -E remove test/${test_dir}/${test_name}${CMAKE_EXECUTABLE_SUFFIX})
#add_test(build/${test_dir}/${test_name} ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${test_name})
#add_test(test/${test_dir}/${test_name} test/${test_dir}/${test_name})
add_test(${test_dir}/${test_name} ${CMAKE_COMMAND} -E remove test/${test_dir}/${test_name}${CMAKE_EXECUTABLE_SUFFIX}
&& ${CMAKE_COMMAND} --verbose --build ${CMAKE_BINARY_DIR} --target ${test_name}
&& test/${test_dir}/${test_name})
set_property(TEST ${test_dir}/${test_name} APPEND PROPERTY DEPENDS build/${test_dir}/${test_name})
endfunction()
The commented lines add 3 "tests" which remove, build and run an executable. I run a single test as follows:
ctest --verbose -R some_test
With the commented 3 lines, I can see the build errors output to my screen. Problem is: this makes the number of tests non-representative. If I use the 3-in-1 solution, the build error output is hidden. Is there any way to solve this?