micro-test-plus 4.1.0
µ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 443 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
[in]nameThe test name, used in reports.
[in]runnerThe test runner managing this test.
[in]own_indexThe test index within the runner.
[in]callableThe callable invoked when the test runs.
[in]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 191 of file test-inlines.h.

195 {
196 // When there are no extra arguments the callable already has the
197 // signature void(Self_T&), so store it directly. Only use std::bind when
198 // additional arguments must be pre-bound, to avoid triggering a GCC ARM
199 // bug in
200 // __is_nothrow_invocable<_Bind<...>, Self_T&> (GCC 15.2.1).
201 if constexpr (sizeof...(arguments) == 0)
202 {
204 }
205 else
206 {
210 }
211
212#if defined(MICRO_OS_PLUS_TRACE) \
213 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
214#if defined(__GNUC__)
215#pragma GCC diagnostic push
216#if defined(__clang__)
217#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
218#endif
219#endif
221#if defined(__GNUC__)
222#pragma GCC diagnostic pop
223#endif
224#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
225 }
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:136
size_t own_index_
The test index, counting from 1.
Definition test.h:406
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:444
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:512
const char * name(void) const noexcept
Gets the node name.

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

◆ 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_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS, emits a trace message identifying the instance being destroyed.

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

235 {
236#if defined(MICRO_OS_PLUS_TRACE) \
237 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
238#if defined(__GNUC__)
239#pragma GCC diagnostic push
240#if defined(__clang__)
241#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
242#endif
243#endif
245#if defined(__GNUC__)
246#pragma GCC diagnostic pop
247#endif
248#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
249 }
const char * name_
The test node name.
Definition test.h:224

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

200 {
201 runner_.abort (sl);
202 }
class runner & runner_
Reference to the test runner that owns this object.
Definition test.h:401

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

217 {
218 // Transfer ownership into the vector.
219 children_subtests_.push_back (std::move (child_test));
220
221 // Run the child test case immediately.
222 class subtest& subtest = *children_subtests_.back ();
223 subtest.run ();
224
225 // This test executed one more subtest.
226#if defined(MICRO_OS_PLUS_TRACE) \
227 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
228#if defined(__GNUC__)
229#pragma GCC diagnostic push
230#if defined(__clang__)
231#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
232#endif
233#endif
234 trace::printf ("%s subtest '%s' executed one more subtest\n",
235 __PRETTY_FUNCTION__, name ());
236#if defined(__GNUC__)
237#pragma GCC diagnostic pop
238#endif
239#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
241 // Do not accumulate the totals from the child test into the current test
242 // totals, each subtest shows only its counters.
243
244#if defined(MICRO_OS_PLUS_TRACE) \
245 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
246#if defined(__GNUC__)
247#pragma GCC diagnostic push
248#if defined(__clang__)
249#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
250#endif
251#endif
252 trace::printf ("%s suite '%s' totals\n", __PRETTY_FUNCTION__,
253 suite.name ());
254#if defined(__GNUC__)
255#pragma GCC diagnostic pop
256#endif
257#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
258
259 // Accumulate the totals from the child test into the suite totals.
260 suite.totals () += subtest.totals ();
261 }
std::vector< std::unique_ptr< subtest > > children_subtests_
Owning collection of direct child subtests.
Definition test.h:427
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 165 of file test-inlines.h.

166 {
167 return children_subtests_.size ();
168 }

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

144 {
146 }
size_t current_subtest_index_
The subtest index, counting from 1.
Definition test.h:417

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

156 {
157 return ++current_subtest_index_;
158 }

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

124 {
125 return own_index_;
126 }

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

134 {
135 own_index_ = index;
136 }

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

188 {
189 return runner_.reporter ();
190 }

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

176 {
177 return runner_;
178 }

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

112 {
113 return totals_;
114 }
runner_totals totals_
Totals for the test node, including nested cases.
Definition test.h:229

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 512 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 427 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 417 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 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().

◆ own_index_

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

Definition at line 406 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 401 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: