Skip to main content

counters Class

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

Declaration​

class micro_os_plus::micro_test_plus::counters { ... }

Included Headers​

Friends Index​

classdetail::check_result

The check result, which counts the outcome of each check. More...

classdetail::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. More...

classrunner

The classes that maintain the counters. More...

classsuite

The suite, which counts an unexpected exception as a failed check. More...

classtest_case

The test case, which counts an unexpected exception as a failed check. More...

Public Constructors Index​

counters (const counters &other)=default

Copy constructor. More...

counters (counters &&other)=default

Move constructor. More...

counters (void)=default

Default constructor. More...

Public Destructor Index​

~counters ()=default

Destructor. More...

Public Operators Index​

counters &operator= (const counters &other)=default

Copy assignment operator. More...

counters &operator= (counters &&other)=default

Move assignment operator. More...

Private Operators Index​

counters &operator+= (const counters &other) noexcept

Accumulates the totals from another instance into this one. More...

Public Member Functions Index​

size_texecuted_checks (void) const noexcept

Returns the total number of checks executed. More...

size_texecuted_test_cases (void) const noexcept

Returns the number of test cases that were executed. More...

size_tfailed_checks (void) const noexcept

Returns the number of checks that failed. More...

size_tfailed_test_cases (void) const noexcept

Returns the number of executed test cases that failed. More...

boolpassed (void) const noexcept

Checks whether all executed checks and test cases were successful. More...

size_tpassed_checks (void) const noexcept

Returns the number of checks that passed. More...

size_tskipped_test_cases (void) const noexcept

Returns the number of test cases skipped by the filter. More...

Private Member Functions Index​

voidincrement_executed_test_cases (size_t count=1) noexcept

Increments the executed test cases counter. More...

voidincrement_failed_checks (size_t count=1) noexcept

Increments the failed-checks counter. More...

voidincrement_failed_test_cases (size_t count=1) noexcept

Increments the failed test cases counter. More...

voidincrement_passed_checks (size_t count=1) noexcept

Increments the passed-checks counter. More...

voidincrement_skipped_test_cases (size_t count=1) noexcept

Increments the skipped test cases counter. More...

Private Member Attributes Index​

size_texecuted_test_cases_ = 0

Total number of test cases executed. More...

size_tfailed_checks_ = 0

Total number of failed checks. More...

size_tfailed_test_cases_ = 0

Total number of executed test cases that failed. More...

size_tpassed_checks_ = 0

Total number of passed checks. More...

size_tskipped_test_cases_ = 0

Total number of test cases skipped by the filter. More...

Deprecated Functions Index​

size_tsuccessful_checks (void) const noexcept

Deprecated name of passed_checks(). More...

size_texecuted_subtests (void) const noexcept

Deprecated name of executed_test_cases(). More...

boolwas_successful (void) const noexcept

Deprecated name of passed(). More...

Description​

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

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.

Friends​

detail::check_result​

friend class detail::check_result

The check result, which counts the outcome of each check.

See the friend declaration of runner.

Definition at line 392 of file counters.h.

detail::runnable_base​

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

See the friend declaration of runner.

Definition at line 402 of file counters.h.

References counters, increment_executed_test_cases, increment_failed_checks, increment_failed_test_cases, increment_passed_checks and increment_skipped_test_cases.

runner​

friend class runner

The classes that maintain the counters.

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.

366 friend class runner;

Reference runner.

Referenced by runner.

suite​

friend class suite

The suite, which counts an unexpected exception as a failed check.

See the friend declaration of runner.

Definition at line 375 of file counters.h.

375 friend class suite;

Reference suite.

Referenced by suite.

test_case​

friend class test_case

The test case, which counts an unexpected exception as a failed check.

See the friend declaration of runner.

Definition at line 384 of file counters.h.

384 friend class test_case;

Reference test_case.

Referenced by test_case.

Public Constructors​

counters()​

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

Copy constructor.

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

Parameters
other

The instance to copy.

Since

6.0.0

Definition at line 144 of file counters.h.

Reference counters.

counters()​

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

Move constructor.

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

Parameters
other

The instance to move from.

Since

6.0.0

Definition at line 157 of file counters.h.

Reference counters.

counters()​

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

Default constructor.

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

Definition at line 131 of file counters.h.

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

Public Destructor​

~counters()​

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

Destructor.

Trivial; the counters own no resources.

Definition at line 196 of file counters.h.

References executed_checks, executed_subtests, executed_test_cases, failed_checks, failed_test_cases, passed, passed_checks, skipped_test_cases, successful_checks and was_successful.

Public Operators​

operator=()​

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

Copy assignment operator.

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

Parameters
other

The instance to copy.

Returns

Reference to this instance.

Since

6.0.0

Definition at line 171 of file counters.h.

Reference counters.

operator=()​

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

Move assignment operator.

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

Parameters
other

The instance to move from.

Returns

Reference to this instance.

Since

6.0.0

Definition at line 187 of file counters.h.

Reference counters.

Private Operators​

operator+=()​

counters & micro_os_plus::micro_test_plus::counters::operator+= (const counters & other)
noexcept

Accumulates the totals from another instance into this one.

Parameters
other

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

Declaration at line 411 of file counters.h, definition at line 71 of file counters.cpp.

71 counters::operator+=(const counters& other) noexcept
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 }

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

Public Member Functions​

executed_checks()​

size_t micro_os_plus::micro_test_plus::counters::executed_checks (void)
inline nodiscard noexcept

Returns the total number of checks executed.

Parameters

None.

Returns

The sum of passed and failed checks.

Returns the sum of passed_checks_ and failed_checks_.

Declaration at line 257 of file counters.h, definition at line 143 of file counters-inlines.h.

143 counters::executed_checks (void) const noexcept
144 {
146 }

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_test_cases()​

size_t micro_os_plus::micro_test_plus::counters::executed_test_cases (void)
inline nodiscard noexcept

failed_checks()​

size_t micro_os_plus::micro_test_plus::counters::failed_checks (void)
inline nodiscard noexcept

failed_test_cases()​

size_t micro_os_plus::micro_test_plus::counters::failed_test_cases (void)
inline nodiscard noexcept

Returns the number of executed test cases that failed.

Parameters

None.

Returns

The cumulative count of failed test cases.

Returns the value of the failed_test_cases_ counter.

Declaration at line 303 of file counters.h, definition at line 176 of file counters-inlines.h.

176 counters::failed_test_cases (void) const noexcept
177 {
178 return failed_test_cases_;
179 }

Reference failed_test_cases_.

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

passed()​

bool micro_os_plus::micro_test_plus::counters::passed (void)
inline nodiscard noexcept

Checks whether all executed checks and test cases were successful.

Parameters

None.

Return Values
true

No checks and no test cases failed.

false

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

Declaration at line 330 of file counters.h, definition at line 199 of file counters-inlines.h.

199 counters::passed (void) const noexcept
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)
inline nodiscard noexcept

Returns the number of checks that passed.

The opposite count is returned by failed_checks(), and their sum by executed_checks().

Parameters

None.

Returns

The cumulative count of passed checks.

Since

6.0.0

Returns the value of the passed_checks_ counter.

Declaration at line 212 of file counters.h, definition at line 110 of file counters-inlines.h.

110 counters::passed_checks (void) const noexcept
111 {
112 return passed_checks_;
113 }

Reference passed_checks_.

Referenced by ~counters, micro_os_plus::micro_test_plus::detail::reporter_tap::end_suite, micro_os_plus::micro_test_plus::detail::reporter_tap::end_test_case, micro_os_plus::micro_test_plus::detail::reporter::format_session_totals, micro_os_plus::micro_test_plus::detail::reporter::format_suite_totals, micro_os_plus::micro_test_plus::detail::reporter::format_test_case_totals and successful_checks.

skipped_test_cases()​

size_t micro_os_plus::micro_test_plus::counters::skipped_test_cases (void)
inline nodiscard noexcept

Returns the number of test cases skipped by the filter.

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.

Declaration at line 318 of file counters.h, definition at line 186 of file counters-inlines.h.

186 counters::skipped_test_cases (void) const noexcept
187 {
189 }

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

Private Member Functions​

increment_executed_test_cases()​

void micro_os_plus::micro_test_plus::counters::increment_executed_test_cases (size_t count=1)
inline noexcept

Increments the executed test cases counter.

Parameters
count

The number of test cases to add (default 1).

Returns

Nothing.

Adds count to the executed_test_cases_ counter.

Declaration at line 447 of file counters.h, definition at line 80 of file counters-inlines.h.

81 {
83 }

Reference 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)
inline noexcept

increment_failed_test_cases()​

void micro_os_plus::micro_test_plus::counters::increment_failed_test_cases (size_t count=1)
inline noexcept

Increments the failed test cases counter.

Parameters
count

The number of failed test cases to add (default 1).

Returns

Nothing.

Adds count to the failed_test_cases_ counter.

Declaration at line 457 of file counters.h, definition at line 90 of file counters-inlines.h.

91 {
92 failed_test_cases_ += count;
93 }

Reference 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)
inline noexcept

Increments the passed-checks counter.

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

Parameters
count

The number of passed checks to add (default 1).

Returns

Nothing.

Since

6.0.0

Adds count to the passed_checks_ counter.

Declaration at line 427 of file counters.h, definition at line 60 of file counters-inlines.h.

60 counters::increment_passed_checks (size_t count) noexcept
61 {
62 passed_checks_ += count;
63 }

Reference 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)
inline noexcept

Increments the skipped test cases counter.

Parameters
count

The number of skipped test cases to add (default 1).

Returns

Nothing.

Since

6.0.0

Adds count to the skipped_test_cases_ counter.

Declaration at line 469 of file counters.h, definition at line 100 of file counters-inlines.h.

101 {
102 skipped_test_cases_ += count;
103 }

Reference skipped_test_cases_.

Referenced by micro_os_plus::micro_test_plus::detail::runnable_base::after_test_case_create and detail::runnable_base.

Private Member Attributes​

executed_test_cases_​

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

Total number of test cases executed.

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

Total number of failed checks.

Incremented by increment_failed_checks() and by operator+=.

Definition at line 485 of file counters.h.

485 size_t failed_checks_ = 0;

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

Total number of executed test cases that failed.

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

Total number of passed checks.

Incremented by increment_passed_checks() and by operator+=.

Definition at line 477 of file counters.h.

477 size_t passed_checks_ = 0;

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

Total number of test cases skipped by the filter.

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.

Deprecated Functions​

executed_subtests()​

size_t micro_os_plus::micro_test_plus::counters::executed_subtests (void)
inline nodiscard noexcept

Deprecated name of executed_test_cases().

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

Declaration at line 288 of file counters.h, definition at line 165 of file counters-inlines.h.

165 counters::executed_subtests (void) const noexcept
166 {
167 return executed_test_cases ();
168 }

Reference executed_test_cases.

Referenced by ~counters.

successful_checks()​

size_t micro_os_plus::micro_test_plus::counters::successful_checks (void)
inline nodiscard noexcept

Deprecated name of passed_checks().

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

Declaration at line 232 of file counters.h, definition at line 122 of file counters-inlines.h.

122 counters::successful_checks (void) const noexcept
123 {
124 return passed_checks ();
125 }

Reference passed_checks.

Referenced by ~counters.

was_successful()​

bool micro_os_plus::micro_test_plus::counters::was_successful (void)
inline nodiscard noexcept

Deprecated name of passed().

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

Declaration at line 350 of file counters.h, definition at line 211 of file counters-inlines.h.

211 counters::was_successful (void) const noexcept
212 {
213 return passed ();
214 }

Reference passed.

Referenced by ~counters.


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


Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.