micro-test-plus 6.0.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
counters.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can be
9 * obtained from https://opensource.org/licenses/mit.
10 */
11
12// ----------------------------------------------------------------------------
13
34
35#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_COUNTERS_H_
36#define MICRO_OS_PLUS_MICRO_TEST_PLUS_COUNTERS_H_
37
38// ----------------------------------------------------------------------------
39
40#if defined(__cplusplus)
41
42// ----------------------------------------------------------------------------
43
44#if __has_include("micro-os-plus/project-config.h")
45#include "micro-os-plus/project-config.h"
46#endif // __has_include("micro-os-plus/project-config.h")
47
48#if __has_include("micro-os-plus/micro-test-plus-defines.h")
49#include "micro-os-plus/micro-test-plus-defines.h"
50#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
51
52#include <cstddef>
53
54// ----------------------------------------------------------------------------
55
56#if defined(__GNUC__)
57#pragma GCC diagnostic push
58
59#if defined(__clang__)
60#pragma clang diagnostic ignored "-Wc++98-compat"
61#endif // defined(__clang__)
62#endif // defined(__GNUC__)
63
64// ============================================================================
65
67{
68 // ==========================================================================
69
70 class runner;
71 class suite;
72 class test_case;
73
74 namespace detail
75 {
76 class check_result;
77 class runnable_base;
78 } // namespace detail
79
80 // ==========================================================================
81
123 {
124 public:
131 counters (void) = default;
132
144 counters (const counters& other) = default;
145
157 counters (counters&& other) = default;
158
170 counters&
171 operator= (const counters& other)
172 = default;
173
186 counters&
188 = default;
189
196 ~counters () = default;
197
211 [[nodiscard]] size_t
212 passed_checks (void) const noexcept;
213
214#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
219
231 [[deprecated ("use passed_checks() (since 6.0.0)"), nodiscard]] size_t
232 successful_checks (void) const noexcept;
233
237#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
238
246 [[nodiscard]] size_t
247 failed_checks (void) const noexcept;
248
256 [[nodiscard]] size_t
257 executed_checks (void) const noexcept;
258
266 [[nodiscard]] size_t
267 executed_test_cases (void) const noexcept;
268
269#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
274
286 [[deprecated ("use executed_test_cases() (since 6.0.0)"),
287 nodiscard]] size_t
288 executed_subtests (void) const noexcept;
289
293#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
294
302 [[nodiscard]] size_t
303 failed_test_cases (void) const noexcept;
304
317 [[nodiscard]] size_t
318 skipped_test_cases (void) const noexcept;
319
329 [[nodiscard]] bool
330 passed (void) const noexcept;
331
332#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
337
349 [[deprecated ("use passed() (since 6.0.0)"), nodiscard]] bool
350 was_successful (void) const noexcept;
351
355#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
356
357 private:
366 friend class runner;
367
375 friend class suite;
376
384 friend class test_case;
385
393
403
410 counters&
411 operator+= (const counters& other) noexcept;
412
426 void
427 increment_passed_checks (size_t count = 1) noexcept;
428
436 void
437 increment_failed_checks (size_t count = 1) noexcept;
438
446 void
447 increment_executed_test_cases (size_t count = 1) noexcept;
448
456 void
457 increment_failed_test_cases (size_t count = 1) noexcept;
458
468 void
469 increment_skipped_test_cases (size_t count = 1) noexcept;
470
477 size_t passed_checks_ = 0;
478
485 size_t failed_checks_ = 0;
486
495
507
517 };
518
519 // --------------------------------------------------------------------------
520} // namespace micro_os_plus::micro_test_plus
521
522#if defined(__GNUC__)
523#pragma GCC diagnostic pop
524#endif // defined(__GNUC__)
525
526// ----------------------------------------------------------------------------
527
528#endif // defined(__cplusplus)
529
530// ============================================================================
531// Templates, inlines & constexpr implementations.
532
534
535// ----------------------------------------------------------------------------
536
537#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_COUNTERS_H_
538
539// ----------------------------------------------------------------------------
size_t failed_test_cases_
Total number of executed test cases that failed.
Definition counters.h:506
void increment_skipped_test_cases(size_t count=1) noexcept
Increments the skipped test cases counter.
bool passed(void) const noexcept
Checks whether all executed checks and test cases were successful.
void increment_executed_test_cases(size_t count=1) noexcept
Increments the executed test cases counter.
void increment_passed_checks(size_t count=1) noexcept
Increments the passed-checks counter.
size_t successful_checks(void) const noexcept
Deprecated name of passed_checks().
size_t skipped_test_cases(void) const noexcept
Returns the number of test cases skipped by the filter.
size_t executed_subtests(void) const noexcept
Deprecated name of executed_test_cases().
size_t executed_test_cases(void) const noexcept
Returns the number of test cases that were executed.
counters(void)=default
Default constructor.
size_t skipped_test_cases_
Total number of test cases skipped by the filter.
Definition counters.h:516
size_t passed_checks_
Total number of passed checks.
Definition counters.h:477
counters(counters &&other)=default
Move constructor.
size_t executed_checks(void) const noexcept
Returns the total number of checks executed.
size_t passed_checks(void) const noexcept
Returns the number of checks that passed.
size_t executed_test_cases_
Total number of test cases executed.
Definition counters.h:494
void increment_failed_test_cases(size_t count=1) noexcept
Increments the failed test cases counter.
size_t failed_test_cases(void) const noexcept
Returns the number of executed test cases that failed.
friend class test_case
The test case, which counts an unexpected exception as a failed check.
Definition counters.h:384
size_t failed_checks_
Total number of failed checks.
Definition counters.h:485
size_t failed_checks(void) const noexcept
Returns the number of checks that failed.
friend class runner
The classes that maintain the counters.
Definition counters.h:366
friend class suite
The suite, which counts an unexpected exception as a failed check.
Definition counters.h:375
void increment_failed_checks(size_t count=1) noexcept
Increments the failed-checks counter.
counters & operator+=(const counters &other) noexcept
Accumulates the totals from another instance into this one.
Definition counters.cpp:71
counters & operator=(const counters &other)=default
Copy assignment operator.
bool was_successful(void) const noexcept
Deprecated name of passed().
counters(const counters &other)=default
Copy constructor.
The result of one check, reported when destroyed.
Non-template base for all runnable objects (suites and test cases).
Definition test.h:349
The test runner for the µTest++ framework.
Definition runner.h:187
A named, runnable test suite registered with the test runner.
Definition test.h:2059
A named, runnable test case that lives inside a suite.
Definition test.h:1362
C++ header file with inline implementations for the µTest++ counters.
Internal implementation details for the µTest++ framework.
Primary namespace for the µTest++ testing framework.