Testing: parallel auto mode, aligned timings and slowest/failure summaries
This commit is contained in:
1 parent
af8757080f
commit
7f861fa78f
3 files changed
+43
-10
No files matched your search
@@ -2,6 +2,9 @@
|
||||
#include <Void/Testing/Reporter.hpp>
|
||||
#include <Void/Testing/Detail/Color.hpp>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
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<std::pair<double, std::string>> timings_;
|
||||
std::vector<std::string> failures_;
|
||||
void print_assertion_failure(const AssertionResult& ar);
|
||||
void print_crash_info(const TestResult& result);
|
||||
};
|
||||
|
||||
@@ -24,18 +24,22 @@ void ConsoleReporter::on_suite_end(const SuiteResult&) {}
|
||||
void ConsoleReporter::on_test_end(const TestResult& result) {
|
||||
double ms = std::chrono::duration<double, std::milli>(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<double, std::milli>(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<std::size_t>(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
|
||||
+10
-5
@@ -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 <n>")
|
||||
<< 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")
|
||||
|
||||
Reference in new issue
Block a user