107 lines
2.7 KiB
C++
107 lines
2.7 KiB
C++
#pragma once
|
|
#include <chrono>
|
|
#include <filesystem>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <source_location>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace Void::Testing
|
|
{
|
|
|
|
inline constexpr std::size_t kMaxRetainedAssertionsPerTest = 1000;
|
|
inline constexpr std::size_t kMaxDiagnosticBytesPerTest = 1024ULL * 1024ULL;
|
|
|
|
enum class AssertKind : uint8_t { Expect, Require, Assert };
|
|
enum class TestState : uint8_t { Passed, Failed, Skipped, Crashed };
|
|
|
|
struct AssertionResult {
|
|
bool passed{true};
|
|
AssertKind kind{AssertKind::Expect};
|
|
std::string expression;
|
|
std::string expected_repr;
|
|
std::string actual_repr;
|
|
std::string message;
|
|
std::source_location location;
|
|
static AssertionResult
|
|
ok(std::source_location loc = std::source_location::current())
|
|
{
|
|
return {.passed = true, .location = loc};
|
|
}
|
|
};
|
|
|
|
struct TestCase {
|
|
std::function<void()> run;
|
|
std::string name;
|
|
std::string suite;
|
|
std::string file;
|
|
int line{0};
|
|
bool disabled{false};
|
|
std::string skip_reason;
|
|
std::vector<std::string> tags;
|
|
std::function<void*()> fixture_create;
|
|
std::function<void(void*)> fixture_destroy;
|
|
std::function<void(void*)> fixture_setup;
|
|
std::function<void(void*)> fixture_teardown;
|
|
};
|
|
|
|
struct TestResult {
|
|
std::string name;
|
|
std::string suite;
|
|
TestState state{TestState::Passed};
|
|
std::chrono::nanoseconds duration{0};
|
|
std::vector<AssertionResult> assertions;
|
|
std::string skip_reason;
|
|
std::string crash_info;
|
|
std::string stacktrace;
|
|
std::vector<std::string> tags;
|
|
bool assertions_truncated{false};
|
|
std::size_t dropped_assertions{0};
|
|
// Counted at record time, so failures beyond the bounded assertion
|
|
// retention still determine the test outcome.
|
|
std::size_t failed_assertions{0};
|
|
std::size_t diagnostic_bytes{0};
|
|
std::string cleanup_error;
|
|
};
|
|
|
|
struct SuiteResult {
|
|
std::string name;
|
|
std::vector<TestResult> tests;
|
|
};
|
|
|
|
struct RunResult {
|
|
std::vector<SuiteResult> suites;
|
|
std::chrono::nanoseconds total_duration{0};
|
|
int passed{0};
|
|
int failed{0};
|
|
int skipped{0};
|
|
int crashed{0};
|
|
int total{0};
|
|
std::string config_error;
|
|
};
|
|
|
|
struct RunConfig {
|
|
std::string filter_pattern;
|
|
std::string suite_filter;
|
|
std::string reporter{"console"};
|
|
std::string output_file;
|
|
std::string tag_filter;
|
|
std::string log_file;
|
|
bool list_only{false};
|
|
bool verbose{false};
|
|
bool no_color{false};
|
|
bool shuffle{false};
|
|
bool show_help{false};
|
|
bool allow_empty{false};
|
|
unsigned repeat{1};
|
|
unsigned random_seed{0};
|
|
unsigned parallel_threads{0}; // 0 = sequential
|
|
std::string parse_error;
|
|
std::string selftest_child;
|
|
};
|
|
|
|
} // namespace Void::Testing
|