static_runner Class
A runner variant that also manages statically-registered test suites. More...
Declaration
Included Headers
Base class
| class | runner |
|
The test runner for the µTest++ framework. More... | |
Public Constructors Index
| static_runner (const char *top_suite_name) | |
|
Constructs the static runner with a top-suite name. More... | |
| static_runner (const static_runner &)=delete | |
|
Deleted copy constructor to prevent copying. More... | |
| static_runner (static_runner &&)=delete | |
|
Deleted move constructor to prevent moving. More... | |
| static_runner (void) | |
|
Constructor for the runner class. More... | |
Public Destructor Index
| ~static_runner () override | |
|
Destructor for the static_runner class. More... | |
Public Operators Index
| static_runner & | operator= (const static_runner &)=delete |
|
Deleted copy assignment operator to prevent copying. More... | |
| static_runner & | operator= (static_runner &&)=delete |
|
Deleted move assignment operator to prevent moving. More... | |
Public Member Functions Index
| void | abort (const reflection::source_location &sl=reflection::source_location::current()) |
|
Aborts test execution immediately. More... | |
| int | exit_code (void) |
|
Returns 0 if all tests were successful, 1 otherwise. More... | |
| class suite & | initialise (int argc, char *argv[], const char *top_suite_name="") |
|
Initialises the test runner with command-line arguments. More... | |
| const char * | name (void) const noexcept |
|
Gets the node name. More... | |
| class reporter & | reporter (void) const noexcept |
|
Returns a reference to the test reporter. More... | |
| size_t | static_suites_count (void) const noexcept |
|
Returns the total count of registered static test suites. More... | |
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. More... | |
| size_t | suites_count (void) const noexcept |
|
Returns the count of test suites. More... | |
| const detail::timestamps & | timings () const noexcept |
|
Gets the timings for this runner (const overload). More... | |
| detail::timestamps & | timings () noexcept |
|
Gets the timings for this runner. More... | |
| size_t | total_suites_count (void) const noexcept final override |
|
Returns the total count of all test suites, including static and dynamic. More... | |
| const runner_totals & | totals () const noexcept |
|
Gets the totals for the test (const overload). More... | |
| runner_totals & | totals () noexcept |
|
Gets the totals for the test. More... | |
Protected Member Functions Index
| void | register_suite_ (std::unique_ptr< class suite > suite) |
|
Registers a test suite with the runner. More... | |
| void | run_suites_ (void) override |
|
Runs all child suites, including statically registered ones. More... | |
Protected Member Attributes Index
| std::vector< std::unique_ptr< class suite > > | children_suites_ |
|
Owning collection of dynamically registered child suites. More... | |
| const char * | name_ |
|
The test node name. More... | |
| std::unique_ptr< class reporter > | reporter_ |
|
Pointer to the test reporter used for outputting test results. More... | |
| std::vector< static_suite * > * | static_children_suites_ |
|
Pointer to the vector of registered static test suites. More... | |
| detail::timestamps | timings_ |
|
Timings for this runner. More... | |
| class { ... } | top_suite_ |
|
The implicit top-level suite; always present and executed first. More... | |
| std::string | top_suite_name_ |
|
Owned storage for the implicit top-suite name. More... | |
| runner_totals | totals_ |
|
Totals for the test node, including nested cases. More... | |
Public Static Functions Index
| static void | register_static_suite (static_runner &runner, static_suite &suite) |
|
Registers a static test suite with the runner. More... | |
Description
A runner variant that also manages statically-registered test suites.
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.
Definition at line 344 of file runner.h.
Public Constructors
static_runner()
|
Constructs the static runner with a top-suite name.
- Parameters
-
top_suite_name The name of the implicit top-level suite. Defaults to an empty string.
- Deprecated
-
Use the anonymous constructor.
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.
Declaration at line 363 of file runner.h, 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.
static_runner()
| delete |
Deleted copy constructor to prevent copying.
Definition at line 368 of file runner.h.
Reference static_runner.
static_runner()
| delete |
Deleted move constructor to prevent moving.
Definition at line 373 of file runner.h.
Reference static_runner.
static_runner()
|
Constructor for the runner class.
- Parameters
None.
Delegates construction to the runner base class. If tracing is enabled, the function signature and suite name are output for diagnostic purposes.
Declaration at line 353 of file runner.h, 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.
Public Destructor
~static_runner()
| virtual |
Destructor for the static_runner class.
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.
Declaration at line 392 of file runner.h, definition at line 532 of file runner.cpp.
Reference static_children_suites_.
Public Operators
operator=()
| delete |
Deleted copy assignment operator to prevent copying.
Definition at line 379 of file runner.h.
Reference static_runner.
operator=()
| delete |
Deleted move assignment operator to prevent moving.
Definition at line 386 of file runner.h.
References micro_os_plus::micro_test_plus::runner::runner, static_runner, register_static_suite, static_suites_count and micro_os_plus::micro_test_plus::runner::suite.
Public Member Functions
abort()
|
Aborts test execution immediately.
- Parameters
-
sl The source location from which the abort is triggered.
- Returns
Nothing.
Prints the source location of the fatal error to stderr and then terminates the process via ::abort().
Declaration at line 210 of file runner.h, definition at line 431 of file runner.cpp.
References micro_os_plus::micro_test_plus::runner::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 micro_os_plus::micro_test_plus::runner::abort.
exit_code()
|
Returns 0 if all tests were successful, 1 otherwise.
- Parameters
None.
- Returns
Integer exit code representing the overall test result.
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.
Declaration at line 180 of file runner.h, definition at line 384 of file runner.cpp.
References micro_os_plus::micro_test_plus::runner::reporter_, micro_os_plus::micro_test_plus::runner::run_suites_, micro_os_plus::micro_test_plus::runner::timings_, micro_os_plus::micro_test_plus::runner::top_suite_ and micro_os_plus::micro_test_plus::detail::test_node::totals_.
initialise()
|
Initialises the test runner with command-line arguments.
- Parameters
-
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.
- Returns
Reference to the top-level test suite.
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.
Declaration at line 170 of file runner.h, definition at line 182 of file runner.cpp.
References micro_os_plus::micro_test_plus::utility::extract_file_name, micro_os_plus::micro_test_plus::runner::reporter_, micro_os_plus::micro_test_plus::runner::timings_, micro_os_plus::micro_test_plus::runner::top_suite_ and micro_os_plus::micro_test_plus::runner::top_suite_name_.
name()
| inline nodiscard noexcept |
Gets the node name.
- Parameters
None.
- Returns
A pointer to the null-terminated test node name.
Returns a pointer to the null-terminated name stored in name_.
Declaration at line 194 of file test.h, definition at line 91 of file test-inlines.h.
Reference micro_os_plus::micro_test_plus::detail::test_node::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, static_runner, static_runner, micro_os_plus::micro_test_plus::detail::test_node::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.
reporter()
| inline nodiscard noexcept |
Returns a reference to the test reporter.
- Parameters
None.
- Returns
Reference to the test reporter.
Returns a reference to the reporter object stored in the unique pointer.
Declaration at line 234 of file runner.h, definition at line 76 of file runner-inlines.h.
Reference micro_os_plus::micro_test_plus::runner::reporter_.
Referenced by micro_os_plus::micro_test_plus::runner::operator=.
static_suites_count()
| nodiscard noexcept |
Returns the total count of registered static test suites.
- Parameters
None.
- Returns
The total number of registered static test suites.
Returns the number of elements in static_children_suites_, or zero if the vector has not been allocated yet.
Declaration at line 413 of file runner.h, definition at line 554 of file runner.cpp.
Reference static_children_suites_.
Referenced by operator= and total_suites_count.
suite()
|
Adds a test suite to the runner.
- Template Parameters
-
Callable_T The type of a callable object.
Args_T The types of the callable arguments.
- Parameters
-
[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.
- Returns
Nothing.
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.
Declaration at line 198 of file runner.h, definition at line 112 of file runner-inlines.h.
References micro_os_plus::micro_test_plus::detail::test_node::name and micro_os_plus::micro_test_plus::runner::register_suite_.
Referenced by micro_os_plus::micro_test_plus::runner::operator=, operator=, register_static_suite and micro_os_plus::micro_test_plus::runner::register_suite_.
suites_count()
| nodiscard noexcept |
Returns the count of test suites.
- Parameters
None.
- Returns
The number of test suites, including the top one.
Returns the number of registered child suites plus one, accounting for the top suite.
Declaration at line 264 of file runner.h, definition at line 459 of file runner.cpp.
Reference micro_os_plus::micro_test_plus::runner::children_suites_.
Referenced by micro_os_plus::micro_test_plus::runner::operator=, run_suites_, micro_os_plus::micro_test_plus::runner::total_suites_count and total_suites_count.
timings()
| inline nodiscard noexcept |
Gets the timings for this runner (const overload).
- Parameters
None.
- Returns
A const reference to the timestamps instance.
Returns a const reference to the timestamps member.
Declaration at line 254 of file runner.h, definition at line 96 of file runner-inlines.h.
timings()
| inline nodiscard noexcept |
Gets the timings for this runner.
- Parameters
None.
- Returns
A reference to the timestamps instance.
Returns a reference to the timestamps member.
Declaration at line 244 of file runner.h, definition at line 86 of file runner-inlines.h.
Reference micro_os_plus::micro_test_plus::runner::timings_.
Referenced by micro_os_plus::micro_test_plus::reporter_human::end_session, micro_os_plus::micro_test_plus::reporter_tap::end_session and micro_os_plus::micro_test_plus::runner::operator=.
total_suites_count()
| nodiscard noexcept virtual |
Returns the total count of all test suites, including static and dynamic.
- Parameters
None.
- Returns
The total number of test suites.
Returns the combined count of dynamically registered suites (from the base runner) and statically registered suites.
Declaration at line 424 of file runner.h, definition at line 567 of file runner.cpp.
References static_suites_count and micro_os_plus::micro_test_plus::runner::suites_count.
totals()
| inline nodiscard noexcept |
Gets the totals for the test (const overload).
- Parameters
None.
- Returns
A const reference to the runner_totals instance.
Returns a const reference to the runner_totals member.
Declaration at line 215 of file test.h, definition at line 111 of file test-inlines.h.
Reference micro_os_plus::micro_test_plus::detail::test_node::totals_.
totals()
| inline nodiscard noexcept |
Gets the totals for the test.
- Parameters
None.
- Returns
A reference to the runner_totals instance.
Returns a reference to the runner_totals member.
Declaration at line 205 of file test.h, definition at line 101 of file test-inlines.h.
Reference micro_os_plus::micro_test_plus::detail::test_node::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 micro_os_plus::micro_test_plus::detail::test_node::operator=.
Protected Member Functions
register_suite_()
| protected |
Registers a test suite with the runner.
- Parameters
-
[in] suite Owning pointer to the test suite to register.
- Returns
Nothing.
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.
Declaration at line 284 of file runner.h, definition at line 307 of file runner.cpp.
References micro_os_plus::micro_test_plus::runner::children_suites_ and micro_os_plus::micro_test_plus::runner::suite.
Referenced by micro_os_plus::micro_test_plus::runner::operator= and micro_os_plus::micro_test_plus::runner::suite.
run_suites_()
| protected virtual |
Runs all child suites, including statically registered ones.
- Parameters
None.
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.
Declaration at line 434 of file runner.h, 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_.
Protected Member Attributes
children_suites_
| protected |
Owning collection of dynamically registered child suites.
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 micro_os_plus::micro_test_plus::runner::register_suite_, micro_os_plus::micro_test_plus::runner::run_suites_ and micro_os_plus::micro_test_plus::runner::suites_count.
name_
| protected |
The test node name.
Derived classes may access this member directly in addition to the public name() getter.
Definition at line 224 of file test.h.
Referenced by micro_os_plus::micro_test_plus::detail::test_node::test_node, 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::detail::test_node::~test_node and micro_os_plus::micro_test_plus::detail::test_node::name.
reporter_
| protected |
Pointer to the test reporter used for outputting test results.
Definition at line 306 of file runner.h.
Referenced by micro_os_plus::micro_test_plus::runner::exit_code, micro_os_plus::micro_test_plus::runner::initialise and micro_os_plus::micro_test_plus::runner::reporter.
static_children_suites_
| protected |
Pointer to the vector of registered static test suites.
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.
timings_
| protected |
Timings for this runner.
Definition at line 311 of file runner.h.
Referenced by micro_os_plus::micro_test_plus::runner::exit_code, micro_os_plus::micro_test_plus::runner::initialise, micro_os_plus::micro_test_plus::runner::timings and micro_os_plus::micro_test_plus::runner::timings.
top_suite_
| protected |
The implicit top-level suite; always present and executed first.
Definition at line 291 of file runner.h.
Referenced by micro_os_plus::micro_test_plus::runner::runner, micro_os_plus::micro_test_plus::runner::runner, micro_os_plus::micro_test_plus::runner::exit_code and micro_os_plus::micro_test_plus::runner::initialise.
top_suite_name_
| protected |
Owned storage for the implicit top-suite name.
Definition at line 316 of file runner.h.
Referenced by micro_os_plus::micro_test_plus::runner::initialise.
totals_
| protected |
Totals for the test node, including nested cases.
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_, run_suites_, micro_os_plus::micro_test_plus::detail::test_node::totals and micro_os_plus::micro_test_plus::detail::test_node::totals.
Public Static Functions
register_static_suite()
| static |
Registers a static test suite with the runner.
- Parameters
-
[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.
Declaration at line 403 of file runner.h, 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.
The documentation for this class was generated from the following files:
Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.