|
micro-test-plus 4.1.0
µTest++ Testing Framework
|
The test runner for the µTest++ framework. More...
#include <micro-os-plus/micro-test-plus.h>
Public Member Functions | |
| runner (const char *top_suite_name) | |
| Deprecated constructor for the runner class. | |
| runner (const runner &)=delete | |
| Deleted copy constructor to prevent copying. | |
| runner (runner &&)=delete | |
| Deleted move constructor to prevent moving. | |
| runner (void) | |
| Constructor for the runner class. | |
| virtual | ~runner () override |
| Destructor for the runner class. | |
| void | abort (const reflection::source_location &sl=reflection::source_location::current()) |
| Aborts test execution immediately. | |
| int | exit_code (void) |
| Returns 0 if all tests were successful, 1 otherwise. | |
| class suite & | initialise (int argc, char *argv[], const char *top_suite_name="") |
| Initialises the test runner with command-line arguments. | |
| const char * | name (void) const noexcept |
| Gets the node name. | |
| runner & | operator= (const runner &)=delete |
| Deleted copy assignment operator to prevent copying. | |
| runner & | operator= (runner &&)=delete |
| Deleted move assignment operator to prevent moving. | |
| class reporter & | reporter (void) const noexcept |
| Returns a reference to the test reporter. | |
| template<typename Callable_T, typename... Args_T> | |
| void | suite (const char *name, Callable_T &&callable, Args_T &&... arguments) |
| Adds a test suite to the runner. | |
| size_t | suites_count (void) const noexcept |
| Returns the count of test suites. | |
| const detail::timestamps & | timings () const noexcept |
| Gets the timings for this runner (const overload). | |
| detail::timestamps & | timings () noexcept |
| Gets the timings for this runner. | |
| virtual size_t | total_suites_count (void) const noexcept |
| Returns the total count of registered test suites. | |
| const runner_totals & | totals () const noexcept |
| Gets the totals for the test (const overload). | |
| runner_totals & | totals () noexcept |
| Gets the totals for the test. | |
Protected Member Functions | |
| void | register_suite_ (std::unique_ptr< class suite > suite) |
| Registers a test suite with the runner. | |
| virtual void | run_suites_ (void) |
| Runs all registered test suites. | |
Protected Attributes | |
| std::vector< std::unique_ptr< class suite > > | children_suites_ |
| Owning collection of dynamically registered child suites. | |
| const char * | name_ |
| The test node name. | |
| std::unique_ptr< class reporter > | reporter_ |
| Pointer to the test reporter used for outputting test results. | |
| detail::timestamps | timings_ |
| Timings for this runner. | |
| class top_suite | top_suite_ |
| The implicit top-level suite; always present and executed first. | |
| std::string | top_suite_name_ |
| Owned storage for the implicit top-suite name. | |
| runner_totals | totals_ |
| Totals for the test node, including nested cases. | |
The runner class is responsible for managing the registration and execution of test suites within the µTest++ framework. It maintains a collection of test suites, each of which registers itself automatically upon construction, enabling seamless integration and execution of tests across different components and folders of a project.
The test runner provides methods for initialising the test environment, registering test suites, retrieving the runner's name, and determining the overall test result via an exit code. It also offers an abort mechanism for terminating test execution in exceptional circumstances.
All members and methods are defined within the micro_os_plus::micro_test_plus namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.
| micro_os_plus::micro_test_plus::runner::runner | ( | void | ) |
The constructor initialises a new runner instance together with its top suite (top_suite_). If tracing is enabled, it outputs the function signature for diagnostic purposes.
Definition at line 107 of file runner.cpp.
References micro_os_plus::micro_test_plus::detail::test_node::test_node(), micro_os_plus::micro_test_plus::detail::test_node::name(), and top_suite_.
Referenced by runner(), runner(), micro_os_plus::micro_test_plus::static_runner::static_runner(), micro_os_plus::micro_test_plus::static_runner::static_runner(), operator=(), operator=(), micro_os_plus::micro_test_plus::static_runner::operator=(), and micro_os_plus::micro_test_plus::static_runner::register_static_suite().
| micro_os_plus::micro_test_plus::runner::runner | ( | const char * | top_suite_name | ) |
| [in] | top_suite_name | The name given to the implicit top suite. Defaults to an empty string. |
The constructor initialises a new runner instance together with its top suite (top_suite_). If tracing is enabled, it outputs the function signature for diagnostic purposes.
Definition at line 130 of file runner.cpp.
References micro_os_plus::micro_test_plus::detail::test_node::test_node(), micro_os_plus::micro_test_plus::detail::test_node::name(), and top_suite_.
|
delete |
References runner().
|
delete |
References runner().
|
overridevirtual |
The reporter_ unique pointer is released automatically. If tracing is enabled, the function signature is output for diagnostic purposes.
Definition at line 153 of file runner.cpp.
| void micro_os_plus::micro_test_plus::runner::abort | ( | const reflection::source_location & | sl = reflection::source_location::current () | ) |
| sl | The source location from which the abort is triggered. |
Prints the source location of the fatal error to stderr and then terminates the process via ::abort().
Definition at line 431 of file runner.cpp.
References abort(), micro_os_plus::micro_test_plus::reflection::source_location::file_name(), micro_os_plus::micro_test_plus::reflection::source_location::line(), and micro_os_plus::micro_test_plus::reflection::short_name().
Referenced by abort().
| int micro_os_plus::micro_test_plus::runner::exit_code | ( | void | ) |
Finalises the top suite by recording its end timestamp and notifying the reporter, then accumulates its totals into the runner totals. Subsequently invokes run_suites_() to sort, execute, and accumulate all registered child suites. Finally, records the session end timestamp, notifies the reporter, and returns 0 if all checks passed or 1 otherwise.
Definition at line 384 of file runner.cpp.
References reporter_, run_suites_(), timings_, top_suite_, and micro_os_plus::micro_test_plus::detail::test_node::totals_.
| suite & micro_os_plus::micro_test_plus::runner::initialise | ( | int | argc, |
| char * | argv[], | ||
| const char * | top_suite_name = "" ) |
| argc | The argument count from main(). |
| argv | The argument vector from main(). |
| top_suite_name | The name given to the implicit top suite. Defaults to an empty string. |
Captures command-line arguments, selects the reporter implementation (human or tap), starts session timing, and emits the initial reporter notifications for the session and top suite.
If the top suite name is not provided, it attempts to derive a name from argv[0] or defaults to "default suite".
If tracing is enabled, the command-line arguments are also logged for diagnostic purposes.
Definition at line 182 of file runner.cpp.
References micro_os_plus::micro_test_plus::utility::extract_file_name(), reporter_, timings_, top_suite_, and top_suite_name_.
|
inlinenodiscardnoexceptinherited |
Returns a pointer to the null-terminated name stored in name_.
Definition at line 91 of file test-inlines.h.
References name_.
Referenced by micro_os_plus::micro_test_plus::detail::runnable< Self_T >::runnable(), micro_os_plus::micro_test_plus::detail::runnable_base::runnable_base(), micro_os_plus::micro_test_plus::runner::runner(), micro_os_plus::micro_test_plus::runner::runner(), micro_os_plus::micro_test_plus::static_runner::static_runner(), micro_os_plus::micro_test_plus::static_runner::static_runner(), test_node(), micro_os_plus::micro_test_plus::detail::runnable_base::after_subtest_create_(), micro_os_plus::micro_test_plus::reporter_human::begin_subtest(), micro_os_plus::micro_test_plus::reporter_tap::begin_subtest(), micro_os_plus::micro_test_plus::reporter_human::begin_suite(), micro_os_plus::micro_test_plus::reporter_tap::begin_suite(), micro_os_plus::micro_test_plus::reporter_human::end_subtest(), micro_os_plus::micro_test_plus::reporter_tap::end_subtest(), micro_os_plus::micro_test_plus::reporter_human::end_suite(), micro_os_plus::micro_test_plus::reporter_tap::end_suite(), micro_os_plus::micro_test_plus::runner::operator=(), and micro_os_plus::micro_test_plus::runner::suite().
References runner().
|
protected |
| [in] | suite | Owning pointer to the test suite to register. |
Takes ownership of the supplied suite unique pointer and appends it to the internal children_suites_ vector, deferring execution until run_suites_() is called. If tracing is enabled, the suite name is logged for diagnostic purposes.
Definition at line 307 of file runner.cpp.
References children_suites_, and suite().
Referenced by operator=(), and suite().
|
inlinenodiscardnoexcept |
Returns a reference to the reporter object stored in the unique pointer.
Definition at line 76 of file runner-inlines.h.
References reporter_.
Referenced by operator=().
|
protectedvirtual |
Sorts children_suites_ alphabetically by suite name using a selection sort on unique_ptr::swap, avoiding the -Waggregate-return diagnostic that std::sort would trigger on unique-pointer iterators. Each suite is assigned a 1-based index offset by the top-suite index, executed via suite::run(), and its totals are accumulated into the runner totals. The executed-subtest counter is not incremented; suites are not counted as subtests.
Reimplemented in micro_os_plus::micro_test_plus::static_runner.
Definition at line 337 of file runner.cpp.
References children_suites_, and micro_os_plus::micro_test_plus::detail::test_node::totals_.
Referenced by exit_code(), operator=(), and micro_os_plus::micro_test_plus::static_runner::run_suites_().
| void micro_os_plus::micro_test_plus::runner::suite | ( | const char * | name, |
| Callable_T && | callable, | ||
| Args_T &&... | arguments ) |
| Callable_T | The type of a callable object. |
| Args_T | The types of the callable arguments. |
| [in] | name | The test suite name or description, used in reports. |
| [in] | callable | A generic callable object, usually a lambda, invoked to perform the test suite. |
| [in] | arguments | A possibly empty list of arguments to be passed to the callable. |
Constructs a suite object on the heap, binding the callable and any additional arguments, then transfers ownership to the runner via register_suite_(). The suite runs immediately as part of the registration process.
Definition at line 112 of file runner-inlines.h.
References micro_os_plus::micro_test_plus::detail::test_node::name(), and register_suite_().
Referenced by operator=(), micro_os_plus::micro_test_plus::static_runner::operator=(), micro_os_plus::micro_test_plus::static_runner::register_static_suite(), and register_suite_().
|
nodiscardnoexcept |
Returns the number of registered child suites plus one, accounting for the top suite.
Definition at line 459 of file runner.cpp.
References children_suites_.
Referenced by operator=(), micro_os_plus::micro_test_plus::static_runner::run_suites_(), total_suites_count(), and micro_os_plus::micro_test_plus::static_runner::total_suites_count().
|
inlinenodiscardnoexcept |
Returns a const reference to the timestamps member.
Definition at line 96 of file runner-inlines.h.
References timings_.
|
inlinenodiscardnoexcept |
Returns a reference to the timestamps member.
Definition at line 86 of file runner-inlines.h.
References timings_.
Referenced by micro_os_plus::micro_test_plus::reporter_human::end_session(), micro_os_plus::micro_test_plus::reporter_tap::end_session(), and operator=().
|
nodiscardvirtualnoexcept |
For the base runner, the total suite count equals suites_count(), as there are no additional static suites.
Reimplemented in micro_os_plus::micro_test_plus::static_runner.
Definition at line 470 of file runner.cpp.
References suites_count().
Referenced by micro_os_plus::micro_test_plus::reporter_human::end_session(), and micro_os_plus::micro_test_plus::reporter_tap::end_session().
|
inlinenodiscardnoexceptinherited |
Returns a const reference to the runner_totals member.
Definition at line 111 of file test-inlines.h.
References totals_.
|
inlinenodiscardnoexceptinherited |
Returns a reference to the runner_totals member.
Definition at line 101 of file test-inlines.h.
References totals_.
Referenced by micro_os_plus::micro_test_plus::detail::runnable_base::after_subtest_create_(), micro_os_plus::micro_test_plus::reporter_human::end_session(), micro_os_plus::micro_test_plus::reporter_tap::end_session(), micro_os_plus::micro_test_plus::reporter_human::end_subtest(), micro_os_plus::micro_test_plus::reporter_tap::end_subtest(), micro_os_plus::micro_test_plus::reporter_human::end_suite(), micro_os_plus::micro_test_plus::reporter_tap::end_suite(), and operator=().
|
protected |
Each call to runner::suite() appends a new suite to this vector and runs it immediately. The vector retains ownership of all suites for the lifetime of the runner.
Definition at line 301 of file runner.h.
Referenced by register_suite_(), run_suites_(), and suites_count().
|
protectedinherited |
Definition at line 224 of file test.h.
Referenced by test_node(), micro_os_plus::micro_test_plus::detail::runnable< Self_T >::~runnable(), micro_os_plus::micro_test_plus::detail::runnable_base::~runnable_base(), ~test_node(), and name().
|
protected |
Definition at line 306 of file runner.h.
Referenced by exit_code(), initialise(), and reporter().
|
protected |
Definition at line 311 of file runner.h.
Referenced by exit_code(), initialise(), timings(), and timings().
|
protected |
Definition at line 291 of file runner.h.
Referenced by runner(), runner(), exit_code(), and initialise().
|
protected |
Definition at line 316 of file runner.h.
Referenced by initialise().
|
protectedinherited |
Definition at line 229 of file test.h.
Referenced by micro_os_plus::micro_test_plus::runner::exit_code(), micro_os_plus::micro_test_plus::runner::run_suites_(), micro_os_plus::micro_test_plus::static_runner::run_suites_(), totals(), and totals().