Skip to main content

extension.h File

C++ header file with declarations for the µTest++ extension concepts. More...

Included Headers​

#include <concepts> #include <iterator> #include <memory> #include <optional> #include <string_view> #include <type_traits> #include <utility>

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

namespaceextension

The templates and the concepts for extending the µTest++ testing framework. More...

Classes Index​

structis_bool_wrapper<T>

Trait marking the wrappers of a bool, whose condition is ambiguous. More...

structop

Empty base struct for the framework expression types. More...

structrange_element<T>

The type of the elements of a range with begin() and end() members. More...

Concepts Index​

conceptambiguous_condition

Concept satisfied by the wrappers of a bool, whose condition is ambiguous. More...

conceptcontainer_like

Concept satisfied when T provides both begin() and end() member functions returning an iterator and its sentinel. More...

conceptformattable_range

Concept satisfied when T is a range that the formatter writes element by element. More...

conceptfree_range

Concept satisfied when T provides begin() and end() only as functions found by argument-dependent lookup. More...

concepthas_value

Concept satisfied when T is a framework compile-time constant. More...

conceptlazy_message

Concept satisfied when T is a callable object that returns a printable message. More...

conceptlegacy_checkable

Concept satisfied when a type was accepted by expect() and require() before the exclusion of the suspicious conditions. More...

conceptmessage_argument

Concept satisfied when T can be appended to the message of a check. More...

conceptstring_like

Concept satisfied when T is a string, convertible to a std::basic_string_view of a character type. More...

conceptsuspicious_condition

Concept satisfied when a type is contextually convertible to bool, but is most likely not a condition. More...

conceptany_op

Concept satisfied when at least one of two types is a framework expression type. More...

conceptcheckable

Concept satisfied when a type can be used as a test expression in expect() or require(). More...

conceptcompare_tag

Concept satisfied by a tag that defines a custom comparator. More...

concepthas_epsilon

Deprecated concept satisfied when T is a framework floating-point wrapper with a tolerance. More...

conceptis_op

Concept satisfied when a type is a framework expression type. More...

conceptpredicate_tag

Concept satisfied by a tag that defines a custom predicate. More...

conceptprintable

Concept satisfied when a type can be appended to the message of a check result via operator<<. More...

Description​

C++ header file with declarations for the µTest++ extension concepts.

This header provides the C++20 concepts that the applications use to extend the framework with their own comparators, operators, and helpers (the expressions they return, extension::compare_op and extension::predicate_op, are declared in detail.h): the concepts that detect the framework expression types, and the types accepted by expect(), require(), and the message operator.

The public concepts, and the templates compare_op and predicate_op, reside within the micro_os_plus::micro_test_plus::extension namespace, separate from the top namespace, so that using namespace on the top namespace does not bring their generic names into the application code.

The concepts used only by the implementation, which detect the framework constants, the containers, and the strings, reside within the detail namespace.

The marker base detail::op of the framework expression types is defined here; the deprecated value wrappers, in the detail namespace, are declared in deprecated.h.

The deprecated v5.0.1 type_traits namespace, which refers to these concepts and to the value wrappers, is declared in deprecated.h.

This file is included by micro-os-plus/micro-test-plus.h, which is the header that the applications include.

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.0 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
50
51#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_EXTENSION_H_
52#define MICRO_OS_PLUS_MICRO_TEST_PLUS_EXTENSION_H_
53
54// ----------------------------------------------------------------------------
55
56#if defined(__cplusplus)
57
58// ----------------------------------------------------------------------------
59
60#if __has_include("micro-os-plus/project-config.h")
61#include "micro-os-plus/project-config.h"
62#endif // __has_include("micro-os-plus/project-config.h")
63
64#if __has_include("micro-os-plus/micro-test-plus-defines.h")
65#include "micro-os-plus/micro-test-plus-defines.h"
66#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
67
68#include <concepts>
69#include <iterator>
70#include <memory>
71#include <optional>
72#include <string_view>
73#include <type_traits>
74#include <utility>
75
76// ----------------------------------------------------------------------------
77
78#if defined(__GNUC__)
79#pragma GCC diagnostic push
80
81#if defined(__clang__)
82#pragma clang diagnostic ignored "-Wc++98-compat"
83#pragma clang diagnostic ignored "-Wdocumentation"
84#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
85#endif // defined(__clang__)
86#endif // defined(__GNUC__)
87
88// ============================================================================
89
91{
92 // --------------------------------------------------------------------------
93
94 namespace detail
95 {
96 // Forward definitions.
98
99 // ========================================================================
100
119 struct op
120 {
128 using op_type = op;
129 };
130
131 // ------------------------------------------------------------------------
132
144 template <class T>
145 struct is_bool_wrapper : std::false_type
146 {
147 };
148
158 template <class T>
159 requires std::is_same_v<std::remove_cv_t<T>, bool>
160 struct is_bool_wrapper<std::optional<T>> : std::true_type
161 {
162 };
163
174 template <class T, class Deleter_T>
175 requires std::is_same_v<std::remove_cv_t<T>, bool>
176 struct is_bool_wrapper<std::unique_ptr<T, Deleter_T>> : std::true_type
177 {
178 };
179
189 template <class T>
190 requires std::is_same_v<std::remove_cv_t<T>, bool>
191 struct is_bool_wrapper<std::shared_ptr<T>> : std::true_type
192 {
193 };
194
215 template <class T>
217
218 // ------------------------------------------------------------------------
219
237 template <class T>
239 = std::is_array_v<T> or std::is_function_v<T>
240 or std::is_member_pointer_v<T>
241 or (std::is_pointer_v<T>
242 and (std::is_function_v<std::remove_pointer_t<T>>
243 or std::is_same_v<
244 std::remove_cv_t<std::remove_pointer_t<T>>, char>
245 or std::is_same_v<
246 std::remove_cv_t<std::remove_pointer_t<T>>, wchar_t>
247 or std::is_same_v<
248 std::remove_cv_t<std::remove_pointer_t<T>>, char8_t>
249 or std::is_same_v<
250 std::remove_cv_t<std::remove_pointer_t<T>>, char16_t>
251 or std::is_same_v<
252 std::remove_cv_t<std::remove_pointer_t<T>>, char32_t>));
253
254 // ------------------------------------------------------------------------
255 } // namespace detail
256
257 // --------------------------------------------------------------------------
258
291 namespace extension
292 {
293 // ------------------------------------------------------------------------
294 // Concepts.
295
318 template <class T>
319 concept is_op
320 = requires { requires std::same_as<typename T::op_type, detail::op>; };
321
322#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
348 template <class T>
349 concept has_epsilon = is_op<T> and requires (const T& t) { t.epsilon; };
350#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
351
368 template <class Lhs_T, class Rhs_T>
370
402 template <class T>
406 and requires (const T& t) { t ? true : false; });
407
432 template <class T>
433 concept printable = requires (detail::expression_formatter& formatter,
434 const T& value) { formatter << value; };
435
455 template <class Tag_T, class Lhs_T, class Rhs_T>
456 concept compare_tag = requires (const Lhs_T& lhs, const Rhs_T& rhs) {
457 requires printable<std::remove_cvref_t<decltype (Tag_T::symbol)>>;
458 { Tag_T::apply (lhs, rhs) } -> std::convertible_to<bool>;
459 };
460
476 template <class Tag_T, class T>
477 concept predicate_tag = requires (const T& operand) {
478 requires printable<std::remove_cvref_t<decltype (Tag_T::symbol)>>;
479 { Tag_T::apply (operand) } -> std::convertible_to<bool>;
480 };
481
482 // ------------------------------------------------------------------------
483 } // namespace extension
484
485 // --------------------------------------------------------------------------
486
487 namespace detail
488 {
489
490#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
504 template <class T>
507 and requires (const T& t) { t ? true : false; };
508#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
509
510 // ------------------------------------------------------------------------
511 // Concepts used only by the implementation.
512
531 template <class T>
532 concept container_like = requires (const T& t) {
533 requires std::input_or_output_iterator<decltype (t.begin ())>;
534 requires std::sentinel_for<decltype (t.end ()), decltype (t.begin ())>;
535 };
536
552 template <class T>
554 = std::convertible_to<const T&, std::basic_string_view<char>>
555 or std::convertible_to<const T&, std::basic_string_view<wchar_t>>
556 or std::convertible_to<const T&, std::basic_string_view<char8_t>>
557 or std::convertible_to<const T&, std::basic_string_view<char16_t>>
558 or std::convertible_to<const T&, std::basic_string_view<char32_t>>;
559
573 template <class T>
574 concept free_range = (not container_like<T>) and requires (const T& t) {
575 requires std::input_or_output_iterator<decltype (begin (t))>;
576 requires std::sentinel_for<decltype (end (t)), decltype (begin (t))>;
577 };
578
591 template <class T>
593
600 template <class T>
601 requires container_like<T>
602 struct range_element<T>
603 {
611 using type = std::remove_cvref_t<
612 decltype (*std::declval<const T&> ().begin ())>;
613 };
614
621 template <class T>
622 requires free_range<T>
623 struct range_element<T>
624 {
633 using type
634 = std::remove_cvref_t<decltype (*begin (std::declval<const T&> ()))>;
635 };
636
664 template <class T>
666 = (container_like<T> or free_range<T>) and (not std::is_array_v<T>)
667 and (not string_like<T>)
668 and (not std::is_same_v<typename range_element<T>::type, T>)
669 and extension::printable<typename range_element<T>::type>;
670
692 template <class T>
694 = std::is_class_v<T> and std::invocable<const T&>
695 and (not std::is_void_v<std::invoke_result_t<const T&>>)
696 and extension::printable<std::invoke_result_t<const T&>>;
697
713 template <class T>
715 = lazy_message<T>
716 or (extension::printable<T>
717 and not(std::is_class_v<T> and std::invocable<const T&>));
718
719#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
737 template <class T>
738 concept has_value = extension::is_op<T> and requires { T::value; };
739#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
740
741 // ------------------------------------------------------------------------
742 } // namespace detail
743
744 // --------------------------------------------------------------------------
745} // namespace micro_os_plus::micro_test_plus
746
747#if defined(__GNUC__)
748#pragma GCC diagnostic pop
749#endif // defined(__GNUC__)
750
751// ----------------------------------------------------------------------------
752
753#endif // defined(__cplusplus)
754
755// ----------------------------------------------------------------------------
756
757#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_EXTENSION_H_
758
759// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.