Skip to content

Commit 756c91a

Browse files
carsonRadtkeCopilotCopilot
authored
infra: individual test executables (#1212)
* infra: individual test executables We used have tests contained in a single executable. This was fine for testing, but it would be more convient to separate tests into indivudal modules so targeted changes could have targeted tests. This change associates each test file with its own executable. We now have 14 tests for GSL each of which testing a different component. * revert -Wno-reserved-identifier * Update tests/span_tests.cpp thanks copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * be sure to include build type in ctest command * [VS] make sure we are building the correct configuration * restore tests/span_tests.cpp * fix build break after merge conflicts * fix build break after merge conflicts #2 * another try at fixing a build break * fix silly typo. build break pt 4 * Use file globbing for test sources instead of manual list (#1227) * Initial plan * Use file globbing for test sources instead of manual list Replace the manually maintained list of test sources with file(GLOB) to automatically discover all .cpp files in the tests directory, excluding no_exception_ensure_tests.cpp which needs special compilation flags. This approach: - Automatically picks up new test files without CMake updates - Still correctly excludes no_exception_ensure_tests.cpp - Maintains the same test build configuration - Works with both C++14 and C++20 Co-authored-by: carsonRadtke <10507970+carsonRadtke@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: carsonRadtke <10507970+carsonRadtke@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent 1883887 commit 756c91a

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

.github/workflows/cmake/action.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ inputs:
33
cmake_preset:
44
required: true
55
type: string
6-
extra_cmake_args:
6+
extra_cmake_build_args:
7+
required: false
8+
type: string
9+
default: ''
10+
extra_cmake_configure_args:
11+
required: false
12+
type: string
13+
default: ''
14+
extra_ctest_args:
715
required: false
816
type: string
917
default: ''
@@ -12,14 +20,14 @@ runs:
1220
using: composite
1321
steps:
1422
- name: Configure CMake
15-
run: cmake --preset ${{ inputs.cmake_preset }} -DCI_TESTING:BOOL=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -Werror=dev ${{ inputs.extra_cmake_args }}
16-
shell: bash
23+
run: cmake --preset ${{ inputs.cmake_preset }} ${{ inputs.extra_cmake_configure_args }} -DCI_TESTING:BOOL=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -Werror=dev
24+
shell: ${{ env.RUNNER_OS == 'Windows' && 'pwsh' || 'bash' }}
1725

1826
- name: Build (with preset)
19-
run: cmake --build --preset ${{ inputs.cmake_preset }}
20-
shell: bash
27+
run: cmake --build --preset ${{ inputs.cmake_preset }} ${{ inputs.extra_cmake_build_args }}
28+
shell: ${{ env.RUNNER_OS == 'Windows' && 'pwsh' || 'bash' }}
2129

2230
- name: Test (with preset)
23-
run: ctest --preset ${{ inputs.cmake_preset }} --output-on-failure --no-compress-output
24-
shell: pwsh
31+
run: ctest --preset ${{ inputs.cmake_preset }} ${{ inputs.extra_ctest_args }} --output-on-failure --no-compress-output
32+
shell: ${{ env.RUNNER_OS == 'Windows' && 'pwsh' || 'bash' }}
2533

.github/workflows/compilers.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
uses: ./.github/workflows/cmake
7676
with:
7777
cmake_preset: clang-${{ matrix.cxx_version }}-${{ matrix.build_type == 'Debug' && 'debug' || 'release' }}
78-
extra_cmake_args: '-DCMAKE_CXX_FLAGS="-isysroot \"$(xcode-select --print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk\""'
78+
extra_cmake_configure_args: '-DCMAKE_CXX_FLAGS="-isysroot \"$(xcode-select --print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk\""'
7979

8080
VisualStudio:
8181
strategy:
@@ -94,6 +94,7 @@ jobs:
9494
uses: ./.github/workflows/cmake
9595
with:
9696
cmake_preset: msvc-${{ matrix.cxx_version }}-${{ matrix.build_type == 'Debug' && 'debug' || 'release' }}
97-
extra_cmake_args: ${{ matrix.extra_args }}
98-
shell: pwsh
97+
extra_cmake_configure_args: ${{ matrix.extra_args }}
98+
extra_cmake_build_args: --config ${{ matrix.build_type }}
99+
extra_ctest_args: -C ${{ matrix.build_type }}
99100

tests/CMakeLists.txt

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -199,29 +199,22 @@ target_include_directories(gsl_tests_config SYSTEM INTERFACE
199199
googletest/googletest/include
200200
)
201201

202-
add_executable(gsl_tests
203-
algorithm_tests.cpp
204-
assertion_tests.cpp
205-
at_tests.cpp
206-
byte_tests.cpp
207-
constexpr_notnull_tests.cpp
208-
notnull_tests.cpp
209-
owner_tests.cpp
210-
pointers_tests.cpp
211-
span_compatibility_tests.cpp
212-
span_ext_tests.cpp
213-
span_tests.cpp
214-
strict_notnull_tests.cpp
215-
216-
utils_tests.cpp
217-
)
202+
# Individually build and register each test source (except no_exception_ensure_tests.cpp)
203+
# no_exception_ensure_tests.cpp is built separately with exceptions disabled
204+
file(GLOB GSL_TEST_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
205+
list(FILTER GSL_TEST_SOURCES EXCLUDE REGEX "no_exception_ensure_tests\\.cpp$")
218206

219-
target_link_libraries(gsl_tests
207+
foreach(src IN LISTS GSL_TEST_SOURCES)
208+
get_filename_component(test_name "${src}" NAME_WE)
209+
add_executable(${test_name} ${src})
210+
target_link_libraries(${test_name}
220211
Microsoft.GSL::GSL
221212
gsl_tests_config
222213
${GTestMain_LIBRARIES}
223-
)
224-
add_test(gsl_tests gsl_tests)
214+
)
215+
add_test(NAME ${test_name} COMMAND ${test_name})
216+
set_target_properties(${test_name} PROPERTIES FOLDER "tests")
217+
endforeach()
225218

226219
# No exception tests
227220

0 commit comments

Comments
 (0)