gitlab-ci test jobs better handle false positive failures

If ctest had to re-run failed tests and those test pass we
now consider it a successful run
This commit is contained in:
Robert Maynard 2020-04-15 11:01:12 -04:00
parent b2823d79aa
commit 889cb33dde

@ -39,6 +39,33 @@ if(NOT DEFINED ENV{GITLAB_CI_EMULATION})
endif()
if (test_result)
message(FATAL_ERROR
"Failed to test")
#Current ctest return value only tracks if tests failed on the initial run.
#So when we use repeat unit pass, and all tests now succede ctest will still
#report a failure, making our gitlab-ci pipeline look red when it isn't
#
#To work around this issue we check if `Testing/Temporary/LastTestsFailed_*.log`
#has a listing of tests that failed.
set(testing_log_dir "$ENV{CI_PROJECT_DIR}/build/Testing/Temporary")
file(GLOB tests_that_failed_log "${testing_log_dir}/LastTestsFailed_*.log")
if(tests_that_failed_log)
#Make sure the file has tests listed
set(has_failing_tests true)
file(STRINGS "${tests_that_failed_log}" failed_tests)
list(LENGTH failed_tests length)
if(length LESS_EQUAL 1)
# each line looks like NUM:TEST_NAME
string(FIND "${failed_tests}" ":" location)
if(location EQUAL -1)
#no ":" so no tests actually failed after all the re-runs
set(has_failing_tests false)
endif()
endif()
if(has_failing_tests)
message(STATUS "Failing test from LastTestsFailed.log: \n ${failed_tests}")
message(FATAL_ERROR "Failed to test")
endif()
endif()
endif ()