Skip to main content

reporter.h File

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

Included Headers

#include "type-traits.h" #include "detail.h" #include "expression-formatter.h" #include "reflection.h" #include <cstdio> #include <string_view> #include <string> #include <memory> #include <vector> #include <charconv> #include "inlines/reporter-inlines.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...

namespacedetail

Internal implementation details for the µTest++ framework. More...

Classes Index

structindent_t

Parameterised stream manipulator for outputting indentation. More...

classreporter

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

Enumerations Index

enum classverbosity { ... }

The verbosity levels for test reporting. More...

Functions Index

reporter &endl (reporter &stream)

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

detail::indent_tindent (size_t level)

Factory function that creates an indent_t manipulator. More...

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.

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 110 of file reporter.h.

111 {
112 silent = 0,
113 quiet = 1,
114 normal = 2,
117 };

Functions

endl()

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

Output stream manipulator for ending a line in test reports.

Parameters
stream

Reference to the reporter instance.

Returns

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

The endl function inserts a newline character into the specified 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 187 of file reporter.cpp.

187 endl (reporter& stream)
188 {
189 stream.endline ();
190 return stream;
191 }

Reference micro_os_plus::micro_test_plus::reporter::endline.

Referenced by micro_os_plus::micro_test_plus::reporter_tap::output_fail_prefix_, micro_os_plus::micro_test_plus::reporter_human::output_fail_suffix_, micro_os_plus::micro_test_plus::reporter_tap::output_fail_suffix_, micro_os_plus::micro_test_plus::reporter_human::output_pass_suffix_ and micro_os_plus::micro_test_plus::reporter_tap::output_pass_suffix_.

indent()

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_OS_PLUS_MICRO_TEST_PLUS_TEST_REPORTER_H_
49#define MICRO_OS_PLUS_MICRO_TEST_PLUS_TEST_REPORTER_H_
50
51// ----------------------------------------------------------------------------
52
53#if defined(__cplusplus)
54
55// ----------------------------------------------------------------------------
56
57#if __has_include("micro-os-plus/project-config.h")
58#include "micro-os-plus/project-config.h"
59#endif // __has_include("micro-os-plus/project-config.h")
60
61#if __has_include("micro-os-plus/micro-test-plus-defines.h")
62#include "micro-os-plus/micro-test-plus-defines.h"
63#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
64
65#include "type-traits.h"
66#include "detail.h"
68#include "reflection.h"
69
70#include <cstdio>
71#include <string_view>
72#include <string>
73#include <memory>
74#include <vector>
75#include <charconv>
76
77// ----------------------------------------------------------------------------
78
79#if defined(__GNUC__)
80#pragma GCC diagnostic push
81
82#pragma GCC diagnostic ignored "-Wpadded"
83#pragma GCC diagnostic ignored "-Waggregate-return"
84#if defined(__clang__)
85#pragma clang diagnostic ignored "-Wc++98-compat"
86#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
87#endif // defined(__clang__)
88#endif // defined(__GNUC__)
89
90// =============================================================================
91
93{
94 // --------------------------------------------------------------------------
95
110 enum class verbosity
111 {
112 silent = 0,
113 quiet = 1,
114 normal = 2,
117 };
118
119 // Forward definitions.
120 class reporter;
121 class runner;
122 class suite;
123 class subtest;
124
132 reporter&
133 endl (reporter& stream);
134
135 namespace detail
136 {
137 // ------------------------------------------------------------------------
138
146 struct indent_t
147 {
148 size_t level;
149 };
150
151 // ------------------------------------------------------------------------
152 } // namespace detail
153
160 [[nodiscard]] detail::indent_t
161 indent (size_t level);
162
163 // ==========================================================================
164
195 {
196 public:
203 reporter (std::unique_ptr<std::vector<std::string_view>> argvs);
204
208 virtual ~reporter ();
209
217 operator<<(std::string_view sv);
218
226 operator<<(char c);
227
235 operator<<(const char* s);
236
244 operator<<(bool v);
245
250 reporter& operator<<(std::nullptr_t);
251
260 template <class T>
261 requires std::is_arithmetic_v<T>
263 operator<<(T v);
264
273 template <typename T>
275 operator<<(T* v);
276
284 operator<<(reporter& (*func) (reporter&));
285
286 // ------------------------------------------------------------------------
287 // Specific operators.
288
289 // ------------------------------------------------------------------------
290
299 void
300 endline (void);
301
315 void
317
326 void
327 flush (void);
328
329 // ------------------------------------------------------------------------
330
340 void
341 pass (std::string& message, const std::string& expression,
343
357 void
358 fail (bool abort, std::string& message, const std::string& expression,
359 bool has_expression, const reflection::source_location& location,
361
362 // ------------------------------------------------------------------------
363
371 virtual void
373 = 0;
374
382 virtual void
384 = 0;
385
393 virtual void
395 = 0;
396
404 virtual void
406 = 0;
407
415 virtual void
417 = 0;
418
426 virtual void
428 = 0;
429
437 virtual const char*
439 = 0;
440
448 auto
450
459 detail::expression_formatter&
460 expression ();
461
462 // ------------------------------------------------------------------------
463
464 protected:
471 [[nodiscard]] inline auto
472 colour_ (const bool cond) const;
473
474 void
476
485 void
486 write_info_ (void);
487
496 virtual void
497 output_pass_prefix_ (std::string& message, subtest& subtest)
498 = 0;
499
507 virtual void
509 = 0;
510
522 virtual void
523 output_fail_prefix_ (std::string& message, const bool has_expression,
524 const reflection::source_location& location,
526 = 0;
527
537 virtual void
538 output_fail_suffix_ (const reflection::source_location& location,
539 bool abort, subtest& subtest)
540 = 0;
541
542 protected:
547
551 detail::colours colours_{};
552
561 std::string buffer_{};
562
573
581 bool add_empty_line_{ true };
582
590 const char* output_file_path_{ nullptr };
591
600 FILE* output_file_{ nullptr };
601
605 std::unique_ptr<std::vector<std::string_view>> argvs_{};
606 };
607
608 // --------------------------------------------------------------------------
609} // namespace micro_os_plus::micro_test_plus
610
611#if defined(__GNUC__)
612#pragma GCC diagnostic pop
613#endif // defined(__GNUC__)
614
615// ----------------------------------------------------------------------------
616
617#endif // defined(__cplusplus)
618
619// ============================================================================
620// Templates, inlines & constexpr implementations.
621
623
624// ----------------------------------------------------------------------------
625
626#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TEST_REPORTER_H_
627
628// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.