From 0b6254394275dfe7450772689134681bc7f36daf Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Tue, 14 Mar 2023 11:51:22 -0600 Subject: [PATCH] Don't automatically run tests after build The runtests target must be used on Windows for the sake of code coverage. However we can't use that target on all other platforms because on some non-Windows platforms like Android, the tests don't even get configured. If you try to build a target that doesn't exist you get a hard failure. Using CTest is better because it will still return zero even if no tests are found as is the case on Android. --- .github/workflows/ci.yml | 12 +++++++++++- test/CMakeLists.txt | 7 ++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c896d23e..69f6e572 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,7 +92,17 @@ jobs: - name: Build shell: bash - run: ${{matrix.platform.prefix}} cmake --build $GITHUB_WORKSPACE/build --config ${{ matrix.type.name == 'Debug' && 'Debug' || 'Release' }} --target install + run: cmake --build $GITHUB_WORKSPACE/build --config ${{ matrix.type.name == 'Debug' && 'Debug' || 'Release' }} --target install + + - name: Test + if: runner.os == 'Windows' + shell: bash + run: cmake --build $GITHUB_WORKSPACE/build --target runtests --config ${{ matrix.type.name == 'Debug' && 'Debug' || 'Release' }} + + - name: Test + if: runner.os != 'Windows' + shell: bash + run: ${{matrix.platform.prefix}} ctest --test-dir $GITHUB_WORKSPACE/build --output-on-failure --config ${{ matrix.type.name == 'Debug' && 'Debug' || 'Release' }} - name: Generate Coverage Report if: matrix.type.name == 'Debug' && runner.os != 'Windows' # Coverage is already generated on Windows when running tests. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 86a6391b..06a5fad4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -138,11 +138,6 @@ if(SFML_OS_WINDOWS AND NOT SFML_USE_SYSTEM_DEPS) VERBATIM) endif() -# Automatically run the tests at the end of the build -add_custom_target(runtests ALL - DEPENDS test-sfml-system test-sfml-window test-sfml-graphics test-sfml-network test-sfml-audio -) - if(SFML_ENABLE_COVERAGE AND SFML_OS_WINDOWS) # Try to find and use OpenCppCoverage for coverage reporting when building with MSVC find_program(OpenCppCoverage_BINARY "OpenCppCoverage.exe") @@ -174,6 +169,8 @@ if(SFML_ENABLE_COVERAGE AND OpenCppCoverage_FOUND) set(COVERAGE_PREFIX ${OpenCppCoverage_BINARY} ARGS --quiet --export_type cobertura:${PROJECT_BINARY_DIR}/coverage.out --cover_children --excluded_modules "${COVERAGE_EXCLUDE}" --sources "${COVERAGE_SRC}" --sources "${COVERAGE_INCLUDE}" --) endif() +# Convenience for building and running tests in a single command +add_custom_target(runtests DEPENDS test-sfml-system test-sfml-window test-sfml-graphics test-sfml-network test-sfml-audio) add_custom_command(TARGET runtests COMMENT "Run tests" POST_BUILD COMMAND ${COVERAGE_PREFIX} ${CMAKE_CTEST_COMMAND} --output-on-failure -C $