55#include < rsl/testing/assert.hpp>
66#include < rsl/testing/test.hpp>
77#include < rsl/testing/output.hpp>
8+ #include < rsl/testing/util.hpp>
89#include < rsl/testing/_testing_impl/discovery.hpp>
910
1011#include " capture.hpp"
1112
13+ #include < cpptrace/basic.hpp>
14+ #include < cpptrace/utils.hpp>
15+
16+ void cleanup_frames (cpptrace::stacktrace& trace, std::string_view test_name) {
17+ std::vector<cpptrace::stacktrace_frame> frames;
18+ for (auto const & frame : trace.frames | std::views::drop (1 )) {
19+ frames.push_back (frame);
20+ if (cpptrace::prune_symbol (frame.symbol ) == test_name) {
21+ break ;
22+ }
23+ }
24+ trace.frames = frames;
25+ }
26+
1227void failure_handler (libassert::assertion_info const & info) {
1328 // libassert::enable_virtual_terminal_processing_if_needed(); // for terminal colors on windows
1429 constexpr bool Colorize = true ;
@@ -20,7 +35,11 @@ void failure_handler(libassert::assertion_info const& info) {
2035 }
2136 message += " \n " ;
2237 message += info.statement (scheme) + info.print_binary_diagnostics (width, scheme) +
23- info.print_extra_diagnostics (width, scheme);
38+ info.print_extra_diagnostics (width, scheme);// + info.print_stacktrace(width, scheme);
39+
40+ auto trace = info.get_stacktrace ();
41+ cleanup_frames (trace, rsl::testing::_testing_impl::assertion_counter ().test_name );
42+ message += trace.to_string (true );
2443 throw rsl::testing::assertion_failure (message);
2544}
2645
@@ -31,11 +50,8 @@ std::set<TestDef>& registry() {
3150 return data;
3251}
3352
34- std::vector<AssertionInfo>* assertion_counter (std::vector<AssertionInfo>* new_counter) {
35- static std::vector<AssertionInfo>* counter = nullptr ;
36- if (new_counter != nullptr ) {
37- counter = new_counter;
38- }
53+ AssertionTracker& assertion_counter () {
54+ static AssertionTracker counter{};
3955 return counter;
4056}
4157} // namespace _testing_impl
@@ -66,15 +82,15 @@ bool TestNamespace::run(Reporter* reporter) {
6682
6783 std::vector<TestResult> results;
6884 for (auto const & test_run : test.get_tests ()) {
69- std::vector<_testing_impl::AssertionInfo> assertions;
70- _testing_impl::assertion_counter (&assertions);
85+ auto & tracker = _testing_impl::assertion_counter ();
86+ tracker.assertions = {};
87+ tracker.test_name = join_str (test.full_name , " ::" );
7188
7289 reporter->before_test (test_run);
7390 auto result = test_run.run ();
7491 reporter->after_test (result);
7592
76- _testing_impl::assertion_counter (nullptr );
77- std::println (" assertion count: {}" , assertions.size ());
93+ std::println (" assertion count: {}" , tracker.assertions .size ());
7894 results.push_back (result);
7995 }
8096
0 commit comments