1 #ifndef WREPORT_TESTSRUNNER_H 2 #define WREPORT_TESTSRUNNER_H 50 unsigned long long elapsed_ns = 0;
53 TestMethodResult(
const std::string& test_case,
const std::string& test_method)
54 : test_case(test_case), test_method(test_method) {}
58 void set_exception(std::exception& e)
60 error_message = e.what();
61 if (error_message.empty())
62 error_message =
"test threw an exception with an empty error message";
63 exception_typeid =
typeid(e).name();
66 void set_unknown_exception()
68 error_message =
"unknown exception caught";
71 void set_setup_exception(std::exception& e)
73 error_message =
"[setup failed: ";
74 error_message += e.what();
78 void set_teardown_exception(std::exception& e)
80 error_message =
"[teardown failed: ";
81 error_message += e.what();
85 bool is_success()
const 87 return error_message.empty();
90 void print_failure_details(FILE* out)
const;
108 bool skipped =
false;
110 TestCaseResult(
const std::string& test_case) : test_case(test_case) {}
112 void set_setup_failed()
114 fail_setup =
"test case setup method threw an unknown exception";
117 void set_setup_failed(std::exception& e)
119 fail_setup =
"test case setup method threw an exception: ";
120 fail_setup += e.what();
123 void set_teardown_failed()
125 fail_teardown =
"test case teardown method threw an unknown exception";
128 void set_teardown_failed(std::exception& e)
130 fail_teardown =
"test case teardown method threw an exception: ";
131 fail_teardown += e.what();
136 methods.emplace_back(std::move(e));
139 bool is_success()
const 141 if (!fail_setup.empty() || !fail_teardown.empty())
return false;
142 for (
const auto& m: methods)
148 unsigned long long elapsed_ns()
const;
199 bool test_method_should_run(
const std::string& fullname)
const;
258 void register_test_case(
TestCase& test_case);
271 std::vector<TestCaseResult> run_tests(
TestController& controller);
280 const std::vector<TestCaseResult>& results;
281 unsigned methods_ok = 0;
282 unsigned methods_failed = 0;
283 unsigned methods_skipped = 0;
284 unsigned test_cases_ok = 0;
285 unsigned test_cases_failed = 0;
286 bool success =
false;
Test registry.
Definition: testrunner.h:247
virtual void test_method_end(const TestMethod &test_method, const TestMethodResult &test_method_result)
Called after running a test method.
Definition: testrunner.h:184
std::string skipped_reason
If the test has been skipped, this is an optional reason.
Definition: testrunner.h:47
std::string exception_typeid
If non-empty, the test threw an exception and this is its type ID.
Definition: testrunner.h:41
Result of running a whole test case.
Definition: testrunner.h:96
Test case collecting several test methods, and self-registering with the singleton instance of TestRe...
Definition: utils/tests.h:479
std::shared_ptr< TestStack > error_stack
Stack frame of where the error happened.
Definition: testrunner.h:38
std::string test_method
Name of the test method.
Definition: testrunner.h:32
std::string whitelist
Any method not matching this glob expression will not be run.
Definition: testrunner.h:194
virtual bool test_method_begin(const TestMethod &test_method, const TestMethodResult &test_method_result)
Called before running a test method.
Definition: testrunner.h:179
std::vector< TestMethodResult > methods
Outcome of all the methods that have been run.
Definition: testrunner.h:101
Simple default implementation of TestController.
Definition: testrunner.h:209
Abstract interface for the objects that supervise test execution.
Definition: testrunner.h:158
std::string fail_teardown
Set to a non-empty string if the teardown method of the test case failed.
Definition: testrunner.h:106
Definition: testrunner.h:278
Exception thrown when a test assertion fails, normally by Location::fail_test.
Definition: utils/tests.h:102
std::vector< TestCase * > entries
All known test cases.
Definition: testrunner.h:250
virtual void test_case_end(const TestCase &test_case, const TestCaseResult &test_case_result)
Called after running a test case.
Definition: testrunner.h:172
std::string test_case
Name of the test case.
Definition: testrunner.h:99
Verbose implementation of TestController.
Definition: testrunner.h:228
Result of running a test method.
Definition: testrunner.h:26
virtual bool test_case_begin(const TestCase &test_case, const TestCaseResult &test_case_result)
Called before running a test case.
Definition: testrunner.h:167
std::string error_message
If non-empty, the test failed with this error.
Definition: testrunner.h:35
String functions.
Definition: benchmark.h:13
Test method information.
Definition: utils/tests.h:452
std::string blacklist
Any method matching this glob expression will not be run.
Definition: testrunner.h:197
std::string fail_setup
Set to a non-empty string if the setup method of the test case failed.
Definition: testrunner.h:103
Test controller that filters tests via a blacklist/whitelist system containing glob patterns on testc...
Definition: testrunner.h:191
std::string test_case
Name of the test case.
Definition: testrunner.h:29