1 parent
f0825fbd1a
commit
42268c6c35
45 files changed
+2732
-262
No files matched your search
+67
-1
@@ -1,5 +1,7 @@
|
||||
#include <Void/Testing/Runner.hpp>
|
||||
#include "Void/Testing/Config.hpp"
|
||||
#include <Void/Logging/FileLogger.hpp>
|
||||
#include <Void/Logging/Level.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/ConsoleReporter.hpp>
|
||||
#include <Void/Stacktrace/Color.hpp>
|
||||
@@ -10,8 +12,10 @@
|
||||
#include <algorithm>
|
||||
#include <csignal>
|
||||
#include <cstdlib>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <regex>
|
||||
#include <unordered_map>
|
||||
@@ -26,7 +30,7 @@ namespace Void::Testing
|
||||
std::string arg = argv[i];
|
||||
if ((arg == "--filter" || arg == "--suite" || arg == "--reporter" ||
|
||||
arg == "--output" || arg == "--tag" || arg == "--seed" ||
|
||||
arg == "--repeat") &&
|
||||
arg == "--repeat" || arg == "--log-file") &&
|
||||
i + 1 < argc) {
|
||||
std::string val = argv[++i];
|
||||
if (arg == "--filter") {
|
||||
@@ -39,6 +43,8 @@ namespace Void::Testing
|
||||
config.output_file = val;
|
||||
} else if (arg == "--tag") {
|
||||
config.tag_filter = val;
|
||||
} else if (arg == "--log-file") {
|
||||
config.log_file = val;
|
||||
} else if (arg == "--seed") {
|
||||
config.shuffle = true;
|
||||
config.random_seed = static_cast<unsigned>(std::stoul(val));
|
||||
@@ -250,6 +256,10 @@ namespace Void::Testing
|
||||
<< "\n"
|
||||
<< " " << apply(green, "--output <file> ")
|
||||
<< apply(dim, "Write reporter output to a file") << "\n"
|
||||
<< " " << apply(green, "--log-file <file> ")
|
||||
<< apply(dim,
|
||||
"Mirror test events to <file> via Void::Logging")
|
||||
<< "\n"
|
||||
<< " " << apply(green, "--verbose ")
|
||||
<< apply(dim, "Enable verbose output") << "\n"
|
||||
<< " " << apply(green, "--no-color ")
|
||||
@@ -274,6 +284,17 @@ namespace Void::Testing
|
||||
auto tests = filter_tests(all_tests, config);
|
||||
auto reporter = create_reporter(config);
|
||||
|
||||
std::unique_ptr<Void::Logging::FileLogger> log_sink;
|
||||
if (!config.log_file.empty()) {
|
||||
try {
|
||||
log_sink = std::make_unique<Void::Logging::FileLogger>(
|
||||
config.log_file);
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "warning: --log-file failed: " << e.what()
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (config.list_only) {
|
||||
for (const auto& t : tests) {
|
||||
std::cout << t.suite << "." << t.name
|
||||
@@ -284,9 +305,17 @@ namespace Void::Testing
|
||||
|
||||
RunResult run_result;
|
||||
reporter->on_run_start(config, static_cast<int>(tests.size()));
|
||||
if (log_sink) {
|
||||
log_sink->info(std::format("run start: {} test(s) discovered",
|
||||
tests.size()));
|
||||
}
|
||||
if (config.shuffle) {
|
||||
std::shuffle(tests.begin(), tests.end(),
|
||||
std::mt19937{config.random_seed});
|
||||
if (log_sink) {
|
||||
log_sink->info(std::format("shuffle enabled (seed = {})",
|
||||
config.random_seed));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<SuiteResult> suite_results;
|
||||
@@ -309,10 +338,41 @@ namespace Void::Testing
|
||||
return t.suite ==
|
||||
suite.name;
|
||||
}));
|
||||
if (log_sink) {
|
||||
log_sink->info(
|
||||
std::format("suite start: {}", suite.name));
|
||||
}
|
||||
}
|
||||
reporter->on_test_start(test);
|
||||
auto result = execute_test(test);
|
||||
reporter->on_test_end(result);
|
||||
if (log_sink) {
|
||||
const auto qualified =
|
||||
std::format("{}.{}", result.suite, result.name);
|
||||
switch (result.state) {
|
||||
case TestState::Passed:
|
||||
log_sink->info(
|
||||
std::format("test pass: {}", qualified));
|
||||
break;
|
||||
case TestState::Failed:
|
||||
log_sink->error(std::format(
|
||||
"test fail: {} — {}", qualified,
|
||||
result.crash_info.empty() ? "assertion failed"
|
||||
: result.crash_info));
|
||||
break;
|
||||
case TestState::Skipped:
|
||||
log_sink->warning(std::format(
|
||||
"test skip: {} ({})", qualified,
|
||||
result.skip_reason.empty() ? "no reason"
|
||||
: result.skip_reason));
|
||||
break;
|
||||
case TestState::Crashed:
|
||||
log_sink->fatal(std::format(
|
||||
"test crash: {} — {}", qualified,
|
||||
result.crash_info));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rep == config.repeat - 1) {
|
||||
suite.tests.push_back(std::move(result));
|
||||
}
|
||||
@@ -343,6 +403,12 @@ namespace Void::Testing
|
||||
}
|
||||
run_result.total_duration = end_time - start_time;
|
||||
reporter->on_run_end(run_result);
|
||||
if (log_sink) {
|
||||
log_sink->info(std::format(
|
||||
"run end: {} total / {} passed / {} failed / {} skipped / {} crashed",
|
||||
run_result.total, run_result.passed, run_result.failed,
|
||||
run_result.skipped, run_result.crashed));
|
||||
}
|
||||
return run_result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
void_add_module(Testing INTERNAL_DEPS Stacktrace)
|
||||
void_add_module(Testing INTERNAL_DEPS Stacktrace Logging Result)
|
||||
Reference in new issue
Block a user