Skip to main content

The test-reporter-inlines.h File Reference

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

Included Headers

#include <stdio.h>
#include <cstring>

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...

Description

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

This header provides the inline implementations for the test reporting facilities used within the µTest++ framework. It defines the logic for formatting and outputting test results, including operator overloads for various value types, containers, and comparison expressions, as well as structured output for logical and exception-related assertions.

The implementations ensure that test outcomes are presented 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::detail 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.

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
48
49#ifndef MICRO_TEST_PLUS_TEST_REPORTER_INLINES_H_
50#define MICRO_TEST_PLUS_TEST_REPORTER_INLINES_H_
51
52// ----------------------------------------------------------------------------
53
54#ifdef __cplusplus
55
56// ----------------------------------------------------------------------------
57
58#include <stdio.h>
59#include <cstring>
60
61// ----------------------------------------------------------------------------
62
63#if defined(__GNUC__)
64#pragma GCC diagnostic push
65#pragma GCC diagnostic ignored "-Waggregate-return"
66#if defined(__clang__)
67#pragma clang diagnostic ignored "-Wc++98-compat"
68#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
69#endif
70#endif
71
73{
74 // --------------------------------------------------------------------------
75
90 template <typename T>
93 {
94 char buff[20];
95 snprintf (buff, sizeof (buff), "%p", reinterpret_cast<void*> (v));
96 out_.append (buff);
97
98 return *this;
99 }
100
101#if 0
110 template <class T>
113 {
114 *this << detail::get (t);
115 return *this;
116 }
117#endif
118
133 template <class T>
136 {
137 out_.append (std::to_string (static_cast<long long> (v.get ())));
138 return *this;
139 }
140
155 template <class T,
160 {
161 *this << '{';
162 auto first = true;
163 for (const auto& arg : t)
164 {
165 *this << (first ? "" : ", ") << arg;
166 first = false;
167 }
168 *this << '}';
169 return *this;
170 }
171
183 template <class Lhs_T, class Rhs_T>
186 {
187 return (*this << color (op) << op.lhs () << " == " << op.rhs ()
188 << colors_.none);
189 }
190
203 template <class Lhs_T, class Rhs_T>
206 {
207 return (*this << color (op) << op.lhs () << " != " << op.rhs ()
208 << colors_.none);
209 }
210
223 template <class Lhs_T, class Rhs_T>
226 {
227 return (*this << color (op) << op.lhs () << " > " << op.rhs ()
228 << colors_.none);
229 }
230
244 template <class Lhs_T, class Rhs_T>
247 {
248 return (*this << color (op) << op.lhs () << " >= " << op.rhs ()
249 << colors_.none);
250 }
251
263 template <class Lhs_T, class Rhs_T>
266 {
267 return (*this << color (op) << op.lhs () << " < " << op.rhs ()
268 << colors_.none);
269 }
270
284 template <class Lhs_T, class Rhs_T>
287 {
288 return (*this << color (op) << op.lhs () << " <= " << op.rhs ()
289 << colors_.none);
290 }
291
304 template <class Lhs_T, class Rhs_T>
307 {
308 return (*this << '(' << op.lhs () << color (op) << " and " << colors_.none
309 << op.rhs () << ')');
310 }
311
324 template <class Lhs_T, class Rhs_T>
327 {
328 return (*this << '(' << op.lhs () << color (op) << " or " << colors_.none
329 << op.rhs () << ')');
330 }
331
340 template <class T>
343 {
344 return (*this << color (op) << "not " << op.value () << colors_.none);
345 }
346
347#if defined(__cpp_exceptions)
360 template <class Expr_T, class Exception_T>
363 {
364 return (*this << color (op) << "throws<"
366 << colors_.none);
367 }
368
379 template <class Expr_T>
382 {
383 return (*this << color (op) << "throws" << colors_.none);
384 }
385
396 template <class Expr_T>
399 {
400 return (*this << color (op) << "nothrow" << colors_.none);
401 }
402#endif
403
417 template <class Expr_T>
418 void
419 test_reporter::pass (Expr_T& expr, std::string& message)
420 {
421 output_pass_prefix_ (message);
422
423 if (message.empty ())
424 {
425 // If there is no message, display the evaluated expression.
426 *this << expr;
427 }
428
430 }
431
441 template <class Expr_T>
442 void
443 test_reporter::fail (Expr_T& expr, bool abort, std::string& message,
444 const reflection::source_location& location)
445 {
446 output_fail_prefix_ (message, location);
447
448 if constexpr (type_traits::is_op_v<Expr_T>)
449 {
450 *this << ", " << expr;
451 }
452
453 output_fail_suffix_ (abort);
454 }
455
456 // --------------------------------------------------------------------------
457} // namespace micro_os_plus::micro_test_plus
458
459#if defined(__GNUC__)
460#pragma GCC diagnostic pop
461#endif
462
463// ----------------------------------------------------------------------------
464
465#endif // __cplusplus
466
467// ----------------------------------------------------------------------------
468
469#endif // MICRO_TEST_PLUS_TEST_REPORTER_INLINES_H_
470
471// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.