Fix handling failed tests.

pull/36/head
VintagePC 2021-06-30 09:21:39 -04:00
parent 3529b73ee5
commit 4371b97d79
1 changed files with 30 additions and 27 deletions

View File

@ -1,5 +1,4 @@
option(GCOV_ENABLE "Enable/use GCOV code coverage for tests" ON) option(GCOV_ENABLE "Enable/use GCOV code coverage for tests" ON)
option(GCOV_CONTINUE_ON_FAILURE "Continue and generate test report even if tests fail" ON)
if (GCOV_ENABLE) if (GCOV_ENABLE)
find_program(GCOV_BINARY NAMES gcov gcov-7) find_program(GCOV_BINARY NAMES gcov gcov-7)
@ -11,14 +10,16 @@ if (GCOV_ENABLE)
add_custom_target(tests_clean add_custom_target(tests_clean
WORKING_DIRECTORY ${PROJECT_BINARY_DIR} WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_BINARY_DIR}/Coverage COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_BINARY_DIR}/Coverage
COMMAND lcov -b ${PROJECT_BINARY_DIR} -d ${PROJECT_BINARY_DIR} --zerocounters COMMAND ${LCOV_BINARY} -b ${PROJECT_BINARY_DIR} -d ${PROJECT_BINARY_DIR} --zerocounters
COMMAND ${CMAKE_COMMAND} -E remove ${PROJECT_BINARY_DIR}/.ctest-finished
) )
# TODO - right now this is kinda janky because some of the tests fail and this causes execution to abort. # This step needs to always return OK but log whether it was successful or not. The thought here is that if the tests all
# Once they no longer do that we can merge this into the test_coverage_report step so it all runs seamlessly. # pass, .ctest-finished is created and we can check for its existance after generating the report to determine if the overall
# For now, build test_run_all and ignore the failure. Then build the test_coverage_report target. # build result is a pass or fail.
add_custom_target(test_run_all add_custom_target(test_run_all
COMMAND cd ${PROJECT_BINARY_DIR} && env CTEST_OUTPUT_ON_FAILURE=1 ctest --timeout 30 || exit 0 COMMAND cd ${PROJECT_BINARY_DIR}
COMMAND env CTEST_OUTPUT_ON_FAILURE=1 ctest --timeout 30 && ${CMAKE_COMMAND} -E touch .ctest-finished || exit 0
DEPENDS tests_clean tests DEPENDS tests_clean tests
) )
@ -30,9 +31,11 @@ if (GCOV_ENABLE)
# Package it up. # Package it up.
COMMAND genhtml coverage.info --output-directory Coverage COMMAND genhtml coverage.info --output-directory Coverage
COMMAND tar -zcvf Coverage.tar.gz Coverage COMMAND tar -zcvf Coverage.tar.gz Coverage
# Cheat and compare a file to itself to check for existence. File-Not-Found is a failure code.
COMMAND ${CMAKE_COMMAND} -E compare_files ${PROJECT_BINARY_DIR}/.ctest-finished ${PROJECT_BINARY_DIR}/.ctest-finished
# TODO - this needs to be fixed so it doesn't suck in all the catch/test cruft. # TODO - this needs to be fixed so it doesn't suck in all the catch/test cruft.
#COMMAND ${PROJECT_SOURCE_DIR}/utils/gcovr.py -r ${PROJECT_SOURCE_DIR} -e '${PROJECT_SOURCE_DIR}/tests/*' -e Catch2 | tee ${PROJECT_BINARY_DIR}/summary.txt #COMMAND ${PROJECT_SOURCE_DIR}/utils/gcovr.py -r ${PROJECT_SOURCE_DIR} -e '${PROJECT_SOURCE_DIR}/tests/*' -e Catch2 | tee ${PROJECT_BINARY_DIR}/summary.txt
#DEPENDS tests_clean tests DEPENDS test_run_all
) )
else() else()
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE OFF) set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE OFF)