From e2dd4548c07baad60b9b0e9efe8a2813522848c7 Mon Sep 17 00:00:00 2001 From: Carson Radtke Date: Thu, 21 Aug 2025 09:57:18 -0600 Subject: [PATCH] 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. --- tests/CMakeLists.txt | 42 ++++++++++++++++++++++++------------------ tests/span_tests.cpp | 8 ++++---- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a8fd30a..9d739ae 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -101,6 +101,7 @@ if(MSVC) # MSVC or simulating MSVC -Wfloat-equal -Wno-c++98-compat -Wno-c++98-compat-pedantic + -Wno-reserved-identifier -Wno-covered-switch-default # GTest -Wno-deprecated-declarations # Allow tests for [[deprecated]] elements -Wno-global-constructors # GTest @@ -199,29 +200,34 @@ 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) +set(GSL_TEST_SOURCES + 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 ) -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 diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index e41026e..6e9b654 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -412,8 +412,8 @@ TEST(span_test, from_std_array_constructor) static_assert(!CtorCompilesFor, std::array&>, "!CtorCompilesFor, std::array&>"); -#if !defined(_MSC_VER) || (_MSC_VER > 1943) || (__cplusplus >= 201703L) - // Fails on "Visual Studio 16 2019/Visual Studio 17 2022, windows-2019/2022, Debug/Release, 14". +#if !defined(_MSC_VER) || (__cplusplus >= 201703L) + // The following static assertion fails on MSVC in C++14 mode. static_assert(!ConversionCompilesFor, std::array>, "!ConversionCompilesFor, std::array>"); #endif @@ -529,8 +529,8 @@ TEST(span_test, from_container_constructor) EXPECT_TRUE(cs.data() == cstr.data()); } -#if !defined(_MSC_VER) || (_MSC_VER > 1943) || (__cplusplus >= 201703L) - // Fails on "Visual Studio 16 2019/Visual Studio 17 2022, windows-2019/2022, Debug/Release, 14". +#if !defined(_MSC_VER) || (__cplusplus >= 201703L) + // The following static assertion fails on MSVC in C++14 mode. static_assert(!ConversionCompilesFor, std::vector>, "!ConversionCompilesFor, std::vector>"); #endif // !defined(_MSC_VER) || (_MSC_VER > 1942) || (__cplusplus >= 201703L)