Skip to main content

reporter.h File

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

Included Headers

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

102 {
103 silent = 0,
104 quiet = 1,
105 normal = 2,
108 };

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 206 of file reporter.cpp.

206 endl (reporter& stream)
207 {
208 stream.endline ();
209 return stream;
210 }

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_TEST_PLUS_TEST_REPORTER_H_
49#define MICRO_TEST_PLUS_TEST_REPORTER_H_
50
51// ----------------------------------------------------------------------------
52
53#ifdef __cplusplus
54
55// ----------------------------------------------------------------------------
56
57#include <cstdio>
58#include <string_view>
59#include <string>
60#include <memory>
61#include <vector>
62#include <charconv>
63
64#include "type-traits.h"
65#include "detail.h"
67#include "reflection.h"
68
69// ----------------------------------------------------------------------------
70
71#if defined(__GNUC__)
72#pragma GCC diagnostic push
73#pragma GCC diagnostic ignored "-Wpadded"
74#pragma GCC diagnostic ignored "-Waggregate-return"
75#if defined(__clang__)
76#pragma clang diagnostic ignored "-Wc++98-compat"
77#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
78#endif
79#endif
80
81// =============================================================================
82
84{
85 // --------------------------------------------------------------------------
86
101 enum class verbosity
102 {
103 silent = 0,
104 quiet = 1,
105 normal = 2,
108 };
109
110 // Forward definitions.
111 class reporter;
112 class runner;
113 class suite;
114 class subtest;
115
123 reporter&
124 endl (reporter& stream);
125
126 namespace detail
127 {
128 // ------------------------------------------------------------------------
129
137 struct indent_t
138 {
139 size_t level;
140 };
141
142 // ------------------------------------------------------------------------
143 } // namespace detail
144
151 [[nodiscard]] detail::indent_t
152 indent (size_t level);
153
154 // ==========================================================================
155
186 {
187 public:
194 reporter (std::unique_ptr<std::vector<std::string_view>> argvs);
195
199 virtual ~reporter ();
200
208 operator<<(std::string_view sv);
209
217 operator<<(char c);
218
226 operator<<(const char* s);
227
235 operator<<(bool v);
236
241 reporter& operator<<(std::nullptr_t);
242
251 template <class T>
252 requires std::is_arithmetic_v<T>
254 operator<<(T v);
255
264 template <typename T>
266 operator<<(T* v);
267
275 operator<<(reporter& (*func) (reporter&));
276
277 // ------------------------------------------------------------------------
278 // Specific operators.
279
280 // ------------------------------------------------------------------------
281
290 void
291 endline (void);
292
306 void
308
317 void
318 flush (void);
319
320 // ------------------------------------------------------------------------
321
331 void
332 pass (std::string& message, const std::string& expression,
334
348 void
349 fail (bool abort, std::string& message, const std::string& expression,
350 bool has_expression, const reflection::source_location& location,
352
353 // ------------------------------------------------------------------------
354
362 virtual void
364 = 0;
365
373 virtual void
375 = 0;
376
384 virtual void
386 = 0;
387
395 virtual void
397 = 0;
398
406 virtual void
408 = 0;
409
417 virtual void
419 = 0;
420
428 virtual const char*
430 = 0;
431
439 auto
441
450 detail::expression_formatter&
451 expression ();
452
453 // ------------------------------------------------------------------------
454
455 protected:
462 [[nodiscard]] inline auto
463 colour_ (const bool cond) const;
464
465 void
467
476 void
477 write_info_ (void);
478
487 virtual void
488 output_pass_prefix_ (std::string& message, subtest& subtest)
489 = 0;
490
498 virtual void
500 = 0;
501
513 virtual void
514 output_fail_prefix_ (std::string& message, const bool has_expression,
515 const reflection::source_location& location,
517 = 0;
518
528 virtual void
529 output_fail_suffix_ (const reflection::source_location& location,
530 bool abort, subtest& subtest)
531 = 0;
532
533 protected:
538
542 detail::colours colours_{};
543
552 std::string buffer_{};
553
564
572 bool add_empty_line_{ true };
573
581 const char* output_file_path_{ nullptr };
582
591 FILE* output_file_{ nullptr };
592
596 std::unique_ptr<std::vector<std::string_view>> argvs_{};
597 };
598
599 // --------------------------------------------------------------------------
600} // namespace micro_os_plus::micro_test_plus
601
602#if defined(__GNUC__)
603#pragma GCC diagnostic pop
604#endif
605
606// ----------------------------------------------------------------------------
607
608#endif // __cplusplus
609
610// ============================================================================
611// Templates & constexpr implementations.
612
614
615// ----------------------------------------------------------------------------
616
617#endif // MICRO_TEST_PLUS_TEST_REPORTER_H_
618
619// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.