From 441527b985fab0e9e9dfb8ccdb3bb60c78e06f84 Mon Sep 17 00:00:00 2001 From: tbeltzun <129868353+tbeltzun@users.noreply.github.com> Date: Fri, 17 Nov 2023 10:49:30 +0100 Subject: [PATCH] rework NDEBUG test structure --- .../unitTests/toolchain/CMakeLists.txt | 5 ----- .../unitTests/toolchain/testToolchain.cpp | 15 +++++++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/coreComponents/unitTests/toolchain/CMakeLists.txt b/src/coreComponents/unitTests/toolchain/CMakeLists.txt index 05a67559f81..7a3b6e5c688 100644 --- a/src/coreComponents/unitTests/toolchain/CMakeLists.txt +++ b/src/coreComponents/unitTests/toolchain/CMakeLists.txt @@ -18,9 +18,4 @@ foreach(test ${gtest_geosx_tests}) # NOTE: we explicitly depend on internal headers in order to check for the spurious addition of -DNDEBUG flag target_include_directories( ${test_name} PUBLIC ${CMAKE_SOURCE_DIR}/coreComponents ) - - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set_tests_properties(${test_name} PROPERTIES WILL_FAIL TRUE) - endif() - endforeach() diff --git a/src/coreComponents/unitTests/toolchain/testToolchain.cpp b/src/coreComponents/unitTests/toolchain/testToolchain.cpp index 11237e5e44d..ec81e510ff9 100644 --- a/src/coreComponents/unitTests/toolchain/testToolchain.cpp +++ b/src/coreComponents/unitTests/toolchain/testToolchain.cpp @@ -12,20 +12,23 @@ * ------------------------------------------------------------------------------------------------------------ */ +#include "common/GeosxConfig.hpp" #include TEST( Toolchain, NDEBUGfromTPls ) { /* - * This test guards against spurious propagation of -DNDEBUG preprocessor flag (HDF5 in our case), - * which has the effect of disabling LvArray assertions: - * instead, we always check that this test fails in CMake Debug mode, whilst it should always - * pass in RelWithDebInfo or Release builds. + * This test guards against spurious propagation of -DNDEBUG preprocessor flag + * (HDF5 from the TPLs in our case), which has the bogus effect of disabling LvArray assertions: + * we check that we are in RelWithDebInfo or Release build type when NDEBUG is defined and in Debug + * configuration when NDEBUG is not defined: thus, LvArray assertions remain in Debug builds. */ + bool constexpr isDebug = std::string_view( GEOSX_CMAKE_BUILD_TYPE ) == std::string_view( "Debug" ); + #ifdef NDEBUG - SUCCEED(); // RelWithDebInfo or Release builds + ASSERT_FALSE( isDebug ); // RelWithDebInfo or Release builds only #else - FAIL(); // Debug builds + ASSERT_TRUE( isDebug ); // Debug builds only #endif }