Skip to main content

The test-reporter.h File Reference

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_os_plus::micro_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...

Enumerations Index

enum classverbosity

The verbosity levels for test reporting. More...

Typedefs Index

usingverbosity_t = verbosity

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

Functions Index

test_reporter &endl (test_reporter &stream)

Output stream manipulator for ending a line in test reports. 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 127 of file test-reporter.h.

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

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
streamReference 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 73 of file test-reporter.cpp.

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 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any 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
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&#95;1&#95;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 = "\033[0m";
109 const char* pass = "\033[32m";
110 const char* fail = "\033[31m";
111 };
112
127 enum class verbosity
128 {
129 silent = 0,
130 quiet = 1,
131 normal = 2,
134 };
135
149
150 // Forward definition.
151 class test_reporter;
152
161 endl (test_reporter& stream);
162
163 // Requires events::assertion_* for and detailed operators.
164
195 {
196 public:
200 test_reporter () = default;
201
212 [[nodiscard]] inline auto
213 color (const bool cond)
214 {
215 return cond ? colors_.pass : colors_.fail;
216 }
217
225 operator<<(std::string_view sv);
226
234 operator<<(char c);
235
243 operator<<(const char* s);
244
252 operator<<(char* s);
253
261 operator<<(bool v);
262
267 test_reporter& operator<<(std::nullptr_t);
268
276 operator<<(signed char c);
277
285 operator<<(unsigned char c);
286
294 operator<<(signed short v);
295
303 operator<<(unsigned short v);
304
312 operator<<(signed int v);
313
321 operator<<(unsigned int v);
322
330 operator<<(signed long v);
331
339 operator<<(unsigned long v);
340
348 operator<<(signed long long v);
349
357 operator<<(unsigned long long v);
358
366 operator<<(float v);
367
375 operator<<(double v);
376
384 operator<<(long double v);
385
394 template <typename T>
396 operator<<(T* v);
397
406
407 // ------------------------------------------------------------------------
408 // Specific operators.
409
418 template <class T>
420 operator<<(const T& t);
421
431 template <class T>
434
443 template <class T,
446 = 0>
448 operator<<(T&& t);
449
459 template <class Lhs_T, class Rhs_T>
462
472 template <class Lhs_T, class Rhs_T>
475
485 template <class Lhs_T, class Rhs_T>
488
498 template <class Lhs_T, class Rhs_T>
501
511 template <class Lhs_T, class Rhs_T>
514
524 template <class Lhs_T, class Rhs_T>
527
537 template <class Lhs_T, class Rhs_T>
540
550 template <class Lhs_T, class Rhs_T>
553
562 template <class T>
564 operator<<(const detail::not_<T>& op);
565
566#if defined(__cpp_exceptions)
577 template <class Expr_T, class Exception_T>
580
589 template <class Expr_T>
592
601 template <class Expr_T>
604#endif
605
614 void
615 endline (void);
616
617 // ------------------------------------------------------------------------
618
629 template <class Expr_T>
630 void
631 pass (Expr_T& expr, std::string& message);
632
645 template <class Expr_T>
646 void
647 fail (Expr_T& expr, bool abort, std::string& message,
648 const reflection::source_location& location);
649
657 void
658 begin_test_case (const char* name);
659
667 void
668 end_test_case (const char* name);
669
677 void
678 begin_test_suite (const char* name);
679
687 void
689
698 void
699 flush (void);
700
709 void
710 output (void);
711
719 bool add_empty_line{ true };
720
725
726 protected:
734 void
735 output_pass_prefix_ (std::string& message);
736
745 void
747
756 void
757 output_fail_prefix_ (std::string& message,
758 const reflection::source_location& location);
759
767 void
768 output_fail_suffix_ (bool abort);
769
774
778 std::string out_{};
779
783 bool is_in_test_case_ = false;
784 };
785
786 // --------------------------------------------------------------------------
787} // namespace micro_os_plus::micro_test_plus
788
789#if defined(__GNUC__)
790#pragma GCC diagnostic pop
791#endif
792
793// ----------------------------------------------------------------------------
794
795#endif // __cplusplus
796
797// ----------------------------------------------------------------------------
798
799#endif // MICRO_TEST_PLUS_TEST_REPORTER_H_
800
801// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.