1#ifndef RADARELAB_UTILS_TESTSRUNNER_H
2#define RADARELAB_UTILS_TESTSRUNNER_H
59 void set_exception(std::exception& e)
63 error_message =
"test threw an exception with an empty error message";
67 void set_unknown_exception()
72 void set_setup_exception(std::exception& e)
79 void set_teardown_exception(std::exception& e)
86 bool is_success()
const
91 void print_failure_details(FILE* out)
const;
113 void set_setup_failed()
115 fail_setup =
"test case setup method threw an unknown exception";
118 void set_setup_failed(std::exception& e)
120 fail_setup =
"test case setup method threw an exception: ";
124 void set_teardown_failed()
126 fail_teardown =
"test case teardown method threw an unknown exception";
129 void set_teardown_failed(std::exception& e)
131 fail_teardown =
"test case teardown method threw an exception: ";
135 void add_test_method(TestMethodResult&& e)
137 methods.emplace_back(std::move(e));
140 bool is_success()
const
149 unsigned long long elapsed_ns()
const;
200 bool test_method_should_run(
const std::string& fullname)
const;
212 radarelab::utils::term::Terminal& output;
231 radarelab::utils::term::Terminal& output;
279struct TestResultStats
281 const std::vector<TestCaseResult>& results;
282 unsigned methods_ok = 0;
283 unsigned methods_failed = 0;
284 unsigned methods_skipped = 0;
285 unsigned test_cases_ok = 0;
286 unsigned test_cases_failed = 0;
287 bool success =
false;
289 TestResultStats(
const std::vector<TestCaseResult>& results);
291 void print_results(radarelab::utils::term::Terminal& out);
292 void print_stats(radarelab::utils::term::Terminal& out);
293 void print_summary(radarelab::utils::term::Terminal& out);
std::string allowlist
Any method not matching this glob expression will not be run.
std::string blocklist
Any method matching this glob expression will not be run.
Test controller that filters tests via a blocklist/allowlist system containing glob patterns on testc...
void test_case_end(const TestCase &test_case, const TestCaseResult &test_case_result) override
Called after running a test case.
bool test_case_begin(const TestCase &test_case, const TestCaseResult &test_case_result) override
Called before running a test case.
void test_method_end(const TestMethod &test_method, const TestMethodResult &test_method_result) override
Called after running a test method.
bool test_method_begin(const TestMethod &test_method, const TestMethodResult &test_method_result) override
Called before running a test method.
Simple default implementation of TestController.
std::string fail_teardown
Set to a non-empty string if the teardown method of the test case failed.
std::vector< TestMethodResult > methods
Outcome of all the methods that have been run.
std::string test_case
Name of the test case.
std::string fail_setup
Set to a non-empty string if the setup method of the test case failed.
bool skipped
Set to true if this test case has been skipped.
Result of running a whole test case.
Test case collecting several test methods, and self-registering with the singleton instance of TestRe...
virtual bool test_case_begin(const TestCase &test_case, const TestCaseResult &test_case_result)
Called before running a test case.
virtual void test_case_end(const TestCase &test_case, const TestCaseResult &test_case_result)
Called after running a test case.
virtual bool test_method_begin(const TestMethod &test_method, const TestMethodResult &test_method_result)
Called before running a test method.
virtual void test_method_end(const TestMethod &test_method, const TestMethodResult &test_method_result)
Called after running a test method.
Abstract interface for the objects that supervise test execution.
Exception thrown when a test assertion fails, normally by Location::fail_test.
std::string test_method
Name of the test method.
std::string skipped_reason
If the test has been skipped, this is an optional reason.
std::shared_ptr< TestStack > error_stack
Stack frame of where the error happened.
bool skipped
True if the test has been skipped.
std::string test_case
Name of the test case.
unsigned long long elapsed_ns
Time in nanoseconds it took the test to run.
std::string exception_typeid
If non-empty, the test threw an exception and this is its type ID.
std::string error_message
If non-empty, the test failed with this error.
Result of running a test method.
static TestRegistry & get()
Get the singleton instance of TestRegistry.
void iterate_test_methods(std::function< void(const TestCase &, const TestMethod &)>)
Iterate on all test methods known by this registry.
std::vector< TestCaseResult > run_tests(TestController &controller)
Run all the registered tests using the given controller.
void register_test_case(TestCase &test_case)
Register a new test case.
std::vector< TestCase * > entries
All known test cases.
void test_case_end(const TestCase &test_case, const TestCaseResult &test_case_result) override
Called after running a test case.
bool test_case_begin(const TestCase &test_case, const TestCaseResult &test_case_result) override
Called before running a test case.
bool test_method_begin(const TestMethod &test_method, const TestMethodResult &test_method_result) override
Called before running a test method.
void test_method_end(const TestMethod &test_method, const TestMethodResult &test_method_result) override
Called after running a test method.
Verbose implementation of TestController.