|
micro-test-plus 4.1.0
µTest++ Testing Framework
|
CRTP base class factoring out callable storage, rule-of-five, and run() logic shared by subtest and suite. More...
#include <micro-os-plus/micro-test-plus.h>
Public Member Functions | |
| template<typename Callable_T, typename... Args_T> | |
| runnable (const char *name, class runner &runner, size_t own_index, Callable_T &&callable, Args_T &&... arguments) | |
| Class template constructor. | |
| runnable (const runnable &)=delete | |
| Deleted copy constructor to prevent copying. | |
| runnable (runnable &&)=delete | |
| Deleted move constructor to prevent moving. | |
| virtual | ~runnable () override |
| Virtual destructor. | |
| void | abort (const reflection::source_location &sl=reflection::source_location::current()) |
| Aborts test execution via the owning runner. | |
| size_t | children_subtests_count (void) const noexcept |
| Returns the number of direct child subtests owned by this node. | |
| size_t | current_subtest_index () const noexcept |
| Returns the index of the most recently created child subtest. | |
| size_t | increment_subtest_index () noexcept |
| Increments and returns the child subtest sequential index. | |
| const char * | name (void) const noexcept |
| Gets the node name. | |
| runnable & | operator= (const runnable &)=delete |
| Deleted copy assignment operator to prevent copying. | |
| runnable & | operator= (runnable &&)=delete |
| Deleted move assignment operator to prevent moving. | |
| size_t | own_index () const noexcept |
| Returns the positional index of this object within its parent. | |
| void | own_index (size_t index) noexcept |
| Sets the positional index of this object within its parent. | |
| class reporter & | reporter (void) const noexcept |
| Gets the test reporter associated with this test runnable. | |
| virtual void | run (void)=0 |
| Runs the test function by invoking the stored callable with the derived self instance. | |
| class runner & | runner (void) const noexcept |
| Gets the test runner associated with this test runnable. | |
| 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 | after_subtest_create_ (std::unique_ptr< subtest > child_test, suite &suite) |
| Registers a newly constructed child subtest and executes it immediately. | |
Protected Attributes | |
| std::function< void(Self_T &)> | callable_ |
| Callable storing the test body and any bound arguments. Invoked with a reference to the derived Self_T instance. | |
| std::vector< std::unique_ptr< subtest > > | children_subtests_ |
| Owning collection of direct child subtests. | |
| size_t | current_subtest_index_ = 0 |
| The subtest index, counting from 1. | |
| const char * | name_ |
| The test node name. | |
| size_t | own_index_ |
| The test index, counting from 1. | |
| class runner & | runner_ |
| Reference to the test runner that owns this object. | |
| runner_totals | totals_ |
| Totals for the test node, including nested cases. | |
| Self_T | The concrete derived class type (CRTP pattern). The stored callable receives a Self_T& reference when the test is executed. |
| micro_os_plus::micro_test_plus::detail::runnable< Self_T >::runnable | ( | const char * | name, |
| class runner & | runner, | ||
| size_t | own_index, | ||
| Callable_T && | callable, | ||
| Args_T &&... | arguments ) |
| Callable_T | The callable type. |
| Args_T | The additional argument types. |
| [in] | name | The test name, used in reports. |
| [in] | runner | The test runner managing this test. |
| [in] | own_index | The test index within the runner. |
| [in] | callable | The callable invoked when the test runs. |
| [in] | arguments | Additional arguments forwarded to the callable after the leading Self_T& reference. |
Binds the callable and its arguments into the stored callable_ function object. When run() is called, the stored function is invoked with a reference to the derived Self_T instance as its first argument, followed by the bound arguments.
Definition at line 191 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::test_node::name(), micro_os_plus::micro_test_plus::detail::runnable_base::own_index(), and micro_os_plus::micro_test_plus::detail::runnable_base::runner().
Referenced by runnable(), runnable(), operator=(), and operator=().
|
delete |
References runnable().
|
delete |
References runnable().
|
overridevirtual |
No-op in production builds. When tracing is enabled via MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS, emits a trace message identifying the instance being destroyed.
Definition at line 234 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::test_node::name_.
|
inherited |
| sl | The source location from which the abort is triggered. |
Delegates immediately to runner_.abort(), passing the supplied source location so that the error message identifies the call site before the process is terminated via ::abort().
Definition at line 199 of file test.cpp.
References runner_.
Referenced by operator=().
|
protectedinherited |
| child_test | Owning pointer to the newly created subtest. |
| suite | The parent suite to which execution results are reported. |
Transfers ownership of child_test into children_subtests_ and immediately invokes subtest::run() on the newly stored subtest. The parent's executed-subtest counter is then incremented. The child's check counters are intentionally not merged into the parent totals; each subtest reports only its own counters. The child's totals are, however, accumulated into suite so that the suite summary reflects all checks performed by its subtests.
Definition at line 215 of file test.cpp.
References children_subtests_, micro_os_plus::micro_test_plus::detail::runner_totals::increment_executed_subtests(), micro_os_plus::micro_test_plus::detail::test_node::name(), micro_os_plus::micro_test_plus::subtest::run(), and micro_os_plus::micro_test_plus::detail::test_node::totals().
Referenced by operator=().
|
inlinenodiscardnoexceptinherited |
Returns the number of child subtests owned by this node.
Definition at line 165 of file test-inlines.h.
References children_subtests_.
Referenced by micro_os_plus::micro_test_plus::reporter_tap::end_subtest(), micro_os_plus::micro_test_plus::reporter_tap::end_suite(), and operator=().
|
inlinenodiscardnoexceptinherited |
Returns the sequential index of the most recently created child subtest.
Definition at line 143 of file test-inlines.h.
References current_subtest_index_.
Referenced by operator=(), micro_os_plus::micro_test_plus::reporter_tap::output_fail_prefix_(), and micro_os_plus::micro_test_plus::reporter_tap::output_pass_prefix_().
|
inlinenoexceptinherited |
Each call to test() invokes this method before constructing the new subtest, so the index values form a strictly increasing, one-based sequence.
Definition at line 155 of file test-inlines.h.
References current_subtest_index_.
Referenced by operator=().
|
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 runnable().
|
delete |
References runnable().
|
inlinenodiscardnoexceptinherited |
Returns the one-based positional index of this object within its parent.
Definition at line 123 of file test-inlines.h.
References own_index_.
Referenced by micro_os_plus::micro_test_plus::detail::runnable< Self_T >::runnable(), runnable_base(), micro_os_plus::micro_test_plus::reporter_tap::end_subtest(), micro_os_plus::micro_test_plus::reporter_tap::end_suite(), and operator=().
|
inlinenoexceptinherited |
| index | The new index value. |
Sets the positional index of this object within its parent.
Definition at line 133 of file test-inlines.h.
References own_index_.
|
nodiscardnoexceptinherited |
Delegates immediately to runner_.reporter(), returning the reporter associated with the owning runner instance.
Definition at line 187 of file test.cpp.
References runner_.
Referenced by operator=().
|
pure virtual |
Implemented in micro_os_plus::micro_test_plus::static_suite, micro_os_plus::micro_test_plus::subtest, and micro_os_plus::micro_test_plus::suite.
|
inlinenodiscardnoexceptinherited |
Returns a reference to the owning test runner.
Definition at line 175 of file test-inlines.h.
References runner_.
Referenced by micro_os_plus::micro_test_plus::detail::runnable< Self_T >::runnable(), runnable_base(), and operator=().
|
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 |
|
protectedinherited |
Each call to test() appends a new subtest to this vector and runs it immediately. The vector retains ownership for the lifetime of the parent runnable.
Definition at line 427 of file test.h.
Referenced by after_subtest_create_(), and children_subtests_count().
|
protectedinherited |
This index is used for reporting and tracking the execution order of subtests within a suite, especially when nested subtests are involved. It is incremented for each subtest created, allowing for clear identification of subtests in reports and diagnostics.
Definition at line 417 of file test.h.
Referenced by current_subtest_index(), and increment_subtest_index().
|
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 406 of file test.h.
Referenced by runnable_base(), own_index(), and own_index().
|
protectedinherited |
Definition at line 401 of file test.h.
Referenced by runnable_base(), abort(), reporter(), and runner().
|
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().