0

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?

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • Personally, I do it with "make test" which will make the dependencies of test first and then run the tests... – IdeaHat Nov 21 '14 at 22:38
  • @IdeaHat I'd like to be able to run (and build) the tests seperately though, in order to reduce the noise when I'm messing with a particular part of my code. – rubenvb Nov 22 '14 at 10:35
  • I'm not really following here. When running cmake, and then building you will get the build errors. Then after everything has successfully built you run your test. I think I'm missing some part of your question? Is this in relation to CDash or something? – Joakim Jan 23 '15 at 18:00

0 Answers0