diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 03daf7f..6dab07c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,7 +37,10 @@ macro(configure_tests target) target_compile_definitions(${target} PRIVATE # Somewhat speed up Catch2 compile times CATCH_CONFIG_FAST_COMPILE - # Enable assertions for more thorough tests + # Fortify test suite for more thorough checks + _FORTIFY_SOURCE=3 + _GLIBCXX_ASSERTIONS + _LIBCPP_ENABLE_ASSERTIONS=1 GFX_TIMSORT_ENABLE_ASSERT ) @@ -85,6 +88,7 @@ endmacro() # Tests that can run with C++98 add_executable(cxx_98_tests cxx_98_tests.cpp + verbose_abort.cpp ) configure_tests(cxx_98_tests) target_compile_features(cxx_98_tests PRIVATE cxx_std_98) @@ -93,6 +97,7 @@ target_compile_features(cxx_98_tests PRIVATE cxx_std_98) add_executable(cxx_11_tests merge_cxx_11_tests.cpp cxx_11_tests.cpp + verbose_abort.cpp ) configure_tests(cxx_11_tests) target_compile_features(cxx_11_tests PRIVATE cxx_std_11) @@ -100,6 +105,7 @@ target_compile_features(cxx_11_tests PRIVATE cxx_std_11) # Tests requiring C++17 support add_executable(cxx_17_tests cxx_17_tests.cpp + verbose_abort.cpp ) configure_tests(cxx_17_tests) target_compile_features(cxx_17_tests PRIVATE cxx_std_17) @@ -107,6 +113,7 @@ target_compile_features(cxx_17_tests PRIVATE cxx_std_17) # Tests requiring C++20 support add_executable(cxx_20_tests cxx_20_tests.cpp + verbose_abort.cpp ) configure_tests(cxx_20_tests) target_compile_features(cxx_20_tests PRIVATE cxx_std_20) diff --git a/tests/verbose_abort.cpp b/tests/verbose_abort.cpp new file mode 100644 index 0000000..eec0271 --- /dev/null +++ b/tests/verbose_abort.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Morwenn. + * + * SPDX-License-Identifier: MIT + */ +#include + +#ifdef _LIBCPP_VERSION +#if defined(_LIBCPP_ENABLE_ASSERTIONS) && _LIBCPP_ENABLE_ASSERTIONS + +#include +#include +#include + +namespace std::inline __1 +{ + /* + * Required to avoid linking issues with AppleClang when + * compiling with _LIBCPP_ENABLE_ASSERTIONS. + * See https://releases.llvm.org/16.0.0/projects/libcxx/docs/UsingLibcxx.html#enabling-the-safe-libc-mode + */ + [[noreturn]] + void __libcpp_verbose_abort(char const* format, ...) { + std::va_list list; + va_start(list, format); + std::vfprintf(stderr, format, list); + va_end(list); + + std::abort(); + } + } + +#endif +#endif