micro-test-plus 6.0.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
check-result.h
Go to the documentation of this file.
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
12// ----------------------------------------------------------------------------
13
36
37#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_CHECK_RESULT_H_
38#define MICRO_OS_PLUS_MICRO_TEST_PLUS_CHECK_RESULT_H_
39
40// ----------------------------------------------------------------------------
41
42#if defined(__cplusplus)
43
44// ----------------------------------------------------------------------------
45
46#if __has_include("micro-os-plus/project-config.h")
47#include "micro-os-plus/project-config.h"
48#endif // __has_include("micro-os-plus/project-config.h")
49
50#if __has_include("micro-os-plus/micro-test-plus-defines.h")
51#include "micro-os-plus/micro-test-plus-defines.h"
52#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
53
55#include "extension.h"
56#include "reflection.h"
57
58#include <cstdio>
59#include <string>
60
61// ----------------------------------------------------------------------------
62
63#if defined(__GNUC__)
64#pragma GCC diagnostic push
65
66#pragma GCC diagnostic ignored "-Wpadded"
67#pragma GCC diagnostic ignored "-Waggregate-return"
68#if defined(__clang__)
69#pragma clang diagnostic ignored "-Wc++98-compat"
70#endif // defined(__clang__)
71#endif // defined(__GNUC__)
72
73// ============================================================================
74
76{
77 class test_case;
78
79 // --------------------------------------------------------------------------
80
81 namespace detail
82 {
83 // ========================================================================
84
93 enum class check_kind
94 {
102
111 };
112
113 // ========================================================================
114
162
163 // ========================================================================
164
209 {
210 public:
221
243 template <class Expr_T>
244 void
245 init (const Expr_T& expr, check_kind kind,
247 expression_formatter& expression, bool writes_passed);
248
256 check_result (const check_result&) = delete;
257
267
276 = delete;
277
286 = delete;
287
295 ~check_result () noexcept (false);
296
317 template <class T>
318 requires detail::message_argument<T>
320 operator<< (const T& msg) &&;
321
322#if !defined(__DOXYGEN__)
337 template <class T>
338 requires (not detail::message_argument<T>)
340 operator<< (const T& msg) &&;
341#endif // !defined(__DOXYGEN__)
342
355 [[nodiscard]] bool
356 value (void) const&& noexcept;
357
358 private:
378 void
379 start (bool value, check_kind kind, bool has_expression,
381 bool writes_passed);
382
390 bool value_ = false;
391
401 bool is_written_ = false;
402
413
424#if defined(__cpp_exceptions)
426#endif // defined(__cpp_exceptions)
427
437 };
438
439 // ------------------------------------------------------------------------
440 } // namespace detail
441
442 // --------------------------------------------------------------------------
443} // namespace micro_os_plus::micro_test_plus
444
445#if defined(__GNUC__)
446#pragma GCC diagnostic pop
447#endif // defined(__GNUC__)
448
449// ----------------------------------------------------------------------------
450
451#endif // defined(__cplusplus)
452
453// ============================================================================
454// Templates, inlines & constexpr implementations.
455
457
458// ----------------------------------------------------------------------------
459
460#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_CHECK_RESULT_H_
461
462// ----------------------------------------------------------------------------
C++ header file with inline implementations for the µTest++ check result.
bool value(void) const &&noexcept
Retrieves the result value.
check_result & operator=(const check_result &)=delete
Deleted copy assignment operator to prevent copying.
int uncaught_exceptions_
The number of uncaught exceptions when the check was created.
test_case * test_case_
Pointer to the test case invoking this check.
void start(bool value, check_kind kind, bool has_expression, const reflection::source_location &location, test_case &test_case, bool writes_passed)
Starts the result of a check from its parts.
check_result(void)
Constructs a result in the initial state.
bool is_written_
Whether the outcome of the check is written.
check_result && operator<<(const T &msg) &&
Appends a message to the check.
void init(const Expr_T &expr, check_kind kind, const reflection::source_location &location, test_case &test_case, expression_formatter &expression, bool writes_passed)
Initialises the result with the check of an expression.
check_result(check_result &&)=delete
Deleted move constructor to prevent moving.
check_result(const check_result &)=delete
Deleted copy constructor to prevent copying.
bool value_
Stores the result value of the check.
failure_info info_
The details displayed when the check fails.
Formats values and expressions into an owned string buffer.
Local implementation of source location information for diagnostics.
Definition reflection.h:143
A named, runnable test case that lives inside a suite.
Definition test.h:1362
Concept satisfied when T can be appended to the message of a check.
Definition extension.h:715
C++ header file with declarations for the µTest++ expression formatter.
C++ header file with declarations for the µTest++ extension concepts.
Internal implementation details for the µTest++ framework.
check_kind
The kind of a check, which determines what happens when it fails.
Primary namespace for the µTest++ testing framework.
C++ header file with declarations for the µTest++ reflection utilities.
The details of a check, displayed when it fails.
bool has_expression
Indicates whether the check has an associated expression.
reflection::source_location location
The source location of the check.
std::string message
The message passed via operator<<(), if any.
constexpr value(const T &_value) noexcept
Constructs a value object with the specified value.