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

Aggregated pass/fail/subtest counters for a node in the test tree. More...

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

Public Member Functions

 runner_totals ()=default
 Default constructor. All counters are zero-initialised.
 runner_totals (const runner_totals &)=delete
 Deleted copy constructor to prevent copying.
 runner_totals (runner_totals &&)=delete
 Deleted move constructor to prevent moving.
size_t executed_checks () const noexcept
 Returns the total number of checks executed.
size_t executed_subtests () const noexcept
 Returns the number of subtests that were executed.
size_t failed_checks () const noexcept
 Returns the number of checks that failed.
void increment_executed_subtests (size_t count=1) noexcept
 Increments the executed-subtests counter.
void increment_failed_checks (size_t count=1) noexcept
 Increments the failed-checks counter.
void increment_successful_checks (size_t count=1) noexcept
 Increments the successful-checks counter.
runner_totalsoperator+= (const runner_totals &other) noexcept
 Accumulates the totals from another instance into this one.
runner_totalsoperator= (const runner_totals &)=delete
 Deleted copy assignment operator to prevent copying.
runner_totalsoperator= (runner_totals &&)=delete
 Deleted move assignment operator to prevent moving.
size_t successful_checks () const noexcept
 Returns the number of checks that passed.
bool was_successful (void) const noexcept
 Checks whether all executed checks were successful.

Protected Attributes

size_t executed_subtests_ = 0
 Total number of tests executed.
size_t failed_checks_ = 0
 Total number of failed checks.
size_t successful_checks_ = 0
 Total number of successful checks.

Detailed Description

runner_totals records three counters that are maintained throughout a test session:

Every test_node-derived object (runner, suite, subtest) owns a runner_totals member and accumulates its counts in place. At the end of each suite or session the operator += propagates the child totals up to the parent node.

The class is non-copyable and non-movable to prevent accidental duplication of live counters.

Definition at line 88 of file runner-totals.h.

Constructor & Destructor Documentation

◆ runner_totals() [1/3]

micro_os_plus::micro_test_plus::detail::runner_totals::runner_totals ( )
default

◆ runner_totals() [2/3]

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

References runner_totals().

◆ runner_totals() [3/3]

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

References runner_totals().

Member Function Documentation

◆ executed_checks()

size_t micro_os_plus::micro_test_plus::detail::runner_totals::executed_checks ( ) const
inlinenodiscardnoexcept
Parameters
None.
Returns
The sum of successful and failed checks.

Returns the sum of successful_checks_ and failed_checks_.

Definition at line 111 of file runner-totals-inlines.h.

112 {
114 }
size_t successful_checks_
Total number of successful checks.
size_t failed_checks_
Total number of failed checks.

References failed_checks_, and successful_checks_.

Referenced by micro_os_plus::micro_test_plus::reporter_tap::end_subtest(), micro_os_plus::micro_test_plus::reporter_tap::end_suite(), and operator=().

◆ executed_subtests()

size_t micro_os_plus::micro_test_plus::detail::runner_totals::executed_subtests ( ) const
inlinenodiscardnoexcept

◆ failed_checks()

size_t micro_os_plus::micro_test_plus::detail::runner_totals::failed_checks ( ) const
inlinenodiscardnoexcept

◆ increment_executed_subtests()

void micro_os_plus::micro_test_plus::detail::runner_totals::increment_executed_subtests ( size_t count = 1)
inlinenoexcept
Parameters
countThe number of subtests to add (default 1).
Returns
Nothing.

Adds count to the executed_subtests_ counter.

Definition at line 81 of file runner-totals-inlines.h.

82 {
83 executed_subtests_ += count;
84 }

References executed_subtests_.

Referenced by micro_os_plus::micro_test_plus::detail::runnable_base::after_subtest_create_(), and operator=().

◆ increment_failed_checks()

void micro_os_plus::micro_test_plus::detail::runner_totals::increment_failed_checks ( size_t count = 1)
inlinenoexcept
Parameters
countThe number of failed checks to add (default 1).
Returns
Nothing.

Adds count to the failed_checks_ counter.

Definition at line 71 of file runner-totals-inlines.h.

72 {
73 failed_checks_ += count;
74 }

References failed_checks_.

Referenced by operator=().

◆ increment_successful_checks()

void micro_os_plus::micro_test_plus::detail::runner_totals::increment_successful_checks ( size_t count = 1)
inlinenoexcept
Parameters
countThe number of successful checks to add (default 1).
Returns
Nothing.

Adds count to the successful_checks_ counter.

Definition at line 61 of file runner-totals-inlines.h.

62 {
63 successful_checks_ += count;
64 }

References successful_checks_.

◆ operator+=()

runner_totals & micro_os_plus::micro_test_plus::detail::runner_totals::operator+= ( const runner_totals & other)
noexcept
Parameters
otherThe instance whose totals are to be added.
Returns
Reference to this instance.

Adds the successful check count, failed check count, and executed subtest count of other to the corresponding members of this instance. Returns a reference to *this to support chaining. When tracing is enabled, the updated totals are output for diagnostic purposes.

Definition at line 71 of file runner-totals.cpp.

72 {
73 successful_checks_ += other.successful_checks ();
74 failed_checks_ += other.failed_checks ();
75 executed_subtests_ += other.executed_subtests ();
76
77#if defined(MICRO_OS_PLUS_TRACE) \
78 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
79#if defined(__GNUC__)
80#pragma GCC diagnostic push
81#if defined(__clang__)
82#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
83#endif
84#endif
85 trace::printf ("%s -> +%zu -%zu in xs%zu\n", __PRETTY_FUNCTION__,
87#if defined(__GNUC__)
88#pragma GCC diagnostic pop
89#endif
90#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
91
92 return *this;
93 }

References runner_totals(), executed_subtests_, failed_checks_, and successful_checks_.

◆ operator=() [1/2]

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

References runner_totals().

◆ operator=() [2/2]

◆ successful_checks()

size_t micro_os_plus::micro_test_plus::detail::runner_totals::successful_checks ( ) const
inlinenodiscardnoexcept

◆ was_successful()

bool micro_os_plus::micro_test_plus::detail::runner_totals::was_successful ( void ) const
inlinenodiscardnoexcept
Parameters
None.
Return values
trueNo checks failed.
falseAt least one check failed.

A runner with no checks at all is considered successful, as it did not fail any check.

Definition at line 132 of file runner-totals-inlines.h.

133 {
134 return failed_checks_ == 0;
135 }

References failed_checks_.

Referenced by micro_os_plus::micro_test_plus::reporter_human::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=().

Member Data Documentation

◆ executed_subtests_

size_t micro_os_plus::micro_test_plus::detail::runner_totals::executed_subtests_ = 0
protected

Definition at line 224 of file runner-totals.h.

Referenced by executed_subtests(), increment_executed_subtests(), and operator+=().

◆ failed_checks_

size_t micro_os_plus::micro_test_plus::detail::runner_totals::failed_checks_ = 0
protected

◆ successful_checks_

size_t micro_os_plus::micro_test_plus::detail::runner_totals::successful_checks_ = 0
protected

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