Skip to main content

test-reporter.h File

C++ header file with declarations for the µTest++ test reporter. More...

Included Headers

#include <string_view> #include <string> #include "type-traits.h" #include "test-suite.h" #include "detail.h"

Namespaces Index

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespacemicro_test_plus

Primary namespace for the µTest++ testing framework. More...

Classes Index

structcolors

Colours used to highlight pass and fail results in test reports. More...

classtest_reporter

Reporter to display test results, including operand values and types for failures. More...

Typedefs Index

typedefverbosity verbosity_t

Type alias for the verbosity enumeration used in test reporting. More...

Enumerations Index

enum classverbosity { ... }

The verbosity levels for test reporting. More...

Functions Index

test_reporter &endl (test_reporter &stream)

Output stream manipulator for ending a line in test reports. More...

Variables Index

const colorscolors_red_green = ...

Description

C++ header file with declarations for the µTest++ test reporter.

This header provides the declarations for the test reporting facilities used within the µTest++ framework. It defines the interfaces for formatting and outputting test results, including operator overloads for a wide range of value types, containers, and comparison expressions, as well as structured output for logical and exception-related assertions.

The test reporter is responsible for presenting test outcomes in a clear, consistent, and expressive manner, supporting both value and pointer semantics, and providing detailed diagnostics for both successful and failed test cases. Special attention is given to formatting, colour highlighting, and extensibility, enabling professional and readable test reports suitable for embedded and general C++ development.

All definitions reside within the micro_os_plus::micro_test_plus namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

The header files are organised within the include/micro-os-plus/micro-test-plus folder to maintain a structured and modular codebase.

This file is intended solely for internal use within the framework and should not be included directly by user code.

Typedefs

verbosity_t

typedef verbosity micro_os_plus::micro_test_plus::verbosity_t

Type alias for the verbosity enumeration used in test reporting.

The verbosity_t type alias provides a convenient shorthand for referring to the verbosity enumeration, which defines the available levels of detail for test output within the reporting system.

Using this alias improves code readability and consistency throughout the framework, especially when specifying or configuring verbosity levels for test reporters.

Definition at line 154 of file test-reporter.h.

Enumerations

verbosity

enum class micro_os_plus::micro_test_plus::verbosity
strong

The verbosity levels for test reporting.

Enumeration values
silent (= 0)
quiet (= 1)
normal (= 2)
verbose (= 3)

The verbosity enumeration defines the available levels of detail for test output produced by the reporting system. These levels control the amount and type of information displayed during test execution, allowing users to tailor the output to their specific requirements.

Selecting an appropriate verbosity level enhances the usability of test reports, whether for concise summaries or comprehensive diagnostics.

Definition at line 133 of file test-reporter.h.

134 {
135 silent = 0,
136 quiet = 1,
137 normal = 2,
140 };

Functions

endl()

test_reporter & micro_os_plus::micro_test_plus::endl (test_reporter & stream)

Output stream manipulator for ending a line in test reports.

Parameters
stream

Reference to the test_reporter instance.

Returns

Reference to the same test_reporter instance, enabling chaining of output operations.

The endl function inserts a newline character into the specified test_reporter stream and flushes its output buffer. This operation ensures that each test output line is clearly separated and immediately visible, facilitating the readability and clarity of test results across all test cases and folders within the µTest++ framework.

Definition at line 78 of file test-reporter.cpp.

79 {
80 reporter->endline ();
81 return stream;
82 }

Reference micro_os_plus::micro_test_plus::reporter.

Referenced by micro_os_plus::micro_test_plus::test_reporter_tap::output_fail_prefix_, micro_os_plus::micro_test_plus::test_reporter_basic::output_fail_suffix_, micro_os_plus::micro_test_plus::test_reporter_tap::output_fail_suffix_, micro_os_plus::micro_test_plus::test_reporter_basic::output_pass_suffix_ and micro_os_plus::micro_test_plus::test_reporter_tap::output_pass_suffix_.

Variables

colors_red_green

const colors micro_os_plus::micro_test_plus::colors_red_green
Initialiser
= { "\033[0m", "\033[32m", "\033[31m" }

Definition at line 113 of file test-reporter.h.

114 "\033[0m",
115 "\033[32m",
116 "\033[31m"
117 };

Referenced by micro_os_plus::micro_test_plus::test_reporter_basic::test_reporter_basic.

File Listing

The file content with the documentation metadata removed is:

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 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12 * released under the terms of the Boost Version 1 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
47
48#ifndef MICRO_TEST_PLUS_TEST_REPORTER_H_
49#define MICRO_TEST_PLUS_TEST_REPORTER_H_
50
51// ----------------------------------------------------------------------------
52
53#ifdef __cplusplus
54
55// ----------------------------------------------------------------------------
56
57// #include <functional>
58#include <string_view>
59#include <string>
60
61#include "type-traits.h"
62#include "test-suite.h"
63#include "detail.h"
64
65// ----------------------------------------------------------------------------
66
67#if defined(__GNUC__)
68#pragma GCC diagnostic push
69#pragma GCC diagnostic ignored "-Wpadded"
70#pragma GCC diagnostic ignored "-Waggregate-return"
71#if defined(__clang__)
72#pragma clang diagnostic ignored "-Wc++98-compat"
73#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
74#endif
75#endif
76
78{
79 // --------------------------------------------------------------------------
80
106 struct colors
107 {
108 const char* none = "";
109 const char* pass = "";
110 const char* fail = "";
111 };
112
114 "\033[0m",
115 "\033[32m",
116 "\033[31m"
117 };
118
133 enum class verbosity
134 {
135 silent = 0,
136 quiet = 1,
137 normal = 2,
140 };
141
155
156 // Forward definition.
157 class test_reporter;
158
167 endl (test_reporter& stream);
168
169 // Requires events::assertion_* for and detailed operators.
170
171 class test_runner;
172
203 {
204 public:
208 virtual ~test_reporter ();
209
220 [[nodiscard]] inline auto
221 color (const bool cond)
222 {
223 return cond ? colors_.pass : colors_.fail;
224 }
225
233 operator<<(std::string_view sv);
234
242 operator<<(char c);
243
251 operator<<(const char* s);
252
260 operator<<(char* s);
261
269 operator<<(bool v);
270
275 test_reporter& operator<<(std::nullptr_t);
276
284 operator<<(signed char c);
285
293 operator<<(unsigned char c);
294
302 operator<<(signed short v);
303
311 operator<<(unsigned short v);
312
320 operator<<(signed int v);
321
329 operator<<(unsigned int v);
330
338 operator<<(signed long v);
339
347 operator<<(unsigned long v);
348
356 operator<<(signed long long v);
357
365 operator<<(unsigned long long v);
366
374 operator<<(float v);
375
383 operator<<(double v);
384
392 operator<<(long double v);
393
402 template <typename T>
404 operator<<(T* v);
405
414
415 // ------------------------------------------------------------------------
416 // Specific operators.
417
426 template <class T>
428 operator<<(const T& t);
429
439 template <class T>
442
451 template <class T,
454 = 0>
456 operator<<(T&& t);
457
467 template <class Lhs_T, class Rhs_T>
470
480 template <class Lhs_T, class Rhs_T>
483
493 template <class Lhs_T, class Rhs_T>
496
506 template <class Lhs_T, class Rhs_T>
509
519 template <class Lhs_T, class Rhs_T>
522
532 template <class Lhs_T, class Rhs_T>
535
545 template <class Lhs_T, class Rhs_T>
548
558 template <class Lhs_T, class Rhs_T>
561
570 template <class T>
572 operator<<(const detail::not_<T>& op);
573
574#if defined(__cpp_exceptions)
585 template <class Expr_T, class Exception_T>
588
597 template <class Expr_T>
600
609 template <class Expr_T>
612#endif
613
622 virtual void
623 endline (void)
624 = 0;
625
626 // ------------------------------------------------------------------------
627
638 template <class Expr_T>
639 void
640 pass (Expr_T& expr, std::string& message);
641
654 template <class Expr_T>
655 void
656 fail (Expr_T& expr, bool abort, std::string& message,
657 const reflection::source_location& location);
658
666 virtual void
667 begin_test_case (const char* name)
668 = 0;
669
677 virtual void
678 end_test_case (const char* name)
679 = 0;
680
688 virtual void
689 begin_test_suite (const char* name)
690 = 0;
691
699 virtual void
701 = 0;
702
710 virtual void
711 begin_test (size_t test_suites_count)
712 = 0;
713
721 virtual void
723 = 0;
724
733 virtual void
734 flush (void)
735 = 0;
736
745 virtual void
746 output (void)
747 = 0;
748
756 bool add_empty_line{ true };
757
762
763 protected:
771 virtual void
772 output_pass_prefix_ (std::string& message)
773 = 0;
774
783 virtual void
785 = 0;
786
797 virtual void
798 output_fail_prefix_ (std::string& message, const bool hasExpression,
799 const reflection::source_location& location)
800 = 0;
801
810 virtual void
812 bool abort)
813 = 0;
814
819
823 std::string out_{};
824
828 bool is_in_test_case_ = false;
829 };
830
831 // --------------------------------------------------------------------------
832} // namespace micro_os_plus::micro_test_plus
833
834#if defined(__GNUC__)
835#pragma GCC diagnostic pop
836#endif
837
838// ----------------------------------------------------------------------------
839
840#endif // __cplusplus
841
842// ----------------------------------------------------------------------------
843
844#endif // MICRO_TEST_PLUS_TEST_REPORTER_H_
845
846// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.14.0.