|
micro-test-plus 4.1.0
µTest++ Testing Framework
|
A runner variant that also manages statically-registered test suites. More...
#include <micro-os-plus/micro-test-plus.h>
Public Member Functions | |
| static_runner (const char *top_suite_name) | |
| Constructs the static runner with a top-suite name. | |
| static_runner (const static_runner &)=delete | |
| Deleted copy constructor to prevent copying. | |
| static_runner (static_runner &&)=delete | |
| Deleted move constructor to prevent moving. | |
| static_runner (void) | |
| Constructor for the runner class. | |
| virtual | ~static_runner () override |
| Destructor for the static_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. | |
| static_runner & | operator= (const static_runner &)=delete |
| Deleted copy assignment operator to prevent copying. | |
| static_runner & | operator= (static_runner &&)=delete |
| Deleted move assignment operator to prevent moving. | |
| class reporter & | reporter (void) const noexcept |
| Returns a reference to the test reporter. | |
| size_t | static_suites_count (void) const noexcept |
| Returns the total count of registered static test suites. | |
| 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 final override |
| Returns the total count of all test suites, including static and dynamic. | |
| const runner_totals & | totals () const noexcept |
| Gets the totals for the test (const overload). | |
| runner_totals & | totals () noexcept |
| Gets the totals for the test. | |
Static Public Member Functions | |
| static void | register_static_suite (static_runner &runner, static_suite &suite) |
| Registers a static test suite with the runner. | |
Protected Member Functions | |
| void | register_suite_ (std::unique_ptr< class suite > suite) |
| Registers a test suite with the runner. | |
| void | run_suites_ (void) override |
| Runs all child suites, including statically registered ones. | |
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. | |
| std::vector< static_suite * > * | static_children_suites_ |
| Pointer to the vector of registered static test suites. | |
| 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. | |
static_runner extends runner to handle static_suite objects that are declared at namespace scope and therefore constructed before or after the runner itself, in unspecified static-initialisation order.
The key design constraint is that static_runner instances must themselves be declared at namespace scope (in the BSS segment), so the pointer static_children_suites_ is zero-initialised by the C runtime before any constructor runs. This ensures that static_suite objects constructed before static_runner can safely append themselves to the vector without losing registrations.
During exit_code(), run_suites_() is called, which first runs all dynamically registered suites (base class behaviour) and then iterates over the statically registered suites.
| micro_os_plus::micro_test_plus::static_runner::static_runner | ( | void | ) |
Delegates construction to the runner base class. If tracing is enabled, the function signature and suite name are output for diagnostic purposes.
Definition at line 483 of file runner.cpp.
References micro_os_plus::micro_test_plus::runner::runner(), and micro_os_plus::micro_test_plus::detail::test_node::name().
Referenced by static_runner(), static_runner(), operator=(), operator=(), and register_static_suite().
| micro_os_plus::micro_test_plus::static_runner::static_runner | ( | const char * | top_suite_name | ) |
| top_suite_name | The name of the implicit top-level suite. Defaults to an empty string. |
Delegates construction to the runner base class with the given top_suite_name. If tracing is enabled, the function signature and suite name are output for diagnostic purposes.
Definition at line 506 of file runner.cpp.
References micro_os_plus::micro_test_plus::runner::runner(), and micro_os_plus::micro_test_plus::detail::test_node::name().
|
delete |
References static_runner().
|
delete |
References static_runner().
|
overridevirtual |
If static_children_suites_ is non-null, the dynamically allocated vector of raw pointers is deleted and the pointer is reset to nullptr. The pointed-to static_suite objects are not deleted, as they are static storage-duration objects. If tracing is enabled, the function signature is output for diagnostic purposes.
Definition at line 532 of file runner.cpp.
References static_children_suites_.
|
inherited |
| 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().
|
inherited |
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_.
|
inherited |
| 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().
|
delete |
References static_runner().
|
delete |
|
static |
| [in] | runner | The static runner instance. |
| [in] | suite | The static test suite to register. |
If runner.static_children_suites_ is null, a new std::vector<static_suite*> is heap-allocated and assigned to it. The address of suite is then appended to the vector. This method is intended to be called from the constructor of static_suite, before test execution begins.
Definition at line 637 of file runner.cpp.
References micro_os_plus::micro_test_plus::runner::runner(), static_runner(), and micro_os_plus::micro_test_plus::runner::suite().
Referenced by operator=(), and micro_os_plus::micro_test_plus::detail::register_static_suite().
|
protectedinherited |
| [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().
|
inlinenodiscardnoexceptinherited |
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=().
|
overrideprotectedvirtual |
First invokes runner::run_suites_() to execute all dynamically registered child suites. If static_children_suites_ is non-null, its contents are sorted alphabetically by suite name using selection sort on raw pointers, each suite is assigned a 1-based index offset by the dynamic suite count, executed via suite::run(), and its totals are accumulated into the runner totals.
Reimplemented from micro_os_plus::micro_test_plus::runner.
Definition at line 582 of file runner.cpp.
References micro_os_plus::micro_test_plus::runner::run_suites_(), static_children_suites_, micro_os_plus::micro_test_plus::runner::suites_count(), and micro_os_plus::micro_test_plus::detail::test_node::totals_.
|
nodiscardnoexcept |
Returns the number of elements in static_children_suites_, or zero if the vector has not been allocated yet.
Definition at line 554 of file runner.cpp.
References static_children_suites_.
Referenced by operator=(), and total_suites_count().
|
inherited |
| 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_().
|
nodiscardnoexceptinherited |
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().
|
inlinenodiscardnoexceptinherited |
Returns a const reference to the timestamps member.
Definition at line 96 of file runner-inlines.h.
References timings_.
|
inlinenodiscardnoexceptinherited |
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=().
|
nodiscardfinaloverridevirtualnoexcept |
Returns the combined count of dynamically registered suites (from the base runner) and statically registered suites.
Reimplemented from micro_os_plus::micro_test_plus::runner.
Definition at line 567 of file runner.cpp.
References static_suites_count(), and micro_os_plus::micro_test_plus::runner::suites_count().
|
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=().
|
protectedinherited |
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().
|
protectedinherited |
Definition at line 306 of file runner.h.
Referenced by exit_code(), initialise(), and reporter().
|
protected |
static_runner instances are always declared at namespace scope, so this pointer lives in the BSS segment and is zero-initialised before any constructor runs. This guarantees that static test suites registered before this runner's constructor executes (due to unspecified static initialisation order across translation units) are not lost. The pointer MUST NOT carry an explicit default member initialiser, as that would run during construction and could overwrite a value already set by an earlier-constructed static_suite.
Definition at line 450 of file runner.h.
Referenced by ~static_runner(), run_suites_(), and static_suites_count().
|
protectedinherited |
Definition at line 311 of file runner.h.
Referenced by exit_code(), initialise(), timings(), and timings().
|
protectedinherited |
Definition at line 291 of file runner.h.
Referenced by runner(), runner(), exit_code(), and initialise().
|
protectedinherited |
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().