11#include < algorithm>
2+ #include < ranges>
23#include < print>
34#include < chrono>
45
@@ -26,20 +27,21 @@ void cleanup_frames(cpptrace::stacktrace& trace, std::string_view test_name) {
2627
2728void failure_handler (libassert::assertion_info const & info) {
2829 // libassert::enable_virtual_terminal_processing_if_needed(); // for terminal colors on windows
29- constexpr bool Colorize = true ;
30+ constexpr bool Colorize = false ;
3031 auto width = libassert::terminal_width (libassert::stderr_fileno);
3132 const auto & scheme = Colorize ? libassert::get_color_scheme () : libassert::color_scheme::blank;
3233 std::string message = std::string (info.action ()) + " at " + info.location () + " :" ;
3334 if (info.message ) {
3435 message += " " + *info.message ;
3536 }
3637 message += " \n " ;
37- message += info.statement (scheme) + info.print_binary_diagnostics (width, scheme) +
38- info.print_extra_diagnostics (width, scheme);// + info.print_stacktrace(width, scheme);
38+ message +=
39+ info.statement (scheme) + info.print_binary_diagnostics (width, scheme) +
40+ info.print_extra_diagnostics (width, scheme); // + info.print_stacktrace(width, scheme);
3941
4042 auto trace = info.get_stacktrace ();
41- cleanup_frames (trace, rsl::testing::_testing_impl::assertion_counter ().test_name );
42- message += trace.to_string (true );
43+ cleanup_frames (trace, rsl::testing::_testing_impl::assertion_counter ().test_name );
44+ message += trace.to_string (Colorize );
4345 throw rsl::testing::assertion_failure (message);
4446}
4547
@@ -82,15 +84,15 @@ bool TestNamespace::run(Reporter* reporter) {
8284
8385 std::vector<TestResult> results;
8486 for (auto const & test_run : test.get_tests ()) {
85- auto & tracker = _testing_impl::assertion_counter ();
87+ auto & tracker = _testing_impl::assertion_counter ();
8688 tracker.assertions = {};
87- tracker.test_name = join_str (test.full_name , " ::" );
89+ tracker.test_name = join_str (test.full_name , " ::" );
8890
8991 reporter->before_test (test_run);
9092 auto result = test_run.run ();
9193 reporter->after_test (result);
9294
93- std::println ( " assertion count: {} " , tracker.assertions . size ()) ;
95+ result. assertions = tracker.assertions ;
9496 results.push_back (result);
9597 }
9698
@@ -116,16 +118,16 @@ TestResult TestCase::run() const {
116118 ret.duration_ms = std::chrono::duration<double , std::milli>(t1 - t0).count ();
117119 return ret;
118120 } catch (assertion_failure const & failure) {
119- ret.error += failure.what ();
121+ ret.failure += failure.what ();
120122 } catch (std::exception const & exc) { //
121- ret.error += exc.what ();
123+ ret.exception += exc.what ();
122124 } catch (std::string const & msg) { //
123- ret.error += msg;
125+ ret.failure += msg;
124126 } catch (std::string_view msg) { //
125- ret.error += msg;
127+ ret.failure += msg;
126128 } catch (char const * msg) { //
127- ret.error += msg;
128- } catch (...) { ret.error += " unknown exception thrown" ; }
129+ ret.failure += msg;
130+ } catch (...) { ret.exception += " unknown exception thrown" ; }
129131
130132 ret.passed = test->expect_failure ;
131133 return ret;
@@ -197,6 +199,31 @@ std::size_t TestNamespace::count() const {
197199 return total;
198200}
199201
202+ void TestNamespace::filter (std::span<std::string const > parts) {
203+ if (parts.empty ()) {
204+ return ;
205+ }
206+
207+ std::string_view current = parts.front ();
208+ std::span<std::string const > next = parts.subspan (1 );
209+
210+ auto it = std::ranges::find_if (children, [&](TestNamespace& ns) { return ns.name == current; });
211+
212+ if (it != children.end ()) {
213+ tests.clear ();
214+ it->filter (next);
215+ if (it->children .empty () && it->tests .empty ()) {
216+ children.clear ();
217+ } else {
218+ children = {*it};
219+ }
220+ return ;
221+ } else {
222+ std::erase_if (tests, [&](const Test& t) { return t.name != current; });
223+ children.clear ();
224+ }
225+ }
226+
200227TestRoot get_tests () {
201228 TestRoot root;
202229 for (auto test_def : rsl::testing::_testing_impl::registry ()) {
0 commit comments