micro-test-plus 6.0.1
µTest++ Testing Framework
Loading...
Searching...
No Matches
test.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 * 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
39
40#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_TEST_H_
41#define MICRO_OS_PLUS_MICRO_TEST_PLUS_TEST_H_
42
43// ----------------------------------------------------------------------------
44
45#if defined(__cplusplus)
46
47// ----------------------------------------------------------------------------
48
49#if __has_include("micro-os-plus/project-config.h")
50#include "micro-os-plus/project-config.h"
51#endif // __has_include("micro-os-plus/project-config.h")
52
53#if __has_include("micro-os-plus/micro-test-plus-defines.h")
54#include "micro-os-plus/micro-test-plus-defines.h"
55#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
56
57#include "check-result.h"
58#include "counters.h"
59#include "extension.h"
60#include "stopwatch.h"
61#include "reflection.h"
62
63#include <cstddef>
64#include <functional>
65#include <initializer_list>
66#include <memory>
67#include <string>
68#include <string_view>
69#include <tuple>
70#include <type_traits>
71#include <utility>
72
73// ----------------------------------------------------------------------------
74
75#if defined(__GNUC__)
76#pragma GCC diagnostic push
77
78#pragma GCC diagnostic ignored "-Waggregate-return"
79#pragma GCC diagnostic ignored "-Wpadded"
80#if defined(__clang__)
81#pragma clang diagnostic ignored "-Wc++98-compat"
82#pragma clang diagnostic ignored "-Wc++98-compat-bind-to-temporary-copy"
83#pragma clang diagnostic ignored "-Wdocumentation"
84#else // GCC only
85#pragma GCC diagnostic ignored "-Wsuggest-final-types"
86#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
87#pragma GCC diagnostic ignored "-Wredundant-tags"
88#endif // defined(__clang__)
89#endif // defined(__GNUC__)
90
91// ============================================================================
92
94{
95 // --------------------------------------------------------------------------
96
97 class counters;
98 class runner;
99 class test_case;
100
101 namespace detail
102 {
114 void
115 escape_control_characters (std::string& name);
116 } // namespace detail
117 class suite;
118 class top_suite;
119 class static_suite;
120
121 // --------------------------------------------------------------------------
122
177 {
178 public:
195 template <typename Pointer_T>
196 requires (std::is_same_v<Pointer_T, const char*>
197 or std::is_same_v<Pointer_T, char*>
198 or std::is_null_pointer_v<Pointer_T>)
201
218 template <std::size_t N>
219 located_name (const char (&name)[N],
222
231 located_name (const std::string& name,
234
243 located_name (std::string&& name,
246
256 located_name (std::string_view name,
259
268 [[nodiscard]] const char*
269 name (void) const noexcept;
270
278 [[nodiscard]] const reflection::source_location&
279 location (void) const noexcept;
280
281 private:
289 std::string name_;
290
299 };
300
301 // --------------------------------------------------------------------------
302
303 namespace detail
304 {
305 class check_result;
306 class reporter;
307 class reporter_human;
308 class reporter_tap;
309
310 // ========================================================================
311
349 {
358
366 friend class check_result;
367
375 friend class reporter_human;
376
385 friend class reporter_tap;
386
387 public:
396 runnable_base (const char* name, runner& test_runner, size_t own_index);
397
404 runnable_base (const runnable_base&) = delete;
405
414
423 = delete;
424
434 = delete;
435
442 virtual ~runnable_base ();
443
444 // ----------------------------------------------------------------------
445
453 [[nodiscard]] const char*
454 name (void) const noexcept;
455
470 [[nodiscard]] const counters&
471 totals (void) const noexcept;
472
473#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
478
492 [[deprecated ("internal to the framework (since 6.0.0)"),
493 nodiscard]] size_t
494 own_index (void) const noexcept;
495
508 [[deprecated ("internal to the framework (since 6.0.0)"),
509 nodiscard]] size_t
510 current_subtest_index (void) const noexcept;
511
523 [[deprecated ("internal to the framework (since 6.0.0)"),
524 nodiscard]] size_t
525 children_subtests_count (void) const noexcept;
526
530#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
531
532 private:
550 virtual void
551 run (void)
552 = 0;
553
567 [[noreturn]] void
570
571 protected:
588 [[nodiscard]] runner&
589 test_runner (void) const noexcept;
590
606 [[nodiscard]] class reporter&
607 test_reporter (void) const noexcept;
608
623 [[nodiscard]] class test_case*
624 running_test_case (void) const noexcept;
625
642 [[nodiscard]] bool
643 has_running_test_case_of (const suite& target) const noexcept;
644
658 [[nodiscard]] bool
659 is_aborted (void) const noexcept;
660
674 [[nodiscard]] bool
675 is_listing (void) const noexcept;
676
691 suite*
692 exchange_running_suite (suite* running) noexcept;
693
720 [[nodiscard]] bool
721 accepts_test_case (const suite& target, const located_name& name);
722
738 void
740
753 size_t
754 next_test_point_number (void) noexcept;
755
770 void
772
808 template <typename Callable_T, typename... Args_T>
809 [[gnu::always_inline]] void
810 create_test_case (const located_name& name, suite& parent_suite,
811 size_t nesting_depth, Callable_T&& callable,
812 Args_T&&... arguments);
813
814 protected:
823 const char* name_;
824
839
849
860
872
884 };
885
886 // ========================================================================
887
914 template <typename Self_T, typename Callable_T, typename... Args_T>
915 [[nodiscard]] auto
916 bind_callable (Callable_T&& callable, Args_T&&... arguments);
917
918 // ========================================================================
919
942 template <typename Self_T, typename Callable_T, typename... Args_T>
944 {
945 public:
968 template <typename C, typename... A>
969 requires (sizeof...(A) > 0)
970 constexpr explicit bound_callable (C&& callable, A&&... arguments);
971
983 [[gnu::always_inline]] void
984 operator() (Self_T& self);
985
986 private:
1000 template <std::size_t... Is>
1001 [[gnu::always_inline]] void
1002 invoke (Self_T& self, std::index_sequence<Is...>);
1003
1011 Callable_T callable_;
1012
1020 std::tuple<Args_T...> arguments_;
1021 };
1022
1023 // ========================================================================
1024
1045 template <typename Self_T>
1047 {
1048 public:
1065 template <typename Callable_T>
1066 requires (!std::is_same_v<std::remove_cv_t<Callable_T>,
1068 explicit callable_ref (Callable_T& callable) noexcept;
1069
1084 [[gnu::always_inline]] void
1085 operator() (Self_T& self) const;
1086
1087 private:
1102 template <typename Callable_T>
1103 static void
1104 invoke_callable (void* callable, Self_T& self);
1105
1113
1121 void (*invoke_) (void* callable, Self_T& self);
1122 };
1123
1124 // ------------------------------------------------------------------------
1125
1138 template <class T>
1139 concept test_values_range = std::is_array_v<std::remove_cvref_t<T>>
1142
1154 template <class T>
1155 concept test_values_tuple = (not test_values_range<T>) and requires {
1156 std::tuple_size<std::remove_cvref_t<T>>::value;
1157 };
1158
1175 template <typename Callable_T>
1177 = std::is_class_v<std::decay_t<Callable_T>>
1178 && (!requires { &std::decay_t<Callable_T>::operator(); });
1179
1196 template <typename Callable_T, typename... Args_T>
1199 || std::is_invocable_v<std::decay_t<Callable_T>&, test_case&,
1200 std::decay_t<Args_T>&...>;
1201
1215 template <typename Callable_T, typename... Args_T>
1218 || std::is_invocable_v<std::decay_t<Callable_T>&, suite&,
1219 std::decay_t<Args_T>&...>)
1220 && std::is_copy_constructible_v<std::decay_t<Callable_T>>
1221 && (std::is_copy_constructible_v<std::decay_t<Args_T>> && ...);
1222
1237 template <class T>
1241#else
1243#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
1244
1257 template <typename... Ts>
1258 inline constexpr bool dependent_false_v = false;
1259
1278 template <typename Callable_T, typename... Args_T>
1279 constexpr void
1280 reject_test_body (void) noexcept;
1281
1298 template <typename Callable_T, typename... Args_T>
1299 constexpr void
1300 reject_suite_body (void) noexcept;
1301
1322 template <class Self_T, class Values_T, class Callable_T>
1323 void
1324 test_each_value (Self_T& self, const located_name& name, Values_T&& values,
1325 Callable_T& callable);
1326
1327 // ------------------------------------------------------------------------
1328 } // namespace detail
1329
1330 // ==========================================================================
1331
1362 {
1374
1383
1384 private:
1406 suite& parent_suite, size_t own_index, size_t nesting_depth,
1408
1409 public:
1416 test_case (const test_case&) = delete;
1417
1425 test_case (test_case&&) = delete;
1426
1433 test_case&
1435 = delete;
1436
1444 test_case&
1446 = delete;
1447
1455 ~test_case () override;
1456
1457 // ------------------------------------------------------------------------
1458
1486 template <typename Callable_T, typename... Args_T>
1487 requires detail::test_body<Callable_T, Args_T...>
1488 void
1489 test (const located_name& name, Callable_T&& callable,
1490 Args_T&&... arguments);
1491
1492#if !defined(__DOXYGEN__)
1511 template <typename Callable_T, typename... Args_T>
1512 requires (!detail::test_body<Callable_T, Args_T...>)
1513 void
1514 test (const located_name& name, Callable_T&& callable,
1515 Args_T&&... arguments);
1516#endif // !defined(__DOXYGEN__)
1517
1561 template <typename Values_T, typename Callable_T>
1564 void
1565 test_each (const located_name& name, Values_T&& values,
1566 Callable_T&& callable);
1567
1589 template <typename T, typename Callable_T>
1590 void
1591 test_each (const located_name& name, std::initializer_list<T> values,
1592 Callable_T&& callable);
1593
1594 // ------------------------------------------------------------------------
1595
1625 template <class Expr_T>
1628 expect (const Expr_T& expr,
1632
1633#if !defined(__DOXYGEN__)
1653 template <class Expr_T>
1656 expect (const Expr_T& expr,
1660#endif // !defined(__DOXYGEN__)
1661
1704 template <class Expr_T>
1705 requires extension::checkable<Expr_T>
1706 detail::check_result&&
1707 require (const Expr_T& expr,
1708 const reflection::source_location& sl
1710 detail::check_result&& result = detail::check_result{});
1711
1712#if !defined(__DOXYGEN__)
1732 template <class Expr_T>
1733 requires detail::unsupported_condition<Expr_T>
1734 detail::check_result&&
1735 require (const Expr_T& expr,
1736 const reflection::source_location& sl
1738 detail::check_result&& result = detail::check_result{});
1739#endif // !defined(__DOXYGEN__)
1740
1741#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
1746
1768 template <class Expr_T>
1769 requires detail::legacy_checkable<Expr_T>
1770 [[deprecated ("the argument is always true; write the condition "
1771 "(since 6.0.0)")]] detail::check_result&&
1772 expect (const Expr_T& expr,
1776
1795 template <class Expr_T>
1797 [[deprecated ("the argument is always true; write the condition "
1798 "(since 6.0.0)")]] detail::check_result&&
1799 require (const Expr_T& expr,
1803
1831 template <class Expr_T>
1833 [[deprecated ("use require() (since 6.0.0)")]] detail::check_result&&
1834 assume (const Expr_T& expr,
1838
1842#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
1843
1844 // ------------------------------------------------------------------------
1845
1853 [[nodiscard]] size_t
1854 nesting_depth (void) const noexcept;
1855
1856 private:
1871 [[nodiscard]] bool
1872 is_misdirected (void) const noexcept;
1873
1890 detail::check_result&&
1892 const reflection::source_location& sl,
1893 detail::check_result&& result);
1894
1910 void
1911 report_misdirected_test (const located_name& name);
1912
1931 void
1932 report_rejected_test (const std::string& message,
1933 const reflection::source_location& location);
1934
1953 [[gnu::always_inline]] void
1954 run (void) override;
1955
1956 private:
1957#if defined(__cpp_exceptions)
1972 void
1973 fail_unexpected_exception (const char* what);
1974#endif // defined(__cpp_exceptions)
1975
1976 private:
1986
1999
2008
2016 };
2017
2018 // ==========================================================================
2019
2059 {
2068
2076
2084
2091 friend class top_suite;
2092
2099 friend class static_suite;
2100
2101 private:
2122 template <typename Callable_T, typename... Args_T>
2123 suite (located_name&& name, runner& test_runner, Callable_T&& callable,
2124 Args_T&&... arguments);
2125
2126 public:
2133 suite (const suite&) = delete;
2134
2142 suite (suite&&) = delete;
2143
2150 suite&
2152 = delete;
2153
2161 suite&
2163 = delete;
2164
2173 ~suite () override;
2174
2175 // ------------------------------------------------------------------------
2176
2194 template <typename Callable_T, typename... Args_T>
2195 requires detail::test_body<Callable_T, Args_T...>
2196 void
2197 test (const located_name& name, Callable_T&& callable,
2198 Args_T&&... arguments);
2199
2200#if !defined(__DOXYGEN__)
2219 template <typename Callable_T, typename... Args_T>
2220 requires (!detail::test_body<Callable_T, Args_T...>)
2221 void
2222 test (const located_name& name, Callable_T&& callable,
2223 Args_T&&... arguments);
2224#endif // !defined(__DOXYGEN__)
2225
2269 template <typename Values_T, typename Callable_T>
2272 void
2273 test_each (const located_name& name, Values_T&& values,
2274 Callable_T&& callable);
2275
2297 template <typename T, typename Callable_T>
2298 void
2299 test_each (const located_name& name, std::initializer_list<T> values,
2300 Callable_T&& callable);
2301
2302#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
2307
2323 [[deprecated ("the timings are internal (since 6.0.0)"),
2324 nodiscard]] const detail::stopwatch&
2325 timings (void) const noexcept;
2326
2341 [[deprecated ("the timings are internal (since 6.0.0)"),
2342 nodiscard]] detail::stopwatch&
2343 timings (void) noexcept;
2344
2348#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
2349
2350 private:
2363 void
2364 run (void) override;
2365
2366 private:
2367#if defined(__cpp_exceptions)
2383 void
2384 fail_unexpected_exception (const char* what);
2385#endif // defined(__cpp_exceptions)
2386
2403 void
2404 link (void) noexcept;
2405
2419 void
2420 unlink (void) noexcept;
2421
2422 private:
2431 std::function<void (suite&)> callable_;
2432
2442
2454
2463 suite* next_ = nullptr;
2464
2475 static suite* first_;
2476 };
2477
2478 // ==========================================================================
2479
2497 class top_suite final : public suite
2498 {
2507
2508 private:
2519 top_suite (const char* name, runner& test_runner);
2520
2521 public:
2528 top_suite (const top_suite&) = delete;
2529
2537 top_suite (top_suite&&) = delete;
2538
2545 top_suite&
2547 = delete;
2548
2556 top_suite&
2558 = delete;
2559
2568 ~top_suite () override;
2569 };
2570
2571 // ==========================================================================
2572
2573 class static_suite;
2574
2575 namespace detail
2576 {
2592 template <typename Callable_T, typename... Args_T>
2594 = (!std::is_invocable_v<std::decay_t<Callable_T>&, suite&,
2595 std::decay_t<Args_T>&...>)
2596 && std::is_invocable_v<std::decay_t<Callable_T>&, static_suite&,
2597 std::decay_t<Args_T>&...>;
2598 } // namespace detail
2599
2600 // ==========================================================================
2601
2644 class static_suite final : public suite
2645 {
2646 public:
2675 template <typename Callable_T, typename... Args_T>
2676 requires (!detail::static_suite_body<Callable_T, Args_T...>
2677 && detail::suite_body<Callable_T, Args_T...>)
2679 Callable_T&& callable, Args_T&&... arguments);
2680
2681#if !defined(__DOXYGEN__)
2698 template <typename Callable_T, typename... Args_T>
2699 requires (!detail::static_suite_body<Callable_T, Args_T...>
2700 && !detail::suite_body<Callable_T, Args_T...>)
2702 Callable_T&& callable, Args_T&&... arguments);
2703#endif // !defined(__DOXYGEN__)
2704
2705#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
2710
2745 template <typename Callable_T, typename... Args_T>
2746 requires (detail::static_suite_body<Callable_T, Args_T...>)
2747 [[deprecated ("use a suite& first parameter (since 6.0.0)")]]
2749 Callable_T&& callable, Args_T&&... arguments);
2750
2754#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
2755
2762 static_suite (const static_suite&) = delete;
2763
2772
2781 = delete;
2782
2792 = delete;
2793
2802 ~static_suite () override;
2803
2804 private:
2819 void
2820 link_or_reject (void) noexcept;
2821 };
2822
2823 // --------------------------------------------------------------------------
2824} // namespace micro_os_plus::micro_test_plus
2825
2826#if defined(__GNUC__)
2827#pragma GCC diagnostic pop
2828#endif // defined(__GNUC__)
2829
2830// ----------------------------------------------------------------------------
2831
2832#endif // defined(__cplusplus)
2833
2834// ============================================================================
2835// Templates, inlines & constexpr implementations.
2836
2837#include "inlines/test-inlines.h"
2838
2839// ----------------------------------------------------------------------------
2840
2841#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_TEST_H_
2842
2843// ----------------------------------------------------------------------------
C++ header file with declarations for the µTest++ check result.
Aggregated check and test case counters for a node in the test tree.
Definition counters.h:123
constexpr bound_callable(C &&callable, A &&... arguments)
Constructs the function object from a callable and the arguments.
void operator()(Self_T &self)
Invokes the stored callable.
std::tuple< Args_T... > arguments_
The stored arguments.
Definition test.h:1020
void invoke(Self_T &self, std::index_sequence< Is... >)
Invokes the stored callable with the stored arguments, unpacked by their indices.
Callable_T callable_
The stored callable.
Definition test.h:1011
Non-owning reference to a callable invoked with a Self_T& argument.
Definition test.h:1047
void operator()(Self_T &self) const
Invokes the referred callable.
callable_ref(Callable_T &callable) noexcept
Constructs a reference to a callable.
void * callable_
The address of the referred callable.
Definition test.h:1112
void(*) invoke_(void *callable, Self_T &self)
The function that invokes the referred callable.
Definition test.h:1121
static void invoke_callable(void *callable, Self_T &self)
Invokes a callable of a given type, from its address.
The result of one check, reported when destroyed.
Human (standard output) implementation of reporter.
TAP (Test Anything Protocol) implementation of reporter.
Abstract base class for the reporters that display test results, including operand values for failure...
Definition reporter.h:276
Non-template base for all runnable objects (suites and test cases).
Definition test.h:349
runner & test_runner(void) const noexcept
Returns the test runner that owns this test runnable.
runnable_base(const runnable_base &)=delete
Deleted copy constructor to prevent copying.
size_t next_test_point_number(void) noexcept
Advances to the next child test point, and returns its number.
void reject_body_exception(void)
Reports the exception that escaped the body of a suite while the test cases are listed,...
Definition test.cpp:289
virtual void run(void)=0
Runs the body of the test case or suite.
void after_test_case_create(class test_case &test_case, suite &suite)
Counts a newly constructed child test case and executes it immediately.
Definition test.cpp:350
class test_case * running_test_case(void) const noexcept
Returns the innermost test case being run by the owning runner, if any.
Definition test.cpp:166
runnable_base & operator=(const runnable_base &)=delete
Deleted copy assignment operator to prevent copying.
bool is_listing(void) const noexcept
Checks whether the owning runner lists the test cases instead of running them.
Definition test.cpp:188
bool accepts_test_case(const suite &target, const located_name &name)
Checks whether a test case can be created on a suite.
Definition test.cpp:239
void abort(const reflection::source_location &sl=reflection::source_location::current()) const
Aborts test execution via the owning runner, for a failed requirement.
Definition test.cpp:306
runnable_base(runnable_base &&)=delete
Deleted move constructor to prevent moving.
friend class micro_test_plus::runner
The runner, which numbers and runs the suites.
Definition test.h:357
size_t own_index_
The test index, counting from 1.
Definition test.h:859
const char * name(void) const noexcept
Returns the node name.
void create_test_case(const located_name &name, suite &parent_suite, size_t nesting_depth, Callable_T &&callable, Args_T &&... arguments)
Creates a child test case, and runs it.
suite * exchange_running_suite(suite *running) noexcept
Replaces the suite whose body is running in the owning runner, and returns the previous one.
Definition test.cpp:212
size_t current_subtest_index(void) const noexcept
Deprecated number of the most recent child test point.
class reporter & test_reporter(void) const noexcept
Returns the test reporter associated with this test runnable.
Definition test.cpp:155
size_t own_index(void) const noexcept
Deprecated positional index of this node within its parent.
runnable_base(const char *name, runner &test_runner, size_t own_index)
Constructs a runnable_base with a name, runner, and index.
Definition test.cpp:126
const counters & totals(void) const noexcept
Returns the totals of the node.
bool is_aborted(void) const noexcept
Checks whether the test execution was aborted by the owning runner.
Definition test.cpp:177
size_t children_subtests_count(void) const noexcept
Deprecated number of direct child test cases of this node.
runner & runner_
Reference to the test runner that owns this object.
Definition test.h:848
size_t test_point_number_
The number of the most recent child test point.
Definition test.h:871
bool has_running_test_case_of(const suite &target) const noexcept
Checks whether the innermost running test case belongs to a suite.
Definition test.cpp:199
friend class reporter_human
The human-readable reporter, which displays the nodes.
Definition test.h:375
friend class reporter_tap
The TAP reporter, which displays the nodes.
Definition test.h:385
friend class check_result
The check result, which numbers and counts the checks.
Definition test.h:366
size_t child_test_cases_count_
The number of direct child test cases.
Definition test.h:883
Measures the elapsed time of an operation.
Definition stopwatch.h:138
A name of a suite or of a test case, with the location where it was given.
Definition test.h:177
reflection::source_location location_
The location where the name was given.
Definition test.h:298
std::string name_
The copy of the name.
Definition test.h:289
const char * name(void) const noexcept
Returns the name.
located_name(Pointer_T name, const reflection::source_location &location=reflection::source_location::current())
Constructs the name from a C string, capturing the location of the caller.
const reflection::source_location & location(void) const noexcept
Returns the location where the name was given.
Local implementation of source location information for diagnostics.
Definition reflection.h:143
static constexpr source_location current(const char *file="unknown", unsigned int line={}) noexcept
Returns the current source location.
The test runner for the µTest++ framework.
Definition runner.h:187
A test suite designed for static (namespace-scope) registration with a runner.
Definition test.h:2645
static_suite(static_suite &&)=delete
Deleted move constructor to prevent moving.
static_suite(located_name name, runner &test_runner, Callable_T &&callable, Args_T &&... arguments)
Deprecated constructor, for a body whose first parameter is static_suite&.
void link_or_reject(void) noexcept
Inserts this suite into the list of suites, or reject it.
Definition test.cpp:814
static_suite(located_name name, runner &test_runner, Callable_T &&callable, Args_T &&... arguments)
Constructs a static suite, and links it into the list of suites.
static_suite & operator=(const static_suite &)=delete
Deleted copy assignment operator to prevent copying.
static_suite(const static_suite &)=delete
Deleted copy constructor to prevent copying.
A named, runnable test suite registered with the test runner.
Definition test.h:2059
const detail::stopwatch & timings(void) const noexcept
Deprecated access to the timings of the suite.
void test(const located_name &name, Callable_T &&callable, Args_T &&... arguments)
Adds a test case to the suite, and runs it.
void fail_unexpected_exception(const char *what)
Reports an exception that escaped the suite body as a failed check of the suite.
Definition test.cpp:701
void unlink(void) noexcept
Removes this suite from the list of suites.
Definition test.cpp:760
void run(void) override
Executes the suite body by invoking the stored callable.
Definition test.cpp:604
void link(void) noexcept
Inserts this suite into the list of suites.
Definition test.cpp:738
suite(const suite &)=delete
Deleted copy constructor to prevent copying.
static suite * first_
The first suite in the list of suites.
Definition test.h:2475
void test_each(const located_name &name, Values_T &&values, Callable_T &&callable)
Adds a test case to the suite for each value of a range or a tuple, and runs them.
suite * next_
The next suite in the list of suites.
Definition test.h:2463
friend class micro_test_plus::runner
The runner, which creates and runs the suites.
Definition test.h:2067
located_name located_name_
The name of the suite, with the location where it was given.
Definition test.h:2453
suite & operator=(const suite &)=delete
Deleted copy assignment operator to prevent copying.
friend class top_suite
The top suite, which is constructed by the runner.
Definition test.h:2091
detail::stopwatch stopwatch_
Stopwatch of this suite.
Definition test.h:2441
suite(suite &&)=delete
Deleted move constructor to prevent moving.
suite(located_name &&name, runner &test_runner, Callable_T &&callable, Args_T &&... arguments)
Constructs a suite with a name, runner, and callable body.
std::function< void(suite &)> callable_
Callable storing the suite body and any bound arguments.
Definition test.h:2431
friend class static_suite
The static suite, which registers itself.
Definition test.h:2099
A named, runnable test case that lives inside a suite.
Definition test.h:1362
test_case(test_case &&)=delete
Deleted move constructor to prevent moving.
void report_rejected_test(const std::string &message, const reflection::source_location &location)
Reports a rejected call as a failed check of this test case.
Definition test.cpp:493
void fail_unexpected_exception(const char *what)
Reports an exception that escaped the test case body as a failed check.
Definition test.cpp:535
size_t nesting_depth_
The nesting depth of this test case within the suite.
Definition test.h:2015
suite & parent_suite_
Reference to the parent suite that owns this test case.
Definition test.h:2007
void test_each(const located_name &name, Values_T &&values, Callable_T &&callable)
Adds a nested test case for each value of a range or a tuple, and runs them.
test_case & operator=(const test_case &)=delete
Deleted copy assignment operator to prevent copying.
test_case(const located_name &name, runner &test_runner, suite &parent_suite, size_t own_index, size_t nesting_depth, detail::callable_ref< test_case > body)
Constructs a test case with a name, runner, parent suite, index, nesting depth, and body.
friend class micro_test_plus::runner
The runner, which reports the rejected calls as failed checks of the running test case.
Definition test.h:1373
detail::check_result && require(const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current(), detail::check_result &&result=detail::check_result{})
Deprecated require() of a suspicious condition.
bool is_misdirected(void) const noexcept
Tells whether another test case is running.
const located_name & located_name_
The name and the location of the call to test() that created this test case.
Definition test.h:1998
detail::check_result && report_misdirected(detail::check_kind kind, const reflection::source_location &sl, detail::check_result &&result)
Reports a check on this test case as a failure of the running one.
Definition test.cpp:444
void test(const located_name &name, Callable_T &&callable, Args_T &&... arguments)
Adds a nested test case to this test case, and runs it.
detail::callable_ref< test_case > callable_
Reference to the test case body, with any bound arguments.
Definition test.h:1985
test_case(const test_case &)=delete
Deleted copy constructor to prevent copying.
void report_misdirected_test(const located_name &name)
Reports a nested test case started on this test case as a failure of the running one.
Definition test.cpp:472
void run(void) override
Executes the test case body by invoking the referred callable.
detail::check_result && assume(const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current(), detail::check_result &&result=detail::check_result{})
Deprecated name of require().
size_t nesting_depth(void) const noexcept
Returns the nesting depth of this test case.
detail::check_result && expect(const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current(), detail::check_result &&result=detail::check_result{})
Deprecated expect() of a suspicious condition.
The optional top suite owned by every runner instance.
Definition test.h:2498
top_suite(top_suite &&)=delete
Deleted move constructor to prevent moving.
friend class micro_test_plus::runner
The runner, which owns the top suite.
Definition test.h:2506
top_suite & operator=(const top_suite &)=delete
Deleted copy assignment operator to prevent copying.
top_suite(const char *name, runner &test_runner)
Constructs the top-level suite with a name and runner reference.
Definition test.cpp:783
top_suite(const top_suite &)=delete
Deleted copy constructor to prevent copying.
Concept satisfied when T provides both begin() and end() member functions returning an iterator and i...
Definition extension.h:532
Concept satisfied when T provides begin() and end() only as functions found by argument-dependent loo...
Definition extension.h:574
Concept satisfied by a callable object whose call operator is not a single non-template member functi...
Definition test.h:1177
Concept satisfied when a type was accepted by expect() and require() before the exclusion of the susp...
Definition extension.h:506
The body of a static suite written for v5.0.1, whose first parameter is a static_suite& reference.
Definition test.h:2594
Concept satisfied by a callable object that can be the body of a suite.
Definition test.h:1217
Concept satisfied by a callable object that can be the body of a test case.
Definition test.h:1198
Concept satisfied when T is a range of values for test_each().
Definition test.h:1139
Concept satisfied when T is a tuple of values for test_each().
Definition test.h:1155
Concept satisfied by a value that expect() and require() do not accept.
Definition test.h:1240
Concept satisfied when a type can be used as a test expression in expect() or require().
Definition extension.h:403
C++ header file with declarations for the µTest++ counters.
C++ header file with declarations for the µTest++ extension concepts.
#define MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED
Enables the deprecated definitions of the µTest++ Testing Framework.
detail::check_result && expect(const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current(), detail::check_result &&result=detail::check_result{})
Evaluates a condition and reports the result.
detail::check_result && require(const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current(), detail::check_result &&result=detail::check_result{})
Checks a condition and, if false, stops the test case.
Internal implementation details for the µTest++ framework.
check_kind
The kind of a check, which determines what happens when it fails.
void test_each_value(Self_T &self, const located_name &name, Values_T &&values, Callable_T &callable)
Adds and runs a test case for each value.
constexpr bool dependent_false_v
A value that is always false, but depends on the template arguments.
Definition test.h:1258
auto bind_callable(Callable_T &&callable, Args_T &&... arguments)
Creates the function object that holds the body of a test case or suite.
constexpr void reject_test_body(void) noexcept
Stops the compilation with a message that tells what the body of a test case takes.
constexpr void reject_suite_body(void) noexcept
Stops the compilation with a message that tells what the body of a suite takes.
void escape_control_characters(std::string &name)
Escapes the control characters of a name.
Definition test.cpp:80
Primary namespace for the µTest++ testing framework.
C++ header file with declarations for the µTest++ reflection utilities.
C++ header file with declarations for the µTest++ stopwatch.
Struct template representing a generic value, accessible via a getter.
Definition deprecated.h:629
C++ header file with inline implementations for the µTest++ test hierarchy.