40#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_TEST_H_
41#define MICRO_OS_PLUS_MICRO_TEST_PLUS_TEST_H_
45#if defined(__cplusplus)
49#if __has_include("micro-os-plus/project-config.h")
50#include "micro-os-plus/project-config.h"
53#if __has_include("micro-os-plus/micro-test-plus-defines.h")
54#include "micro-os-plus/micro-test-plus-defines.h"
65#include <initializer_list>
76#pragma GCC diagnostic push
78#pragma GCC diagnostic ignored "-Waggregate-return"
79#pragma GCC diagnostic ignored "-Wpadded"
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"
85#pragma GCC diagnostic ignored "-Wsuggest-final-types"
86#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
87#pragma GCC diagnostic ignored "-Wredundant-tags"
195 template <
typename Po
inter_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>)
218 template <std::
size_t N>
268 [[nodiscard]]
const char*
269 name (
void)
const noexcept;
307 class reporter_human;
453 [[nodiscard]]
const char*
454 name (
void)
const noexcept;
471 totals (
void)
const noexcept;
473#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
492 [[deprecated (
"internal to the framework (since 6.0.0)"),
508 [[deprecated (
"internal to the framework (since 6.0.0)"),
523 [[deprecated (
"internal to the framework (since 6.0.0)"),
808 template <
typename Callable_T,
typename... Args_T>
809 [[gnu::always_inline]]
void
811 size_t nesting_depth, Callable_T&& callable,
812 Args_T&&... arguments);
914 template <
typename Self_T,
typename Callable_T,
typename... Args_T>
916 bind_callable (Callable_T&& callable, Args_T&&... arguments);
942 template <
typename Self_T,
typename Callable_T,
typename... Args_T>
968 template <
typename C,
typename... A>
969 requires (
sizeof...(A) > 0)
970 constexpr explicit bound_callable (C&& callable, A&&... arguments);
983 [[gnu::always_inline]]
void
1000 template <std::size_t... Is>
1001 [[gnu::always_inline]]
void
1002 invoke (Self_T& self, std::index_sequence<Is...>);
1045 template <
typename Self_T>
1065 template <
typename Callable_T>
1066 requires (!std::is_same_v<std::remove_cv_t<Callable_T>,
1084 [[gnu::always_inline]]
void
1102 template <
typename Callable_T>
1156 std::tuple_size<std::remove_cvref_t<T>>
::value;
1175 template <
typename Callable_T>
1177 = std::is_class_v<std::decay_t<Callable_T>>
1178 && (!
requires { &std::decay_t<Callable_T>::operator(); });
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>&...>;
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>> && ...);
1257 template <
typename... Ts>
1278 template <
typename Callable_T,
typename... Args_T>
1298 template <
typename Callable_T,
typename... Args_T>
1322 template <
class Self_T,
class Values_T,
class Callable_T>
1325 Callable_T& callable);
1486 template <
typename Callable_T,
typename... Args_T>
1490 Args_T&&... arguments);
1492#if !defined(__DOXYGEN__)
1511 template <
typename Callable_T,
typename... Args_T>
1515 Args_T&&... arguments);
1561 template <
typename Values_T,
typename Callable_T>
1566 Callable_T&& callable);
1589 template <
typename T,
typename Callable_T>
1592 Callable_T&& callable);
1625 template <
class Expr_T>
1628 expect (
const Expr_T& expr,
1633#if !defined(__DOXYGEN__)
1653 template <
class Expr_T>
1656 expect (
const Expr_T& expr,
1704 template <
class Expr_T>
1705 requires extension::checkable<Expr_T>
1706 detail::check_result&&
1708 const reflection::source_location& sl
1710 detail::check_result&& result = detail::check_result{});
1712#if !defined(__DOXYGEN__)
1732 template <
class Expr_T>
1733 requires detail::unsupported_condition<Expr_T>
1734 detail::check_result&&
1736 const reflection::source_location& sl
1738 detail::check_result&& result = detail::check_result{});
1741#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
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&&
1795 template <
class Expr_T>
1797 [[deprecated (
"the argument is always true; write the condition "
1831 template <
class Expr_T>
1834 assume (
const Expr_T& expr,
1853 [[nodiscard]]
size_t
1890 detail::check_result&&
1892 const reflection::source_location& sl,
1893 detail::check_result&& result);
1933 const reflection::source_location& location);
1953 [[gnu::always_inline]]
void
1954 run (
void)
override;
1957#if defined(__cpp_exceptions)
2122 template <
typename Callable_T,
typename... Args_T>
2124 Args_T&&... arguments);
2194 template <
typename Callable_T,
typename... Args_T>
2198 Args_T&&... arguments);
2200#if !defined(__DOXYGEN__)
2219 template <
typename Callable_T,
typename... Args_T>
2223 Args_T&&... arguments);
2269 template <
typename Values_T,
typename Callable_T>
2274 Callable_T&& callable);
2297 template <
typename T,
typename Callable_T>
2300 Callable_T&& callable);
2302#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
2323 [[deprecated (
"the timings are internal (since 6.0.0)"),
2325 timings (
void)
const noexcept;
2341 [[deprecated (
"the timings are internal (since 6.0.0)"),
2364 run (
void)
override;
2367#if defined(__cpp_exceptions)
2404 link (
void)
noexcept;
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>&...>;
2675 template <
typename Callable_T,
typename... Args_T>
2679 Callable_T&& callable, Args_T&&... arguments);
2681#if !defined(__DOXYGEN__)
2698 template <
typename Callable_T,
typename... Args_T>
2702 Callable_T&& callable, Args_T&&... arguments);
2705#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
2745 template <
typename Callable_T,
typename... Args_T>
2747 [[deprecated (
"use a suite& first parameter (since 6.0.0)")]]
2749 Callable_T&& callable, Args_T&&... arguments);
2826#if defined(__GNUC__)
2827#pragma GCC diagnostic pop
C++ header file with declarations for the µTest++ check result.
Aggregated check and test case counters for a node in the test tree.
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.
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.
Non-owning reference to a callable invoked with a Self_T& argument.
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.
void(*) invoke_(void *callable, Self_T &self)
The function that invokes the referred callable.
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...
Non-template base for all runnable objects (suites and test cases).
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,...
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.
class test_case * running_test_case(void) const noexcept
Returns the innermost test case being run by the owning runner, if any.
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.
bool accepts_test_case(const suite &target, const located_name &name)
Checks whether a test case can be created on a suite.
void abort(const reflection::source_location &sl=reflection::source_location::current()) const
Aborts test execution via the owning runner, for a failed requirement.
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.
size_t own_index_
The test index, counting from 1.
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.
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.
counters totals_
Totals for the node.
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.
const counters & totals(void) const noexcept
Returns the totals of the node.
const char * name_
The node name.
bool is_aborted(void) const noexcept
Checks whether the test execution was aborted by the owning runner.
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.
size_t test_point_number_
The number of the most recent child test point.
bool has_running_test_case_of(const suite &target) const noexcept
Checks whether the innermost running test case belongs to a suite.
friend class reporter_human
The human-readable reporter, which displays the nodes.
friend class reporter_tap
The TAP reporter, which displays the nodes.
friend class check_result
The check result, which numbers and counts the checks.
size_t child_test_cases_count_
The number of direct child test cases.
Measures the elapsed time of an operation.
A name of a suite or of a test case, with the location where it was given.
reflection::source_location location_
The location where the name was given.
std::string name_
The copy of the name.
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.
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.
A test suite designed for static (namespace-scope) registration with a runner.
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.
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.
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.
void unlink(void) noexcept
Removes this suite from the list of suites.
void run(void) override
Executes the suite body by invoking the stored callable.
void link(void) noexcept
Inserts this suite into the list of suites.
suite(const suite &)=delete
Deleted copy constructor to prevent copying.
static suite * first_
The first suite in the list of suites.
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.
friend class micro_test_plus::runner
The runner, which creates and runs the suites.
located_name located_name_
The name of the suite, with the location where it was given.
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.
detail::stopwatch stopwatch_
Stopwatch of this suite.
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.
friend class static_suite
The static suite, which registers itself.
A named, runnable test case that lives inside a suite.
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.
void fail_unexpected_exception(const char *what)
Reports an exception that escaped the test case body as a failed check.
size_t nesting_depth_
The nesting depth of this test case within the suite.
suite & parent_suite_
Reference to the parent suite that owns this test case.
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.
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.
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.
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.
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.
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.
top_suite(top_suite &&)=delete
Deleted move constructor to prevent moving.
friend class micro_test_plus::runner
The runner, which owns the top suite.
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.
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...
Concept satisfied when T provides begin() and end() only as functions found by argument-dependent loo...
Concept satisfied by a callable object whose call operator is not a single non-template member functi...
Concept satisfied when a type was accepted by expect() and require() before the exclusion of the susp...
The body of a static suite written for v5.0.1, whose first parameter is a static_suite& reference.
Concept satisfied by a callable object that can be the body of a suite.
Concept satisfied by a callable object that can be the body of a test case.
Concept satisfied when T is a range of values for test_each().
Concept satisfied when T is a tuple of values for test_each().
Concept satisfied by a value that expect() and require() do not accept.
Concept satisfied when a type can be used as a test expression in expect() or require().
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.
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.
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.
C++ header file with inline implementations for the µTest++ test hierarchy.