Skip to content

Commit

Permalink
Fortity test suite
Browse files Browse the repository at this point in the history
Compile tests with _LIBCPP_ENABLE_ASSERTIONS and _GLIBCXX_ASSERTIONS,
and _FORTITY_SOURCE allow standard libraries to perform additional checks.
  • Loading branch information
Morwenn committed Jan 28, 2024
1 parent 25443c7 commit 929f8e7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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)
Expand All @@ -93,20 +97,23 @@ 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)

# 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)

# 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)
Expand Down
34 changes: 34 additions & 0 deletions tests/verbose_abort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 Morwenn.
*
* SPDX-License-Identifier: MIT
*/
#include <version>

#ifdef _LIBCPP_VERSION
#if defined(_LIBCPP_ENABLE_ASSERTIONS) && _LIBCPP_ENABLE_ASSERTIONS

#include <cstdarg>
#include <cstdio>
#include <cstdlib>

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

0 comments on commit 929f8e7

Please sign in to comment.