micro-test-plus 5.0.1
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::detail::runnable< Self_T > Class Template Referenceabstract

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"

Inheritance diagram for micro_os_plus::micro_test_plus::detail::runnable< Self_T >:

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.
runnableoperator= (const runnable &)=delete
 Deleted copy assignment operator to prevent copying.
runnableoperator= (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_totalstotals () const noexcept
 Gets the totals for the test (const overload).
runner_totalstotals () 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 runnerrunner_
 Reference to the test runner that owns this object.
runner_totals totals_
 Totals for the test node, including nested cases.

Detailed Description

template<typename Self_T>
class micro_os_plus::micro_test_plus::detail::runnable< Self_T >
Template Parameters
Self_TThe concrete derived class type (CRTP pattern). The stored callable receives a Self_T& reference when the test is executed.

Definition at line 452 of file test.h.

Constructor & Destructor Documentation

◆ runnable() [1/3]

template<typename Self_T>
template<typename Callable_T, typename... Args_T>
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 )
Template Parameters
Callable_TThe callable type.
Args_TThe additional argument types.
Parameters
nameThe test name, used in reports.
runnerThe test runner managing this test.
own_indexThe test index within the runner.
callableThe callable invoked when the test runs.
argumentsAdditional 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 194 of file test-inlines.h.

198 {
199 // When there are no extra arguments the callable already has the
200 // signature void(Self_T&), so store it directly. Only use std::bind when
201 // additional arguments must be pre-bound, to avoid triggering a GCC ARM
202 // bug in
203 // __is_nothrow_invocable<_Bind<...>, Self_T&> (GCC 15.2.1).
204 if constexpr (sizeof...(arguments) == 0)
205 {
207 }
208 else
209 {
213 }
214
215#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
217#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
218 }
class runner & runner(void) const noexcept
Gets the test runner associated with this test runnable.
runnable_base(const char *name, runner &runner, size_t own_index)
Constructs a runnable_base with a name, runner, and index.
Definition test.cpp:118
size_t own_index_
The test index, counting from 1.
Definition test.h:415
size_t own_index() const noexcept
Returns the positional index of this object within its parent.
CRTP base class factoring out callable storage, rule-of-five, and run() logic shared by subtest and s...
Definition test.h:453
std::function< void(Self_T &)> callable_
Callable storing the test body and any bound arguments. Invoked with a reference to the derived Self_...
Definition test.h:521
const char * name(void) const noexcept
Gets the node name.

References micro_os_plus::micro_test_plus::detail::runnable_base::runnable_base(), 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=().

◆ runnable() [2/3]

template<typename Self_T>
micro_os_plus::micro_test_plus::detail::runnable< Self_T >::runnable ( const runnable< Self_T > & )
delete

References runnable().

◆ runnable() [3/3]

template<typename Self_T>
micro_os_plus::micro_test_plus::detail::runnable< Self_T >::runnable ( runnable< Self_T > && )
delete

References runnable().

◆ ~runnable()

template<typename Self_T>
micro_os_plus::micro_test_plus::detail::runnable< Self_T >::~runnable ( )
overridevirtual

No-op in production builds. When tracing is enabled via MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED, emits a trace message identifying the instance being destroyed.

Definition at line 227 of file test-inlines.h.

228 {
229#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
231#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
232 }
const char * name_
The test node name.
Definition test.h:233

References micro_os_plus::micro_test_plus::detail::test_node::name_.

Member Function Documentation

◆ abort()

void micro_os_plus::micro_test_plus::detail::runnable_base::abort ( const reflection::source_location & sl = reflection::source_location::current ())
inherited
Parameters
slThe source location from which the abort is triggered.
Returns
Does not return.

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 161 of file test.cpp.

162 {
163 runner_.abort (sl);
164 }
class runner & runner_
Reference to the test runner that owns this object.
Definition test.h:410

References runner_.

Referenced by operator=().

◆ after_subtest_create_()

void micro_os_plus::micro_test_plus::detail::runnable_base::after_subtest_create_ ( std::unique_ptr< subtest > child_test,
suite & suite )
protectedinherited
Parameters
child_testOwning pointer to the newly created subtest.
suiteThe parent suite to which execution results are reported.
Returns
Nothing.

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 177 of file test.cpp.

179 {
180 // Transfer ownership into the vector.
181 children_subtests_.push_back (std::move (child_test));
182
183 // Run the child test case immediately.
184 class subtest& subtest = *children_subtests_.back ();
185 subtest.run ();
186
187 // This test executed one more subtest.
188#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
189 trace::printf ("%s subtest '%s' executed one more subtest\n",
190 __PRETTY_FUNCTION__, name ());
191#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
193 // Do not accumulate the totals from the child test into the current test
194 // totals, each subtest shows only its counters.
195
196#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
197 trace::printf ("%s suite '%s' totals\n", __PRETTY_FUNCTION__,
198 suite.name ());
199#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
200
201 // Accumulate the totals from the child test into the suite totals.
202 suite.totals () += subtest.totals ();
203 }
std::vector< std::unique_ptr< subtest > > children_subtests_
Owning collection of direct child subtests.
Definition test.h:436
void increment_executed_subtests(size_t count=1) noexcept
Increments the executed-subtests counter.
runner_totals & totals() noexcept
Gets the totals for the test.

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=().

◆ children_subtests_count()

size_t micro_os_plus::micro_test_plus::detail::runnable_base::children_subtests_count ( void ) const
inlinenodiscardnoexceptinherited
Parameters
None.
Returns
The number of child subtests.

Returns the number of child subtests owned by this node.

Definition at line 168 of file test-inlines.h.

169 {
170 return children_subtests_.size ();
171 }

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=().

◆ current_subtest_index()

size_t micro_os_plus::micro_test_plus::detail::runnable_base::current_subtest_index ( ) const
inlinenodiscardnoexceptinherited
Parameters
None.
Returns
The current child subtest sequential index.

Returns the sequential index of the most recently created child subtest.

Definition at line 146 of file test-inlines.h.

147 {
149 }
size_t current_subtest_index_
The subtest index, counting from 1.
Definition test.h:426

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_().

◆ increment_subtest_index()

size_t micro_os_plus::micro_test_plus::detail::runnable_base::increment_subtest_index ( )
inlinenoexceptinherited
Parameters
None.
Returns
The new index value after incrementing.

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 158 of file test-inlines.h.

159 {
160 return ++current_subtest_index_;
161 }

References current_subtest_index_.

Referenced by operator=().

◆ name()

◆ operator=() [1/2]

template<typename Self_T>
runnable & micro_os_plus::micro_test_plus::detail::runnable< Self_T >::operator= ( const runnable< Self_T > & )
delete

References runnable().

◆ operator=() [2/2]

template<typename Self_T>
runnable & micro_os_plus::micro_test_plus::detail::runnable< Self_T >::operator= ( runnable< Self_T > && )
delete

References runnable().

◆ own_index() [1/2]

size_t micro_os_plus::micro_test_plus::detail::runnable_base::own_index ( ) const
inlinenodiscardnoexceptinherited
Parameters
None.
Returns
The one-based own index.

Returns the one-based positional index of this object within its parent.

Definition at line 126 of file test-inlines.h.

127 {
128 return own_index_;
129 }

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=().

◆ own_index() [2/2]

void micro_os_plus::micro_test_plus::detail::runnable_base::own_index ( size_t index)
inlinenoexceptinherited
Note
This overload follows the same-name getter/setter pattern used throughout the framework: the getter is the const overload and the setter is the non-const single-argument overload.
Parameters
indexThe new index value.
Returns
Nothing.

Sets the positional index of this object within its parent.

Definition at line 136 of file test-inlines.h.

137 {
138 own_index_ = index;
139 }

References own_index_.

◆ reporter()

reporter & micro_os_plus::micro_test_plus::detail::runnable_base::reporter ( void ) const
nodiscardnoexceptinherited
Parameters
None.
Returns
A reference to the test reporter.

Delegates immediately to runner_.reporter(), returning the reporter associated with the owning runner instance.

Definition at line 149 of file test.cpp.

150 {
151 return runner_.reporter ();
152 }

References runner_.

Referenced by operator=().

◆ run()

template<typename Self_T>
virtual void micro_os_plus::micro_test_plus::detail::runnable< Self_T >::run ( void )
pure virtual

◆ runner()

class runner & micro_os_plus::micro_test_plus::detail::runnable_base::runner ( void ) const
inlinenodiscardnoexceptinherited
Parameters
None.
Returns
A reference to the test runner.

Returns a reference to the owning test runner.

Definition at line 178 of file test-inlines.h.

179 {
180 return runner_;
181 }

References runner_.

Referenced by micro_os_plus::micro_test_plus::detail::runnable< Self_T >::runnable(), runnable_base(), and operator=().

◆ totals() [1/2]

const runner_totals & micro_os_plus::micro_test_plus::detail::test_node::totals ( ) const
inlinenodiscardnoexceptinherited
Parameters
None.
Returns
A const reference to the runner_totals instance.

Returns a const reference to the runner_totals member.

Definition at line 114 of file test-inlines.h.

115 {
116 return totals_;
117 }
runner_totals totals_
Totals for the test node, including nested cases.
Definition test.h:238

References totals_.

◆ totals() [2/2]

Member Data Documentation

◆ callable_

template<typename Self_T>
std::function<void (Self_T&)> micro_os_plus::micro_test_plus::detail::runnable< Self_T >::callable_
protected

Definition at line 521 of file test.h.

◆ children_subtests_

std::vector<std::unique_ptr<subtest> > micro_os_plus::micro_test_plus::detail::runnable_base::children_subtests_
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 436 of file test.h.

Referenced by after_subtest_create_(), and children_subtests_count().

◆ current_subtest_index_

size_t micro_os_plus::micro_test_plus::detail::runnable_base::current_subtest_index_ = 0
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 426 of file test.h.

Referenced by current_subtest_index(), and increment_subtest_index().

◆ name_

const char* micro_os_plus::micro_test_plus::detail::test_node::name_
protectedinherited
Note
Derived classes may access this member directly in addition to the public name() getter.

Definition at line 233 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().

◆ own_index_

size_t micro_os_plus::micro_test_plus::detail::runnable_base::own_index_
protectedinherited

Definition at line 415 of file test.h.

Referenced by runnable_base(), own_index(), and own_index().

◆ runner_

class runner& micro_os_plus::micro_test_plus::detail::runnable_base::runner_
protectedinherited

Definition at line 410 of file test.h.

Referenced by runnable_base(), abort(), reporter(), and runner().

◆ totals_

runner_totals micro_os_plus::micro_test_plus::detail::test_node::totals_
protectedinherited

The documentation for this class was generated from the following files: