diff --git a/.github/workflows/cmake/action.yml b/.github/workflows/cmake/action.yml index b8794da26..d2130cd4f 100644 --- a/.github/workflows/cmake/action.yml +++ b/.github/workflows/cmake/action.yml @@ -3,7 +3,15 @@ inputs: cmake_preset: required: true type: string - extra_cmake_args: + extra_cmake_build_args: + required: false + type: string + default: '' + extra_cmake_configure_args: + required: false + type: string + default: '' + extra_ctest_args: required: false type: string default: '' @@ -12,14 +20,14 @@ runs: using: composite steps: - name: Configure CMake - run: cmake --preset ${{ inputs.cmake_preset }} -DCI_TESTING:BOOL=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -Werror=dev ${{ inputs.extra_cmake_args }} - shell: bash + run: cmake --preset ${{ inputs.cmake_preset }} ${{ inputs.extra_cmake_configure_args }} -DCI_TESTING:BOOL=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -Werror=dev + shell: ${{ env.RUNNER_OS == 'Windows' && 'pwsh' || 'bash' }} - name: Build (with preset) - run: cmake --build --preset ${{ inputs.cmake_preset }} - shell: bash + run: cmake --build --preset ${{ inputs.cmake_preset }} ${{ inputs.extra_cmake_build_args }} + shell: ${{ env.RUNNER_OS == 'Windows' && 'pwsh' || 'bash' }} - name: Test (with preset) - run: ctest --preset ${{ inputs.cmake_preset }} --output-on-failure --no-compress-output - shell: pwsh + run: ctest --preset ${{ inputs.cmake_preset }} ${{ inputs.extra_ctest_args }} --output-on-failure --no-compress-output + shell: ${{ env.RUNNER_OS == 'Windows' && 'pwsh' || 'bash' }} diff --git a/.github/workflows/compilers.yml b/.github/workflows/compilers.yml index e576ce48e..3ab6b5d93 100644 --- a/.github/workflows/compilers.yml +++ b/.github/workflows/compilers.yml @@ -75,7 +75,7 @@ jobs: uses: ./.github/workflows/cmake with: cmake_preset: clang-${{ matrix.cxx_version }}-${{ matrix.build_type == 'Debug' && 'debug' || 'release' }} - extra_cmake_args: '-DCMAKE_CXX_FLAGS="-isysroot \"$(xcode-select --print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk\""' + extra_cmake_configure_args: '-DCMAKE_CXX_FLAGS="-isysroot \"$(xcode-select --print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk\""' VisualStudio: strategy: @@ -94,6 +94,7 @@ jobs: uses: ./.github/workflows/cmake with: cmake_preset: msvc-${{ matrix.cxx_version }}-${{ matrix.build_type == 'Debug' && 'debug' || 'release' }} - extra_cmake_args: ${{ matrix.extra_args }} - shell: pwsh + extra_cmake_configure_args: ${{ matrix.extra_args }} + extra_cmake_build_args: --config ${{ matrix.build_type }} + extra_ctest_args: -C ${{ matrix.build_type }} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a8fd30ac3..d583c24b7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -199,29 +199,22 @@ target_include_directories(gsl_tests_config SYSTEM INTERFACE googletest/googletest/include ) -add_executable(gsl_tests - algorithm_tests.cpp - assertion_tests.cpp - at_tests.cpp - byte_tests.cpp - constexpr_notnull_tests.cpp - notnull_tests.cpp - owner_tests.cpp - pointers_tests.cpp - span_compatibility_tests.cpp - span_ext_tests.cpp - span_tests.cpp - strict_notnull_tests.cpp - - utils_tests.cpp -) +# Individually build and register each test source (except no_exception_ensure_tests.cpp) +# no_exception_ensure_tests.cpp is built separately with exceptions disabled +file(GLOB GSL_TEST_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") +list(FILTER GSL_TEST_SOURCES EXCLUDE REGEX "no_exception_ensure_tests\\.cpp$") -target_link_libraries(gsl_tests +foreach(src IN LISTS GSL_TEST_SOURCES) + get_filename_component(test_name "${src}" NAME_WE) + add_executable(${test_name} ${src}) + target_link_libraries(${test_name} Microsoft.GSL::GSL gsl_tests_config ${GTestMain_LIBRARIES} -) -add_test(gsl_tests gsl_tests) + ) + add_test(NAME ${test_name} COMMAND ${test_name}) + set_target_properties(${test_name} PROPERTIES FOLDER "tests") +endforeach() # No exception tests