micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::detail::runnable_base Class Reference

Non-template base for all runnable objects (suites and subtests). More...

#include <micro-os-plus/micro-test-plus.h>

Inheritance diagram for micro_os_plus::micro_test_plus::detail::runnable_base:

Public Member Functions

 runnable_base (const char *name, runner &runner, size_t own_index)
 Constructs a runnable_base with a name, runner, and index.
 runnable_base (const runnable_base &)=delete
 Deleted copy constructor to prevent copying.
 runnable_base (runnable_base &&)=delete
 Deleted move constructor to prevent moving.
virtual ~runnable_base () 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_baseoperator= (const runnable_base &)=delete
 Deleted copy assignment operator to prevent copying.
runnable_baseoperator= (runnable_base &&)=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.
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::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

runnable_base extends test_node with the state that is shared by every runnable object but does not depend on the CRTP self-type:

  • a reference to the owning runner,
  • the object's own index within its parent container,
  • a sequential subtest index used when creating nested subtests, and
  • an owning vector of child subtest instances.

Concrete runnable classes (suite, subtest) derive from runnable<Self_T> which in turn derives from runnable_base.

The class is non-copyable and non-movable to preserve unique ownership and consistent state throughout the test session.

Definition at line 253 of file test.h.

Constructor & Destructor Documentation

◆ runnable_base() [1/3]

micro_os_plus::micro_test_plus::detail::runnable_base::runnable_base ( const char * name,
runner & runner,
size_t own_index )
Parameters
nameThe name used in reports.
runnerThe test runner managing this object.
own_indexThe positional index of this object within its parent.

The constructor initialises a new instance of the runnable_base class with the specified name. It sets up the internal state required for managing test cases within the suite. If tracing is enabled, the function signature is output for diagnostic purposes. The default test suite does not require explicit registration, ensuring seamless integration within the µTest++ framework and supporting organised test management across all files and folders.

Definition at line 136 of file test.cpp.

139 {
140#if defined(MICRO_OS_PLUS_TRACE) \
141 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
142#if defined(__GNUC__)
143#pragma GCC diagnostic push
144#if defined(__clang__)
145#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
146#endif
147#endif
148 trace::printf ("%s '%s' %zu\n", __PRETTY_FUNCTION__, name, own_index_);
149#if defined(__GNUC__)
150#pragma GCC diagnostic pop
151#endif
152#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
153 }
class runner & runner(void) const noexcept
Gets the test runner associated with this test runnable.
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.
class runner & runner_
Reference to the test runner that owns this object.
Definition test.h:401
const char * name(void) const noexcept
Gets the node name.
test_node(const char *name)
Constructs a test node.
Definition test.cpp:84

References micro_os_plus::micro_test_plus::detail::test_node::test_node(), micro_os_plus::micro_test_plus::detail::test_node::name(), own_index(), own_index_, runner(), and runner_.

Referenced by runnable_base(), runnable_base(), micro_os_plus::micro_test_plus::top_suite::name(), operator=(), and operator=().

◆ runnable_base() [2/3]

micro_os_plus::micro_test_plus::detail::runnable_base::runnable_base ( const runnable_base & )
delete

References runnable_base().

◆ runnable_base() [3/3]

micro_os_plus::micro_test_plus::detail::runnable_base::runnable_base ( runnable_base && )
delete

References runnable_base().

◆ ~runnable_base()

micro_os_plus::micro_test_plus::detail::runnable_base::~runnable_base ( )
overridevirtual

The destructor releases any resources associated with the runnable_base instance. It ensures that the test suite is properly cleaned up after execution, supporting robust and reliable test management across all files and folders within the µTest++ framework.

Definition at line 162 of file test.cpp.

163 {
164#if defined(MICRO_OS_PLUS_TRACE) \
165 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
166#if defined(__GNUC__)
167#pragma GCC diagnostic push
168#if defined(__clang__)
169#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
170#endif
171#endif
172 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name_);
173#if defined(__GNUC__)
174#pragma GCC diagnostic pop
175#endif
176#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS
177
178 // children_subtests_ holds unique_ptrs; destroyed automatically.
179 }
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 ())
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 }

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 )
protected
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
inlinenodiscardnoexcept
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
inlinenodiscardnoexcept
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 ( )
inlinenoexcept
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]

runnable_base & micro_os_plus::micro_test_plus::detail::runnable_base::operator= ( const runnable_base & )
delete

References runnable_base().

◆ operator=() [2/2]

runnable_base & micro_os_plus::micro_test_plus::detail::runnable_base::operator= ( runnable_base && )
delete

◆ own_index() [1/2]

size_t micro_os_plus::micro_test_plus::detail::runnable_base::own_index ( ) const
inlinenodiscardnoexcept
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)
inlinenoexcept
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
nodiscardnoexcept
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=().

◆ runner()

class runner & micro_os_plus::micro_test_plus::detail::runnable_base::runner ( void ) const
inlinenodiscardnoexcept
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

◆ children_subtests_

std::vector<std::unique_ptr<subtest> > micro_os_plus::micro_test_plus::detail::runnable_base::children_subtests_
protected

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
protected

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_
protected

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_
protected

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: