Skip to content

Commit 929f8e7

Browse files
committed
Fortity test suite
Compile tests with _LIBCPP_ENABLE_ASSERTIONS and _GLIBCXX_ASSERTIONS, and _FORTITY_SOURCE allow standard libraries to perform additional checks.
1 parent 25443c7 commit 929f8e7

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

tests/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ macro(configure_tests target)
3737
target_compile_definitions(${target} PRIVATE
3838
# Somewhat speed up Catch2 compile times
3939
CATCH_CONFIG_FAST_COMPILE
40-
# Enable assertions for more thorough tests
40+
# Fortify test suite for more thorough checks
41+
_FORTIFY_SOURCE=3
42+
_GLIBCXX_ASSERTIONS
43+
_LIBCPP_ENABLE_ASSERTIONS=1
4144
GFX_TIMSORT_ENABLE_ASSERT
4245
)
4346

@@ -85,6 +88,7 @@ endmacro()
8588
# Tests that can run with C++98
8689
add_executable(cxx_98_tests
8790
cxx_98_tests.cpp
91+
verbose_abort.cpp
8892
)
8993
configure_tests(cxx_98_tests)
9094
target_compile_features(cxx_98_tests PRIVATE cxx_std_98)
@@ -93,20 +97,23 @@ target_compile_features(cxx_98_tests PRIVATE cxx_std_98)
9397
add_executable(cxx_11_tests
9498
merge_cxx_11_tests.cpp
9599
cxx_11_tests.cpp
100+
verbose_abort.cpp
96101
)
97102
configure_tests(cxx_11_tests)
98103
target_compile_features(cxx_11_tests PRIVATE cxx_std_11)
99104

100105
# Tests requiring C++17 support
101106
add_executable(cxx_17_tests
102107
cxx_17_tests.cpp
108+
verbose_abort.cpp
103109
)
104110
configure_tests(cxx_17_tests)
105111
target_compile_features(cxx_17_tests PRIVATE cxx_std_17)
106112

107113
# Tests requiring C++20 support
108114
add_executable(cxx_20_tests
109115
cxx_20_tests.cpp
116+
verbose_abort.cpp
110117
)
111118
configure_tests(cxx_20_tests)
112119
target_compile_features(cxx_20_tests PRIVATE cxx_std_20)

tests/verbose_abort.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2024 Morwenn.
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
#include <version>
7+
8+
#ifdef _LIBCPP_VERSION
9+
#if defined(_LIBCPP_ENABLE_ASSERTIONS) && _LIBCPP_ENABLE_ASSERTIONS
10+
11+
#include <cstdarg>
12+
#include <cstdio>
13+
#include <cstdlib>
14+
15+
namespace std::inline __1
16+
{
17+
/*
18+
* Required to avoid linking issues with AppleClang when
19+
* compiling with _LIBCPP_ENABLE_ASSERTIONS.
20+
* See https://releases.llvm.org/16.0.0/projects/libcxx/docs/UsingLibcxx.html#enabling-the-safe-libc-mode
21+
*/
22+
[[noreturn]]
23+
void __libcpp_verbose_abort(char const* format, ...) {
24+
std::va_list list;
25+
va_start(list, format);
26+
std::vfprintf(stderr, format, list);
27+
va_end(list);
28+
29+
std::abort();
30+
}
31+
}
32+
33+
#endif
34+
#endif

0 commit comments

Comments
 (0)