1 parent
4fc129fb7e
commit
e7186f17f0
42 files changed
+1816
-413
No files matched your search
@@ -0,0 +1,71 @@
|
||||
#include <Void/Testing/ConsoleReporter.hpp>
|
||||
#include <Void/Testing/Detail/Color.hpp>
|
||||
#include <Void/Testing/Detail/SignalHandler.hpp>
|
||||
#include <format>
|
||||
#include <chrono>
|
||||
#include <algorithm>
|
||||
|
||||
namespace Void::Testing {
|
||||
using namespace Detail::Color;
|
||||
|
||||
void ConsoleReporter::on_run_start(const RunConfig&, int total_tests) {
|
||||
os_ << "\n" << apply(bold_blue, "╭──────────────────────────────────────────────╮") << "\n"
|
||||
<< apply(bold_blue, "│") << apply(bold_white, " Void Testing") << apply(dim, " v1.0") << std::string(31, ' ') << apply(bold_blue, "│") << "\n"
|
||||
<< std::format("{}│{} Discovered {} test{}{}│\n", apply(bold_blue, "╰"), apply(dim, ""), apply(bold_white, std::to_string(total_tests)), total_tests != 1 ? "s" : "", std::string(total_tests < 10 ? 33 : 28, ' '))
|
||||
<< apply(bold_blue, "╰──────────────────────────────────────────────╯") << "\n\n";
|
||||
}
|
||||
|
||||
void ConsoleReporter::on_suite_start(const std::string& suite_name, int test_count) {
|
||||
os_ << std::format(" {} {} [{} test{}]\n", apply(bold_blue, "◆"), apply(bold_white, suite_name), apply(dim, std::to_string(test_count)), test_count != 1 ? "s" : "");
|
||||
}
|
||||
|
||||
void ConsoleReporter::on_test_start(const TestCase&) {}
|
||||
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);
|
||||
std::string tags_str;
|
||||
if (!result.tags.empty()) { for(const auto& t : result.tags) tags_str += "[" + t + "]"; tags_str = " " + apply(dim, tags_str); }
|
||||
|
||||
switch (result.state) {
|
||||
case TestState::Passed: os_ << std::format(" {} {:<40s}{}{}\n", apply(bold_green, "✔"), apply(green, result.name), tags_str, apply(dim, time_str)); break;
|
||||
case TestState::Failed:
|
||||
os_ << std::format(" {} {:<40s}{}{}\n", apply(bold_red, "✘"), apply(red, result.name), tags_str, 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", apply(bold_yellow, "⊘"), apply(yellow, result.name), apply(dim, std::format("[SKIPPED: {}]", result.skip_reason.empty() ? "no reason" : result.skip_reason))); break;
|
||||
case TestState::Crashed: os_ << std::format(" {} {:<40s}{}\n", apply(bold_red, "⚡"), apply(red, result.name), apply(dim, time_str)); print_crash_info(result); break;
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleReporter::print_assertion_failure(const AssertionResult& ar) {
|
||||
os_ << apply(red, " ╭─── Assertion Failed") << apply(dim, " ──────────────────────╮") << "\n";
|
||||
std::filesystem::path p{ar.location.file_name()};
|
||||
os_ << std::format(" │ {}:{}\n", apply(bold_white, p.filename().string()), ar.location.line());
|
||||
if (!ar.expression.empty()) os_ << std::format(" │ {}\n", apply(cyan, ar.expression));
|
||||
if (!ar.expected_repr.empty()) os_ << std::format(" │ {} {}\n", apply(bold_white, "expected:"), apply(green, ar.expected_repr));
|
||||
if (!ar.actual_repr.empty()) os_ << std::format(" │ {} {}\n", apply(bold_white, "actual: "), apply(red, ar.actual_repr));
|
||||
if (!ar.message.empty()) os_ << std::format(" │ {}\n", ar.message);
|
||||
os_ << apply(red, " ╰────────────────────────────────────────────╯") << "\n";
|
||||
}
|
||||
|
||||
void ConsoleReporter::print_crash_info(const TestResult& result) {
|
||||
os_ << apply(bold_red, " ╭─── Crash") << apply(dim, " ───────────────────────────╮") << "\n";
|
||||
if (!result.crash_info.empty()) os_ << std::format(" │ {}\n", apply(red, result.crash_info));
|
||||
os_ << apply(bold_red, " ╰────────────────────────────────────────────╯") << "\n";
|
||||
if (!result.stacktrace.empty()) os_ << apply(dim, " Stacktrace:\n") << result.stacktrace << "\n";
|
||||
}
|
||||
|
||||
void ConsoleReporter::on_run_end(const RunResult& result) {
|
||||
os_ << "\n" << apply(dim, "╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍") << "\n"
|
||||
<< std::format(" {} tests: ", apply(bold_white, std::to_string(result.total)));
|
||||
if (result.passed > 0) os_ << std::format("{} {} ", apply(bold_green, std::to_string(result.passed)), apply(green, "✔"));
|
||||
if (result.failed + result.crashed > 0) os_ << std::format("{} {} ", apply(bold_red, std::to_string(result.failed + result.crashed)), apply(red, "✘"));
|
||||
if (result.skipped > 0) os_ << std::format("{} {} ", apply(bold_yellow, std::to_string(result.skipped)), apply(yellow, "⊘"));
|
||||
double total_ms = std::chrono::duration<double, std::milli>(result.total_duration).count();
|
||||
os_ << std::format(" {} {}\n", apply(dim, "in"), apply(bold_cyan, total_ms < 1000 ? std::format("{:.1f}ms", total_ms) : std::format("{:.2f}s", total_ms / 1000.0)))
|
||||
<< apply(dim, "╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍") << "\n\n";
|
||||
}
|
||||
} // namespace Void::Testing
|
||||
Reference in new issue
Block a user