Fix unit tests on windows (#213)
* Fix unit tests on windows Based on PR#210 from @gudnimg Cherry picked just the necessary changes + reformatted the corresponding CMakeLists.txt * Change cd -> WORKING_DIRECTORY even for test coverage report * Update CMakeLists.txt * Add `BYPRODUCTS` arguments Co-authored-by: D.R.racer <drracer@drracer.eu> Co-authored-by: vintagepc <53943260+vintagepc@users.noreply.github.com>pull/216/head
parent
2ab3b96542
commit
794b0d0a81
|
|
@ -7,33 +7,46 @@ if (GCOV_ENABLE)
|
|||
add_compile_options(-g -O0 -fprofile-arcs -ftest-coverage)
|
||||
link_libraries(-coverage -lgcov)
|
||||
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)
|
||||
add_custom_target(tests_clean
|
||||
add_custom_target(
|
||||
tests_clean
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_BINARY_DIR}/Coverage
|
||||
COMMAND ${LCOV_BINARY} -b ${PROJECT_BINARY_DIR} -d ${PROJECT_BINARY_DIR} --zerocounters
|
||||
COMMAND ${CMAKE_COMMAND} -E remove ${PROJECT_BINARY_DIR}/.ctest-finished
|
||||
)
|
||||
|
||||
# This step needs to always return OK but log whether it was successful or not. The thought here is that if the tests all
|
||||
# pass, .ctest-finished is created and we can check for its existance after generating the report to determine if the overall
|
||||
# build result is a pass or fail.
|
||||
add_custom_target(test_run_all
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}
|
||||
COMMAND env CTEST_OUTPUT_ON_FAILURE=1 ctest --timeout 30 && ${CMAKE_COMMAND} -E touch .ctest-finished || exit 0
|
||||
# This step needs to always return OK but log whether it was successful or not. The thought here
|
||||
# is that if the tests all pass, .ctest-finished is created and we can check for its existance
|
||||
# after generating the report to determine if the overall build result is a pass or fail.
|
||||
add_custom_target(
|
||||
test_run_all
|
||||
COMMAND ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1 ${CMAKE_CTEST_COMMAND} --timeout 30
|
||||
COMMAND ${CMAKE_COMMAND} -E touch .ctest-finished || exit 0
|
||||
BYPRODUCTS ${PROJECT_BINARY_DIR}/.ctest-finished
|
||||
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
|
||||
DEPENDS tests_clean tests
|
||||
)
|
||||
|
||||
add_custom_target(test_coverage_report
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}
|
||||
COMMAND ${LCOV_BINARY} --capture --gcov-tool="${GCOV_BINARY}" --directory ${PROJECT_BINARY_DIR} --output-file ${PROJECT_BINARY_DIR}/coverage.info
|
||||
add_custom_target(
|
||||
test_coverage_report
|
||||
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
|
||||
COMMAND
|
||||
${LCOV_BINARY} --capture --gcov-tool="${GCOV_BINARY}" --directory ${PROJECT_BINARY_DIR}
|
||||
--output-file ${PROJECT_BINARY_DIR}/coverage.info
|
||||
# Strip system headers and other uninteresting stuff.
|
||||
COMMAND ${LCOV_BINARY} --remove coverage.info '/usr/*' '${PROJECT_SOURCE_DIR}/tests/*' '${PROJECT_SOURCE_DIR}/lib/Catch2/*' -o coverage.info
|
||||
COMMAND
|
||||
${LCOV_BINARY} --remove coverage.info '/usr/*' '${PROJECT_SOURCE_DIR}/tests/*'
|
||||
'${PROJECT_SOURCE_DIR}/lib/Catch2/*' -o coverage.info
|
||||
# Package it up.
|
||||
COMMAND genhtml coverage.info --output-directory 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.
|
||||
# Cheat and compare a file to itself to check for existence. File-Not-Found is a failure
|
||||
# code.
|
||||
COMMAND ../../utils/gcovr.py -r . -e '../../tests' -e '../../lib/Catch2' | tee Summary.txt
|
||||
COMMAND ${CMAKE_COMMAND} -E compare_files ${PROJECT_BINARY_DIR}/.ctest-finished ${PROJECT_BINARY_DIR}/.ctest-finished
|
||||
COMMAND ${CMAKE_COMMAND} -E compare_files ${PROJECT_BINARY_DIR}/.ctest-finished
|
||||
${PROJECT_BINARY_DIR}/.ctest-finished
|
||||
BYPRODUCTS ${PROJECT_BINARY_DIR}/Summary.txt ${PROJECT_BINARY_DIR}/Coverage.tar.gz
|
||||
${PROJECT_BINARY_DIR}Coverage ${PROJECT_BINARY_DIR}/coverage.info
|
||||
DEPENDS test_run_all
|
||||
)
|
||||
else()
|
||||
|
|
|
|||
Loading…
Reference in New Issue