micro-test-plus 6.0.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::counters Class Reference

Aggregated check and test case counters for a node in the test tree. More...

#include "micro-os-plus/micro-test-plus.h"

Public Member Functions

 counters (const counters &other)=default
 Copy constructor.
 counters (counters &&other)=default
 Move constructor.
 counters (void)=default
 Default constructor.
 ~counters ()=default
 Destructor.
size_t executed_checks (void) const noexcept
 Returns the total number of checks executed.
size_t executed_test_cases (void) const noexcept
 Returns the number of test cases that were executed.
size_t failed_checks (void) const noexcept
 Returns the number of checks that failed.
size_t failed_test_cases (void) const noexcept
 Returns the number of executed test cases that failed.
counters & operator= (const counters &other)=default
 Copy assignment operator.
counters & operator= (counters &&other)=default
 Move assignment operator.
bool passed (void) const noexcept
 Checks whether all executed checks and test cases were successful.
size_t passed_checks (void) const noexcept
 Returns the number of checks that passed.
size_t skipped_test_cases (void) const noexcept
 Returns the number of test cases skipped by the filter.
Deprecated Functions
size_t successful_checks (void) const noexcept
 Deprecated name of passed_checks().
size_t executed_subtests (void) const noexcept
 Deprecated name of executed_test_cases().
bool was_successful (void) const noexcept
 Deprecated name of passed().

Private Member Functions

void increment_executed_test_cases (size_t count=1) noexcept
 Increments the executed test cases counter.
void increment_failed_checks (size_t count=1) noexcept
 Increments the failed-checks counter.
void increment_failed_test_cases (size_t count=1) noexcept
 Increments the failed test cases counter.
void increment_passed_checks (size_t count=1) noexcept
 Increments the passed-checks counter.
void increment_skipped_test_cases (size_t count=1) noexcept
 Increments the skipped test cases counter.
counters & operator+= (const counters &other) noexcept
 Accumulates the totals from another instance into this one.

Private Attributes

size_t executed_test_cases_ = 0
 Total number of test cases executed.
size_t failed_checks_ = 0
 Total number of failed checks.
size_t failed_test_cases_ = 0
 Total number of executed test cases that failed.
size_t passed_checks_ = 0
 Total number of passed checks.
size_t skipped_test_cases_ = 0
 Total number of test cases skipped by the filter.

Friends

class detail::check_result
 The check result, which counts the outcome of each check.
class detail::runnable_base
 The base of the test tree nodes, which counts the test cases, adds their totals to those of the suite, and counts a test case started on a suite that is not running as a failed check.
class runner
 The classes that maintain the counters.
class suite
 The suite, which counts an unexpected exception as a failed check.
class test_case
 The test case, which counts an unexpected exception as a failed check.

Detailed Description

counters records five counters that are maintained throughout a test session:

For a test case, the test case counters refer only to its direct nested test cases; for a suite or the runner, they refer to the test cases at all nesting levels.

The runner and every node of the test tree (suite, test_case) own a counters member and accumulate their counts in place. At the end of each suite or session the operator += propagates the child totals up to the parent node, or to the runner.

The tests can read the counters of the runner, of a suite, or of a test case through the totals() accessor. The functions that update the counters are private, and called only by the framework classes, which are friends.

The class is a copyable value type, so that a test can take a snapshot of the counters (counters before = ts.totals ();) and compare it later with the current values. The copy is independent: it is not updated when the original counters change. The nodes that own the live counters are themselves neither copyable nor movable. The runner, the suites, and the test cases return only a const reference, so that the counters of the nodes are read only.

Definition at line 122 of file counters.h.

Constructor & Destructor Documentation

◆ counters() [1/3]

micro_os_plus::micro_test_plus::counters::counters ( void )
default

All counters start at zero, via their default member initialisers.

Referenced by counters(), counters(), detail::runnable_base, operator+=(), operator=(), and operator=().

◆ counters() [2/3]

micro_os_plus::micro_test_plus::counters::counters ( const counters & other)
default

Copies the values of all the counters. The new instance is independent of the original, which may continue to be updated.

Parameters
otherThe instance to copy.
Since
6.0.0

References counters().

◆ counters() [3/3]

micro_os_plus::micro_test_plus::counters::counters ( counters && other)
default

Equivalent to the copy constructor, since the counters are plain integral values.

Parameters
otherThe instance to move from.
Since
6.0.0

References counters().

◆ ~counters()

micro_os_plus::micro_test_plus::counters::~counters ( )
default

Member Function Documentation

◆ executed_checks()

size_t micro_os_plus::micro_test_plus::counters::executed_checks ( void ) const
inlinenodiscardnoexcept
Parameters
None.
Returns
The sum of passed and failed checks.

Returns the sum of passed_checks_ and failed_checks_.

Definition at line 143 of file counters-inlines.h.

144 {
146 }
size_t passed_checks_
Total number of passed checks.
Definition counters.h:477
size_t failed_checks_
Total number of failed checks.
Definition counters.h:485

References failed_checks_, and passed_checks_.

Referenced by ~counters(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_suite(), and micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case().

◆ executed_subtests()

size_t micro_os_plus::micro_test_plus::counters::executed_subtests ( void ) const
inlinenodiscardnoexcept

Calls executed_test_cases(). The old name referred to the subtest class, which is now test_case.

Parameters
None.
Returns
The value returned by executed_test_cases().
Deprecated
use executed_test_cases() (since 6.0.0)

Forwards to executed_test_cases().

Definition at line 165 of file counters-inlines.h.

166 {
167 return executed_test_cases ();
168 }
size_t executed_test_cases(void) const noexcept
Returns the number of test cases that were executed.

References executed_test_cases().

Referenced by ~counters().

◆ executed_test_cases()

◆ failed_checks()

size_t micro_os_plus::micro_test_plus::counters::failed_checks ( void ) const
inlinenodiscardnoexcept

◆ failed_test_cases()

size_t micro_os_plus::micro_test_plus::counters::failed_test_cases ( void ) const
inlinenodiscardnoexcept
Parameters
None.
Returns
The cumulative count of failed test cases.

Returns the value of the failed_test_cases_ counter.

Definition at line 176 of file counters-inlines.h.

177 {
178 return failed_test_cases_;
179 }
size_t failed_test_cases_
Total number of executed test cases that failed.
Definition counters.h:506

References failed_test_cases_.

Referenced by ~counters(), and micro_os_plus::micro_test_plus::detail::reporter::format_test_case_totals().

◆ increment_executed_test_cases()

void micro_os_plus::micro_test_plus::counters::increment_executed_test_cases ( size_t count = 1)
inlineprivatenoexcept
Parameters
countThe number of test cases to add (default 1).
Returns
Nothing.

Adds count to the executed_test_cases_ counter.

Definition at line 80 of file counters-inlines.h.

81 {
82 executed_test_cases_ += count;
83 }

References executed_test_cases_.

Referenced by micro_os_plus::micro_test_plus::detail::runnable_base::after_test_case_create(), and detail::runnable_base.

◆ increment_failed_checks()

void micro_os_plus::micro_test_plus::counters::increment_failed_checks ( size_t count = 1)
inlineprivatenoexcept

◆ increment_failed_test_cases()

void micro_os_plus::micro_test_plus::counters::increment_failed_test_cases ( size_t count = 1)
inlineprivatenoexcept
Parameters
countThe number of failed test cases to add (default 1).
Returns
Nothing.

Adds count to the failed_test_cases_ counter.

Definition at line 90 of file counters-inlines.h.

91 {
92 failed_test_cases_ += count;
93 }

References failed_test_cases_.

Referenced by micro_os_plus::micro_test_plus::detail::runnable_base::after_test_case_create(), and detail::runnable_base.

◆ increment_passed_checks()

void micro_os_plus::micro_test_plus::counters::increment_passed_checks ( size_t count = 1)
inlineprivatenoexcept

Called for each check that passed; the opposite count is incremented by increment_failed_checks().

Parameters
countThe number of passed checks to add (default 1).
Returns
Nothing.
Since
6.0.0

Adds count to the passed_checks_ counter.

Definition at line 60 of file counters-inlines.h.

61 {
62 passed_checks_ += count;
63 }

References passed_checks_.

Referenced by micro_os_plus::micro_test_plus::detail::check_result::~check_result(), and detail::runnable_base.

◆ increment_skipped_test_cases()

void micro_os_plus::micro_test_plus::counters::increment_skipped_test_cases ( size_t count = 1)
inlineprivatenoexcept
Parameters
countThe number of skipped test cases to add (default 1).
Returns
Nothing.
Since
6.0.0

Adds count to the skipped_test_cases_ counter.

Definition at line 100 of file counters-inlines.h.

101 {
102 skipped_test_cases_ += count;
103 }
size_t skipped_test_cases_
Total number of test cases skipped by the filter.
Definition counters.h:516

References skipped_test_cases_.

Referenced by micro_os_plus::micro_test_plus::detail::runnable_base::after_test_case_create(), and detail::runnable_base.

◆ operator+=()

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

Adds the passed check count, failed check count, executed test case count, failed test case count, and skipped test case 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 counters.cpp.

72 {
73 passed_checks_ += other.passed_checks ();
74 failed_checks_ += other.failed_checks ();
75 executed_test_cases_ += other.executed_test_cases ();
76 failed_test_cases_ += other.failed_test_cases ();
77 skipped_test_cases_ += other.skipped_test_cases ();
78
79#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
80 trace::printf ("%s -> +%" MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE
84 __PRETTY_FUNCTION__, passed_checks_, failed_checks_,
86#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED
87
88 return *this;
89 }
#define MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE
Portable printf() conversion for the size_t values.
Definition detail.h:102

References counters(), executed_test_cases_, failed_checks_, failed_test_cases_, MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE, passed_checks_, and skipped_test_cases_.

◆ operator=() [1/2]

counters & micro_os_plus::micro_test_plus::counters::operator= ( const counters & other)
default

Replaces the values of all the counters with those of other.

Parameters
otherThe instance to copy.
Returns
Reference to this instance.
Since
6.0.0

References counters().

◆ operator=() [2/2]

counters & micro_os_plus::micro_test_plus::counters::operator= ( counters && other)
default

Equivalent to the copy assignment operator, since the counters are plain integral values.

Parameters
otherThe instance to move from.
Returns
Reference to this instance.
Since
6.0.0

References counters().

◆ passed()

bool micro_os_plus::micro_test_plus::counters::passed ( void ) const
inlinenodiscardnoexcept
Parameters
None.
Return values
trueNo checks and no test cases failed.
falseAt least one check or one test case failed.

A node with no checks at all is considered successful, as it did not fail any check. A test case whose own checks all passed is still unsuccessful if one of its nested test cases failed, so that a failure is reported at every level above it, as in node-tap.

Definition at line 199 of file counters-inlines.h.

200 {
201 return failed_checks_ == 0 && failed_test_cases_ == 0;
202 }

References failed_checks_, and failed_test_cases_.

Referenced by ~counters(), micro_os_plus::micro_test_plus::detail::runnable_base::after_test_case_create(), micro_os_plus::micro_test_plus::detail::reporter_human::end_session(), micro_os_plus::micro_test_plus::detail::reporter_human::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_suite(), micro_os_plus::micro_test_plus::detail::reporter_human::end_test_case(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case(), micro_os_plus::micro_test_plus::detail::reporter::format_suite_totals(), micro_os_plus::micro_test_plus::detail::reporter::format_test_case_totals(), micro_os_plus::micro_test_plus::runner::run_suites(), and was_successful().

◆ passed_checks()

size_t micro_os_plus::micro_test_plus::counters::passed_checks ( void ) const
inlinenodiscardnoexcept

◆ skipped_test_cases()

size_t micro_os_plus::micro_test_plus::counters::skipped_test_cases ( void ) const
inlinenodiscardnoexcept

The skipped test cases are not included in executed_test_cases().

Parameters
None.
Returns
The cumulative count of skipped test cases.
Since
6.0.0

Returns the value of the skipped_test_cases_ counter.

Definition at line 186 of file counters-inlines.h.

187 {
188 return skipped_test_cases_;
189 }

References skipped_test_cases_.

Referenced by ~counters(), micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case(), micro_os_plus::micro_test_plus::detail::reporter::format_session_totals(), and micro_os_plus::micro_test_plus::detail::reporter::format_suite_totals().

◆ successful_checks()

size_t micro_os_plus::micro_test_plus::counters::successful_checks ( void ) const
inlinenodiscardnoexcept

Calls passed_checks(). The old name called the checks "successful", while the reporters print them as "passed".

Parameters
None.
Returns
The value returned by passed_checks().
Deprecated
use passed_checks() (since 6.0.0)

Forwards to passed_checks().

Definition at line 122 of file counters-inlines.h.

123 {
124 return passed_checks ();
125 }
size_t passed_checks(void) const noexcept
Returns the number of checks that passed.

References passed_checks().

Referenced by ~counters().

◆ was_successful()

bool micro_os_plus::micro_test_plus::counters::was_successful ( void ) const
inlinenodiscardnoexcept

Calls passed(). The new name matches the word used by the reports, and by passed_checks().

Parameters
None.
Returns
The value returned by passed().
Deprecated
use passed() (since 6.0.0)

Forwards to passed().

Definition at line 211 of file counters-inlines.h.

212 {
213 return passed ();
214 }
bool passed(void) const noexcept
Checks whether all executed checks and test cases were successful.

References passed().

Referenced by ~counters().

◆ detail::check_result

friend class detail::check_result
friend

See the friend declaration of runner.

Definition at line 392 of file counters.h.

◆ detail::runnable_base

◆ runner

friend class runner
friend

The nodes of the test tree and the check result update their counters, and the runner accumulates the totals of the suites; the applications only read them.

Definition at line 366 of file counters.h.

References runner.

Referenced by runner.

◆ suite

friend class suite
friend

See the friend declaration of runner.

Definition at line 375 of file counters.h.

References suite.

Referenced by suite.

◆ test_case

friend class test_case
friend

See the friend declaration of runner.

Definition at line 384 of file counters.h.

References test_case.

Referenced by test_case.

Member Data Documentation

◆ executed_test_cases_

size_t micro_os_plus::micro_test_plus::counters::executed_test_cases_ = 0
private

Incremented by increment_executed_test_cases() and by operator+=.

Definition at line 494 of file counters.h.

Referenced by executed_test_cases(), increment_executed_test_cases(), and operator+=().

◆ failed_checks_

size_t micro_os_plus::micro_test_plus::counters::failed_checks_ = 0
private

Incremented by increment_failed_checks() and by operator+=.

Definition at line 485 of file counters.h.

Referenced by executed_checks(), failed_checks(), increment_failed_checks(), operator+=(), and passed().

◆ failed_test_cases_

size_t micro_os_plus::micro_test_plus::counters::failed_test_cases_ = 0
private

Incremented by increment_failed_test_cases(), when a test case ends with a failed check or a failed nested test case, and by operator+=. A test case fails when any of its nested test cases fails, as in node-tap, although the checks of the nested test cases are not counted in its check counters.

Definition at line 506 of file counters.h.

Referenced by failed_test_cases(), increment_failed_test_cases(), operator+=(), and passed().

◆ passed_checks_

size_t micro_os_plus::micro_test_plus::counters::passed_checks_ = 0
private

Incremented by increment_passed_checks() and by operator+=.

Definition at line 477 of file counters.h.

Referenced by executed_checks(), increment_passed_checks(), operator+=(), and passed_checks().

◆ skipped_test_cases_

size_t micro_os_plus::micro_test_plus::counters::skipped_test_cases_ = 0
private

Incremented by increment_skipped_test_cases(), when the name of a test case, or of its suite, does not match the filter pattern of its level, and by operator+=.

Definition at line 516 of file counters.h.

Referenced by increment_skipped_test_cases(), operator+=(), and skipped_test_cases().


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