From 7f861fa78f3d64308f2a0d8aa6322a70c87f46b9 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Fri, 4 Dec 2026 00:48:10 +0300 Subject: [PATCH] Testing: parallel auto mode, aligned timings and slowest/failure summaries --- include/Void/Testing/ConsoleReporter.hpp | 5 ++++ src/Testing/ConsoleReporter.cpp | 33 ++++++++++++++++++++---- src/Testing/Runner.cpp | 15 +++++++---- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/include/Void/Testing/ConsoleReporter.hpp b/include/Void/Testing/ConsoleReporter.hpp index 1e67898..372c7cf 100644 --- a/include/Void/Testing/ConsoleReporter.hpp +++ b/include/Void/Testing/ConsoleReporter.hpp @@ -2,6 +2,9 @@ #include #include #include +#include +#include +#include namespace Void::Testing { class ConsoleReporter final : public Reporter { @@ -17,6 +20,8 @@ public: void on_run_end(const RunResult& result) override; private: std::ostream& os_; + std::vector> timings_; + std::vector failures_; void print_assertion_failure(const AssertionResult& ar); void print_crash_info(const TestResult& result); }; diff --git a/src/Testing/ConsoleReporter.cpp b/src/Testing/ConsoleReporter.cpp index c0ad156..1ad49d7 100644 --- a/src/Testing/ConsoleReporter.cpp +++ b/src/Testing/ConsoleReporter.cpp @@ -24,18 +24,22 @@ void ConsoleReporter::on_suite_end(const SuiteResult&) {} void ConsoleReporter::on_test_end(const TestResult& result) { double ms = std::chrono::duration(result.duration).count(); std::string time_str = ms < 1.0 ? std::format("{:.3f}ms", ms) : std::format("{:.1f}ms", ms); + timings_.emplace_back(ms, result.name); + if (result.state == TestState::Failed || result.state == TestState::Crashed) { + failures_.push_back(result.name); + } std::string tags_str; if (!result.tags.empty()) { for(const auto& t : result.tags) tags_str += "[" + t + "]"; tags_str = " " + Void::Testing::Detail::Color::apply(dim, tags_str); } switch (result.state) { - case TestState::Passed: os_ << std::format(" {} {:<40s}{}{}\n", Void::Testing::Detail::Color::apply(bold_green, "✔"), Void::Testing::Detail::Color::apply(green, result.name), tags_str, Void::Testing::Detail::Color::apply(dim, time_str)); break; + case TestState::Passed: os_ << std::format(" {} {:<44s}{}{:>9s}\n", Void::Testing::Detail::Color::apply(bold_green, "✔"), Void::Testing::Detail::Color::apply(green, result.name), tags_str, Void::Testing::Detail::Color::apply(dim, time_str)); break; case TestState::Failed: - os_ << std::format(" {} {:<40s}{}{}\n", Void::Testing::Detail::Color::apply(bold_red, "✘"), Void::Testing::Detail::Color::apply(red, result.name), tags_str, Void::Testing::Detail::Color::apply(dim, time_str)); + os_ << std::format(" {} {:<44s}{}{:>9s}\n", Void::Testing::Detail::Color::apply(bold_red, "✘"), Void::Testing::Detail::Color::apply(red, result.name), tags_str, Void::Testing::Detail::Color::apply(dim, time_str)); for (const auto& ar : result.assertions) if (!ar.passed) print_assertion_failure(ar); if (!result.crash_info.empty()) print_crash_info(result); break; - case TestState::Skipped: os_ << std::format(" {} {:<40s}{}\n", Void::Testing::Detail::Color::apply(bold_yellow, "⊘"), Void::Testing::Detail::Color::apply(yellow, result.name), Void::Testing::Detail::Color::apply(dim, std::format("[SKIPPED: {}]", result.skip_reason.empty() ? "no reason" : result.skip_reason))); break; - case TestState::Crashed: os_ << std::format(" {} {:<40s}{}\n", Void::Testing::Detail::Color::apply(bold_red, "⚡"), Void::Testing::Detail::Color::apply(red, result.name), Void::Testing::Detail::Color::apply(dim, time_str)); print_crash_info(result); break; + case TestState::Skipped: os_ << std::format(" {} {:<44s}{}\n", Void::Testing::Detail::Color::apply(bold_yellow, "⊘"), Void::Testing::Detail::Color::apply(yellow, result.name), Void::Testing::Detail::Color::apply(dim, std::format("[SKIPPED: {}]", result.skip_reason.empty() ? "no reason" : result.skip_reason))); break; + case TestState::Crashed: os_ << std::format(" {} {:<44s}{:>9s}\n", Void::Testing::Detail::Color::apply(bold_red, "⚡"), Void::Testing::Detail::Color::apply(red, result.name), Void::Testing::Detail::Color::apply(dim, time_str)); print_crash_info(result); break; } } @@ -65,6 +69,25 @@ void ConsoleReporter::on_run_end(const RunResult& result) { if (result.skipped > 0) os_ << std::format("{} {} ", Void::Testing::Detail::Color::apply(bold_yellow, std::to_string(result.skipped)), Void::Testing::Detail::Color::apply(yellow, "⊘")); double total_ms = std::chrono::duration(result.total_duration).count(); os_ << std::format(" {} {}\n", Void::Testing::Detail::Color::apply(dim, "in"), Void::Testing::Detail::Color::apply(bold_cyan, total_ms < 1000 ? std::format("{:.1f}ms", total_ms) : std::format("{:.2f}s", total_ms / 1000.0))) - << Void::Testing::Detail::Color::apply(dim, "╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍") << "\n\n"; + << Void::Testing::Detail::Color::apply(dim, "╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍") << "\n"; + if (!failures_.empty()) { + os_ << "\n" << Void::Testing::Detail::Color::apply(bold_red, " Failures:") << "\n"; + for (const auto& name : failures_) { + os_ << " " << Void::Testing::Detail::Color::apply(red, "✘ " + name) << "\n"; + } + } + if (timings_.size() > 1) { + std::sort(timings_.begin(), timings_.end(), + [](const auto& lhs, const auto& rhs) { + return lhs.first > rhs.first; + }); + os_ << "\n" << Void::Testing::Detail::Color::apply(dim, " Slowest:") << "\n"; + const std::size_t count = std::min(5, timings_.size()); + for (std::size_t i = 0; i < count; ++i) { + os_ << std::format(" {:>9.2f}ms {}\n", timings_[i].first, + Void::Testing::Detail::Color::apply(dim, timings_[i].second)); + } + } + os_ << "\n"; } } // namespace Void::Testing diff --git a/src/Testing/Runner.cpp b/src/Testing/Runner.cpp index 102ff76..94b7f64 100644 --- a/src/Testing/Runner.cpp +++ b/src/Testing/Runner.cpp @@ -177,11 +177,16 @@ namespace Void::Testing } else if (arg == "--parallel") { std::string val; if (need_val(arg, i, val)) { - unsigned parsed = 0; - if (!parse_unsigned_strict(val, parsed)) { - config.parse_error = std::format("Invalid --parallel value: {}", val); + if (val == "auto") { + const unsigned hw = std::thread::hardware_concurrency(); + config.parallel_threads = hw == 0 ? 2U : std::min(hw, 64U); } else { - config.parallel_threads = parsed; + unsigned parsed = 0; + if (!parse_unsigned_strict(val, parsed)) { + config.parse_error = std::format("Invalid --parallel value: {}", val); + } else { + config.parallel_threads = parsed; + } } } } else if (arg == "--help") { @@ -532,7 +537,7 @@ namespace Void::Testing #ifdef VOID_HAS_ASYNC << " " << opt("--parallel ") << Void::Testing::Detail::Color::apply(dim, - "Run tests across n threads (no crash detection)") + "Run tests across n threads, or 'auto' for the CPU count (no crash detection)") << "\n" #endif << " " << opt("--verbose")