Skip to content

Commit

Permalink
rework NDEBUG test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeltzun committed Nov 17, 2023
1 parent 672a6c1 commit 441527b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
5 changes: 0 additions & 5 deletions src/coreComponents/unitTests/toolchain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
15 changes: 9 additions & 6 deletions src/coreComponents/unitTests/toolchain/testToolchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@
* ------------------------------------------------------------------------------------------------------------
*/

#include "common/GeosxConfig.hpp"
#include <gtest/gtest.h>

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
}

Expand Down

0 comments on commit 441527b

Please sign in to comment.