micro-test-plus 4.1.1
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::static_runner Class Referencefinal

A runner variant that also manages statically-registered test suites. More...

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

Inheritance diagram for micro_os_plus::micro_test_plus::static_runner:

Public Member Functions

 static_runner (const char *top_suite_name)
 Constructs the static runner with a top-suite name.
 static_runner (const static_runner &)=delete
 Deleted copy constructor to prevent copying.
 static_runner (static_runner &&)=delete
 Deleted move constructor to prevent moving.
 static_runner (void)
 Constructor for the runner class.
virtual ~static_runner () override
 Destructor for the static_runner class.
void abort (const reflection::source_location &sl=reflection::source_location::current())
 Aborts test execution immediately.
int exit_code (void)
 Returns 0 if all tests were successful, 1 otherwise.
class suiteinitialise (int argc, char *argv[], const char *top_suite_name="")
 Initialises the test runner with command-line arguments.
const char * name (void) const noexcept
 Gets the node name.
static_runneroperator= (const static_runner &)=delete
 Deleted copy assignment operator to prevent copying.
static_runneroperator= (static_runner &&)=delete
 Deleted move assignment operator to prevent moving.
class reporter & reporter (void) const noexcept
 Returns a reference to the test reporter.
size_t static_suites_count (void) const noexcept
 Returns the total count of registered static test suites.
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.
size_t suites_count (void) const noexcept
 Returns the count of test suites.
const detail::timestampstimings () const noexcept
 Gets the timings for this runner (const overload).
detail::timestampstimings () noexcept
 Gets the timings for this runner.
virtual size_t total_suites_count (void) const noexcept final override
 Returns the total count of all test suites, including static and dynamic.
const runner_totals & totals () const noexcept
 Gets the totals for the test (const overload).
runner_totals & totals () noexcept
 Gets the totals for the test.

Static Public Member Functions

static void register_static_suite (static_runner &runner, static_suite &suite)
 Registers a static test suite with the runner.

Protected Member Functions

void register_suite_ (std::unique_ptr< class suite > suite)
 Registers a test suite with the runner.
void run_suites_ (void) override
 Runs all child suites, including statically registered ones.

Protected Attributes

std::vector< std::unique_ptr< class suite > > children_suites_
 Owning collection of dynamically registered child suites.
const char * name_
 The test node name.
std::unique_ptr< class reporterreporter_
 Pointer to the test reporter used for outputting test results.
std::vector< static_suite * > * static_children_suites_
 Pointer to the vector of registered static test suites.
detail::timestamps timings_
 Timings for this runner.
class top_suite top_suite_
 The implicit top-level suite; always present and executed first.
std::string top_suite_name_
 Owned storage for the implicit top-suite name.
runner_totals totals_
 Totals for the test node, including nested cases.

Detailed Description

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.

Constructor & Destructor Documentation

◆ static_runner() [1/4]

micro_os_plus::micro_test_plus::static_runner::static_runner ( void )
Parameters
None.

Delegates construction to the runner base class. If tracing is enabled, the function signature and suite name are output for diagnostic purposes.

Definition at line 492 of file runner.cpp.

492 : runner{}
493 {
494#if defined(MICRO_OS_PLUS_TRACE) \
495 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
496#if defined(__GNUC__)
497#pragma GCC diagnostic push
498#if defined(__clang__)
499#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
500#endif
501#endif
502 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
503#if defined(__GNUC__)
504#pragma GCC diagnostic pop
505#endif
506#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
507 }
const char * name(void) const noexcept
Gets the node name.
runner(void)
Constructor for the runner class.
Definition runner.cpp:116

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

◆ static_runner() [2/4]

micro_os_plus::micro_test_plus::static_runner::static_runner ( const char * top_suite_name)
Parameters
top_suite_nameThe 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.

Definition at line 515 of file runner.cpp.

516 : runner{ top_suite_name }
517 {
518#if defined(MICRO_OS_PLUS_TRACE) \
519 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
520#if defined(__GNUC__)
521#pragma GCC diagnostic push
522#if defined(__clang__)
523#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
524#endif
525#endif
526 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
527#if defined(__GNUC__)
528#pragma GCC diagnostic pop
529#endif
530#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
531 }

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

◆ static_runner() [3/4]

micro_os_plus::micro_test_plus::static_runner::static_runner ( const static_runner & )
delete

References static_runner().

◆ static_runner() [4/4]

micro_os_plus::micro_test_plus::static_runner::static_runner ( static_runner && )
delete

References static_runner().

◆ ~static_runner()

micro_os_plus::micro_test_plus::static_runner::~static_runner ( )
overridevirtual

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.

Definition at line 541 of file runner.cpp.

542 {
543#if defined(MICRO_OS_PLUS_TRACE) \
544 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
545 trace::printf ("%s\n", __PRETTY_FUNCTION__);
546#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED
547
548 if (static_children_suites_ != nullptr)
549 {
550 // The tests are static, so we do not delete them, but we need to
551 // delete the array of pointers.
553 static_children_suites_ = nullptr;
554 }
555 }
std::vector< static_suite * > * static_children_suites_
Pointer to the vector of registered static test suites.
Definition runner.h:450

References static_children_suites_.

Member Function Documentation

◆ abort()

void micro_os_plus::micro_test_plus::runner::abort ( const reflection::source_location & sl = reflection::source_location::current ())
inherited
Parameters
slThe 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().

Definition at line 440 of file runner.cpp.

441 {
442#if defined(MICRO_OS_PLUS_TRACE) \
443 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
444 trace::printf ("%s\n", __PRETTY_FUNCTION__);
445#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
446
447#if defined(__GNUC__)
448#pragma GCC diagnostic push
449#if defined(__clang__)
450#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
451#endif
452#endif
453 fprintf (stderr, "\nerror: test execution aborted at %s:%u\n",
454 reflection::short_name (sl.file_name ()), sl.line ());
455#if defined(__GNUC__)
456#pragma GCC diagnostic pop
457#endif
458
459 ::abort ();
460 }
void abort(const reflection::source_location &sl=reflection::source_location::current())
Aborts test execution immediately.
Definition runner.cpp:440
const char * short_name(const char *name) noexcept
Extract a short type or function name from a fully qualified name.

References 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 abort().

◆ exit_code()

int micro_os_plus::micro_test_plus::runner::exit_code ( void )
inherited
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.

Definition at line 393 of file runner.cpp.

394 {
395#if defined(MICRO_OS_PLUS_TRACE) \
396 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
397 trace::printf ("%s\n", __PRETTY_FUNCTION__);
398#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
399
400 if (reporter_ == nullptr)
401 {
402 fprintf (stderr, "error: test runner not initialised\n");
403 return 1;
404 }
405
406 top_suite_.timings ().timestamp_end ();
407 reporter_->end_suite (top_suite_);
408 totals_ += top_suite_.totals ();
409
410 run_suites_ ();
411
412 timings_.timestamp_end ();
413 reporter_->end_session (*this);
414
415 const int result = totals_.was_successful () ? 0 : 1;
416
417#if defined(MICRO_OS_PLUS_TRACE) \
418 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
419#if defined(__GNUC__)
420#pragma GCC diagnostic push
421#if defined(__clang__)
422#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
423#endif
424#endif
425 trace::printf ("%s -> %d\n", __PRETTY_FUNCTION__, result);
426#if defined(__GNUC__)
427#pragma GCC diagnostic pop
428#endif
429#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
430
431 return result;
432 }
runner_totals totals_
Totals for the test node, including nested cases.
Definition test.h:229
detail::timestamps timings_
Timings for this runner.
Definition runner.h:311
class top_suite top_suite_
The implicit top-level suite; always present and executed first.
Definition runner.h:291
std::unique_ptr< class reporter > reporter_
Pointer to the test reporter used for outputting test results.
Definition runner.h:306
virtual void run_suites_(void)
Runs all registered test suites.
Definition runner.cpp:346

References reporter_, run_suites_(), timings_, top_suite_, and micro_os_plus::micro_test_plus::detail::test_node::totals_.

◆ initialise()

suite & micro_os_plus::micro_test_plus::runner::initialise ( int argc,
char * argv[],
const char * top_suite_name = "" )
inherited
Parameters
argcThe argument count from main().
argvThe argument vector from main().
top_suite_nameThe 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.

Definition at line 191 of file runner.cpp.

192 {
193#if defined(MICRO_OS_PLUS_TRACE) \
194 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
195 trace::printf ("%s\n", __PRETTY_FUNCTION__);
196#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
197
198#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
199#if defined(MICRO_OS_PLUS_DEBUG)
200 trace::printf ("argv[");
201 for (int i = 0; i < argc; ++i)
202 {
203 if (i > 0)
204 {
205 trace::printf (", ");
206 }
207 trace::printf ("'%s'", argv[i]);
208 }
209 trace::puts ("]");
210#endif // defined(MICRO_OS_PLUS_DEBUG)
211#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
212
213 if (strlen (top_suite_name) > 0)
214 {
215 // If provided by this call, use it, possibly override the
216 // deprecated constructor.
217 top_suite_name_ = top_suite_name;
218 top_suite_.name (top_suite_name_.c_str ());
219 }
220 else if (strlen (top_suite_.name ()) == 0)
221 {
222 // If not provided by the constructor or by this call, try to extract a
223 // name from argv[0], which is commonly the executable name. If that
224 // fails, use a default name.
225 if (argc > 0 && argv != nullptr && argv[0] != nullptr)
226 {
227 std::string_view top_suite_name_view{ utility::extract_file_name (
228 argv[0]) };
229
230 const auto dot_pos = top_suite_name_view.rfind ('.');
231 if (dot_pos != std::string_view::npos)
232 {
233 top_suite_name_view = top_suite_name_view.substr (0, dot_pos);
234 }
235
236 top_suite_name_ = top_suite_name_view;
237 }
238 else
239 {
240 top_suite_name_ = "default suite";
241 }
242 top_suite_.name (top_suite_name_.c_str ());
243 }
244
245 std::vector<std::string_view> argvs (argv, argv + argc);
246
247 std::string_view reporter_name{ "tap" };
248 static constexpr std::string_view reporter_prefix{ "--reporter=" };
249 for (size_t i = 0; i < argvs.size (); ++i)
250 {
251 if (argvs[i].starts_with (reporter_prefix))
252 {
253 reporter_name = argvs[i].substr (reporter_prefix.size ());
254 }
255 else if (argvs[i]
256 == reporter_prefix.substr (0, reporter_prefix.size () - 1))
257 {
258 if (i + 1 < argvs.size ())
259 {
260 reporter_name = argvs[++i];
261 }
262 else
263 {
264 fprintf (stderr, "error: --reporter option requires a "
265 "reporter name argument\n");
266 exit (1);
267 }
268 }
269 }
270
271 // Initialise and configure the reporter.
272 if (reporter_name == "human")
273 {
274 reporter_ = std::make_unique<reporter_human> (
275 std::make_unique<std::vector<std::string_view>> (
276 std::move (argvs)));
277 }
278 else if (reporter_name == "tap")
279 {
280 reporter_ = std::make_unique<reporter_tap> (
281 std::make_unique<std::vector<std::string_view>> (
282 std::move (argvs)));
283 }
284 else
285 {
286 fprintf (stderr, "error: unknown reporter '%.*s'\n",
287 static_cast<int> (reporter_name.size ()),
288 reporter_name.data ());
289 exit (1);
290 }
291
292 // ------------------------------------------------------------------------
293
294 timings_.timestamp_begin ();
295 reporter_->begin_session (*this);
296
297 top_suite_.timings ().timestamp_begin ();
298 reporter_->begin_suite (top_suite_);
299
300 return top_suite_;
301 }
std::string top_suite_name_
Owned storage for the implicit top-suite name.
Definition runner.h:316
const char * extract_file_name(const char *path) noexcept
Extracts the file name component from a full path.
Definition utility.cpp:93

References micro_os_plus::micro_test_plus::utility::extract_file_name(), reporter_, timings_, top_suite_, and top_suite_name_.

◆ name()

const char * micro_os_plus::micro_test_plus::detail::test_node::name ( void ) const
inlinenodiscardnoexceptinherited

◆ operator=() [1/2]

static_runner & micro_os_plus::micro_test_plus::static_runner::operator= ( const static_runner & )
delete

References static_runner().

◆ operator=() [2/2]

◆ register_static_suite()

void micro_os_plus::micro_test_plus::static_runner::register_static_suite ( static_runner & runner,
static_suite & suite )
static
Parameters
[in]runnerThe static runner instance.
[in]suiteThe 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.

Definition at line 646 of file runner.cpp.

648 {
649#if defined(MICRO_OS_PLUS_TRACE) \
650 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
651#if defined(__GNUC__)
652#pragma GCC diagnostic push
653#if defined(__clang__)
654#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
655#endif
656#endif
657 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite.name ());
658#if defined(__GNUC__)
659#pragma GCC diagnostic pop
660#endif
661#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
662
663 if (runner.static_children_suites_ == nullptr)
664 {
665#if defined(MICRO_OS_PLUS_TRACE) \
666 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
667 trace::printf ("%s new static_children_suites_ array\n",
668 __PRETTY_FUNCTION__);
669#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
670 runner.static_children_suites_ = new std::vector<static_suite*>;
671 }
672 runner.static_children_suites_->push_back (&suite);
673 }
void suite(const char *name, Callable_T &&callable, Args_T &&... arguments)
Adds a test suite to the runner.

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

◆ register_suite_()

void micro_os_plus::micro_test_plus::runner::register_suite_ ( std::unique_ptr< class suite > suite)
protectedinherited
Parameters
[in]suiteOwning 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.

Definition at line 316 of file runner.cpp.

317 {
318#if defined(MICRO_OS_PLUS_TRACE) \
319 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
320#if defined(__GNUC__)
321#pragma GCC diagnostic push
322#if defined(__clang__)
323#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
324#endif
325#endif
326 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite->name ());
327#if defined(__GNUC__)
328#pragma GCC diagnostic pop
329#endif
330#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
331
332 children_suites_.push_back (std::move (suite));
333 }
std::vector< std::unique_ptr< class suite > > children_suites_
Owning collection of dynamically registered child suites.
Definition runner.h:301

References children_suites_, and suite().

Referenced by operator=(), and suite().

◆ reporter()

class reporter & micro_os_plus::micro_test_plus::runner::reporter ( void ) const
inlinenodiscardnoexceptinherited
Parameters
None.
Returns
Reference to the test reporter.

Returns a reference to the reporter object stored in the unique pointer.

Definition at line 77 of file runner-inlines.h.

78 {
79 return *reporter_;
80 }

References reporter_.

Referenced by operator=().

◆ run_suites_()

void micro_os_plus::micro_test_plus::static_runner::run_suites_ ( void )
overrideprotectedvirtual
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.

Reimplemented from micro_os_plus::micro_test_plus::runner.

Definition at line 591 of file runner.cpp.

592 {
593#if defined(MICRO_OS_PLUS_TRACE) \
594 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
595 trace::printf ("%s\n", __PRETTY_FUNCTION__);
596#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
597
599
600 if (static_children_suites_ != nullptr)
601 {
602 // Use selection sort with std::swap on raw pointers (returns void)
603 // to avoid std::sort triggering -Waggregate-return via
604 // std::move_backward returning a class-type iterator.
605 const size_t n = static_children_suites_->size ();
606 auto& suites = *static_children_suites_;
607 for (size_t i = 0; i < n; ++i)
608 {
609 size_t min_idx = i;
610 for (size_t j = i + 1; j < n; ++j)
611 {
612 if (std::string_view{ suites[j]->name () }
613 < std::string_view{ suites[min_idx]->name () })
614 min_idx = j;
615 }
616 if (min_idx != i)
617 std::swap (suites[i], suites[min_idx]);
618 }
619
620 for (size_t i = 0; i < n; ++i)
621 {
622 auto* suite_ptr = suites[i];
623
624 suite_ptr->own_index (i + 1 + suites_count ());
625
626 // Run the child suite immediately.
627 suite_ptr->run ();
628
629 // Accumulate the totals from the static suite into the runner
630 // totals.
631 // DO NOT increment executed_subtests here.
632 totals_ += suite_ptr->totals ();
633 }
634 }
635 }
size_t suites_count(void) const noexcept
Returns the count of test suites.
Definition runner.cpp:468

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

◆ static_suites_count()

size_t micro_os_plus::micro_test_plus::static_runner::static_suites_count ( void ) const
nodiscardnoexcept
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.

Definition at line 563 of file runner.cpp.

564 {
565 return static_children_suites_ != nullptr
566 ? static_children_suites_->size ()
567 : 0;
568 }

References static_children_suites_.

Referenced by operator=(), and total_suites_count().

◆ suite()

template<typename Callable_T, typename... Args_T>
void micro_os_plus::micro_test_plus::runner::suite ( const char * name,
Callable_T && callable,
Args_T &&... arguments )
inherited
Template Parameters
Callable_TThe type of a callable object.
Args_TThe types of the callable arguments.
Parameters
[in]nameThe test suite name or description, used in reports.
[in]callableA generic callable object, usually a lambda, invoked to perform the test suite.
[in]argumentsA 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.

Definition at line 113 of file runner-inlines.h.

115 {
116#if defined(MICRO_OS_PLUS_TRACE) \
117 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
118#if defined(__GNUC__)
119#pragma GCC diagnostic push
120#if defined(__clang__)
121#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
122#endif
123#endif
124 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name);
125#if defined(__GNUC__)
126#pragma GCC diagnostic pop
127#endif
128#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
129
130 auto child_suite = std::make_unique<class suite> (
131 name, *this, std::forward<Callable_T> (callable),
132 std::forward<Args_T> (arguments)...);
133
134 register_suite_ (std::move (child_suite));
135 }
void register_suite_(std::unique_ptr< class suite > suite)
Registers a test suite with the runner.
Definition runner.cpp:316

References micro_os_plus::micro_test_plus::detail::test_node::name(), and register_suite_().

Referenced by operator=(), micro_os_plus::micro_test_plus::static_runner::operator=(), micro_os_plus::micro_test_plus::static_runner::register_static_suite(), and register_suite_().

◆ suites_count()

size_t micro_os_plus::micro_test_plus::runner::suites_count ( void ) const
nodiscardnoexceptinherited
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.

Definition at line 468 of file runner.cpp.

469 {
470 return children_suites_.size () + 1;
471 }

References children_suites_.

Referenced by operator=(), micro_os_plus::micro_test_plus::static_runner::run_suites_(), total_suites_count(), and micro_os_plus::micro_test_plus::static_runner::total_suites_count().

◆ timings() [1/2]

const detail::timestamps & micro_os_plus::micro_test_plus::runner::timings ( ) const
inlinenodiscardnoexceptinherited
Parameters
None.
Returns
A const reference to the timestamps instance.

Returns a const reference to the timestamps member.

Definition at line 97 of file runner-inlines.h.

98 {
99 return timings_;
100 }

References timings_.

◆ timings() [2/2]

detail::timestamps & micro_os_plus::micro_test_plus::runner::timings ( )
inlinenodiscardnoexceptinherited
Parameters
None.
Returns
A reference to the timestamps instance.

Returns a reference to the timestamps member.

Definition at line 87 of file runner-inlines.h.

88 {
89 return timings_;
90 }

References timings_.

Referenced by micro_os_plus::micro_test_plus::reporter_human::end_session(), micro_os_plus::micro_test_plus::reporter_tap::end_session(), and operator=().

◆ total_suites_count()

size_t micro_os_plus::micro_test_plus::static_runner::total_suites_count ( void ) const
nodiscardfinaloverridevirtualnoexcept
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.

Reimplemented from micro_os_plus::micro_test_plus::runner.

Definition at line 576 of file runner.cpp.

577 {
578 return suites_count () + static_suites_count ();
579 }
size_t static_suites_count(void) const noexcept
Returns the total count of registered static test suites.
Definition runner.cpp:563

References static_suites_count(), and micro_os_plus::micro_test_plus::runner::suites_count().

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

113 {
114 return totals_;
115 }

References totals_.

◆ totals() [2/2]

runner_totals & micro_os_plus::micro_test_plus::detail::test_node::totals ( )
inlinenodiscardnoexceptinherited

Member Data Documentation

◆ children_suites_

std::vector<std::unique_ptr<class suite> > micro_os_plus::micro_test_plus::runner::children_suites_
protectedinherited

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 register_suite_(), run_suites_(), and suites_count().

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

◆ reporter_

std::unique_ptr<class reporter> micro_os_plus::micro_test_plus::runner::reporter_
protectedinherited

Definition at line 306 of file runner.h.

Referenced by exit_code(), initialise(), and reporter().

◆ static_children_suites_

std::vector<static_suite*>* micro_os_plus::micro_test_plus::static_runner::static_children_suites_
protected

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_

detail::timestamps micro_os_plus::micro_test_plus::runner::timings_
protectedinherited

Definition at line 311 of file runner.h.

Referenced by exit_code(), initialise(), timings(), and timings().

◆ top_suite_

class top_suite micro_os_plus::micro_test_plus::runner::top_suite_
protectedinherited

Definition at line 291 of file runner.h.

Referenced by runner(), runner(), exit_code(), and initialise().

◆ top_suite_name_

std::string micro_os_plus::micro_test_plus::runner::top_suite_name_
protectedinherited

Definition at line 316 of file runner.h.

Referenced by initialise().

◆ 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: