test.h File
C++ header file with declarations for the µTest++ test hierarchy. More...
Included Headers
Namespaces Index
| namespace | micro_os_plus |
|
The primary namespace for the µOS++ framework. More... | |
| namespace | micro_test_plus |
|
Primary namespace for the µTest++ testing framework. More... | |
| namespace | detail |
|
Internal implementation details for the µTest++ framework. More... | |
Classes Index
| class | bound_callable<Self_T, Callable_T, Args_T> |
|
Function object that holds a callable and the additional arguments it is invoked with. More... | |
| class | callable_ref<Self_T> |
|
Non-owning reference to a callable invoked with a Self_T& argument. More... | |
| class | located_name |
|
A name of a suite or of a test case, with the location where it was given. More... | |
| class | runnable_base |
|
Non-template base for all runnable objects (suites and test cases). More... | |
| class | static_suite |
|
A test suite designed for static (namespace-scope) registration with a runner. More... | |
| class | suite |
|
A named, runnable test suite registered with the test runner. More... | |
| class | test_case |
|
A named, runnable test case that lives inside a suite. More... | |
| class | top_suite |
|
The optional top suite owned by every runner instance. More... | |
Concepts Index
| concept | generic_callable |
|
Concept satisfied by a callable object whose call operator is not a single non-template member function. More... | |
| concept | static_suite_body |
|
The body of a static suite written for v5.0.1, whose first parameter is a static_suite& reference. More... | |
| concept | suite_body |
|
Concept satisfied by a callable object that can be the body of a suite. More... | |
| concept | test_body |
|
Concept satisfied by a callable object that can be the body of a test case. More... | |
| concept | test_values_range |
|
Concept satisfied when T is a range of values for test_each(). More... | |
| concept | test_values_tuple |
|
Concept satisfied when T is a tuple of values for test_each(). More... | |
| concept | unsupported_condition |
|
Concept satisfied by a value that expect() and require() do not accept. More... | |
Functions Index
template <typename Self_T, typename Callable_T, typename... Args_T> | |
| auto | bind_callable (Callable_T &&callable, Args_T &&... arguments) |
|
Creates the function object that holds the body of a test case or suite. More... | |
| void | escape_control_characters (std::string &name) |
|
Escapes the control characters of a name. More... | |
template <typename Callable_T, typename... Args_T> | |
| constexpr void | reject_suite_body (void) noexcept |
|
Stops the compilation with a message that tells what the body of a suite takes. More... | |
template <typename Callable_T, typename... Args_T> | |
| constexpr void | reject_test_body (void) noexcept |
|
Stops the compilation with a message that tells what the body of a test case takes. More... | |
template <class Self_T, class Values_T, class Callable_T> | |
| 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. More... | |
Variables Index
template <typename... Ts> | |
| constexpr bool | dependent_false_v = false |
|
A value that is always false, but depends on the template arguments. More... | |
Description
C++ header file with declarations for the µTest++ test hierarchy.
This header provides the declarations for the test hierarchy used within the µTest++ framework: the internal detail::runnable_base base class, and the test_case, suite, top_suite, and static_suite classes. They offer mechanisms for running test cases, managing the counters of the passed and failed checks, and registering test suites with the runner.
The test suites are non-copyable and non-movable, so that each one has a single owner. Their bodies are any callable objects, such as functions and lambdas, with optional arguments.
All definitions reside within the micro_os_plus::micro_test_plus namespace.
This file is included by micro-os-plus/micro-test-plus.h, which is the header that the applications include.
Functions
bind_callable()
| nodiscard |
Creates the function object that holds the body of a test case or suite.
Without additional arguments, the callable already has the signature void (Self_T&), and a copy of it is returned, without a wrapper.
Otherwise, a bound_callable stores copies of the callable and of the arguments (decayed, as by auto), since a suite may run after the caller's temporaries are gone; the callable receives the copies as non-const lvalues. A reference parameter thus refers to the copy; to refer to the caller's object, pass a pointer, or std::ref(), which converts to a T& parameter (an auto& parameter receives the std::reference_wrapper itself).
The returned object holds a copy of the callable (decayed, as by auto) when there are no additional arguments; otherwise it is a bound_callable that holds copies of the callable and of the arguments, and passes the arguments after the leading reference, which is passed when the body is invoked. No memory is allocated, other than by the copies themselves.
A suite stores the object in a std::function, since it runs later; a test case, which runs immediately, refers to it with a callable_ref.
- Template Parameters
-
Self_T The type referred to by the first parameter of the callable (test_case or suite).
Callable_T The type of the callable object.
Args_T The types of the additional callable arguments.
- Parameters
-
callable A generic callable object, usually a lambda.
arguments A possibly empty list of arguments forwarded to the callable after the leading Self_T& reference.
- Returns
The function object, invocable with a Self_T& argument.
Definition at line 344 of file test-inlines.h.
Reference micro_os_plus::micro_test_plus::detail::bind_callable.
Referenced by micro_os_plus::micro_test_plus::detail::bind_callable and micro_os_plus::micro_test_plus::detail::runnable_base::create_test_case.
escape_control_characters()
|
Escapes the control characters of a name.
Replaces, in place, the control characters other than the tab, including the line feed and the NUL, with their escape sequences, so that the names reach the console and the output files as one line of visible text. Defined in src/test.cpp.
- Parameters
-
name The name to escape.
The text is scanned first, so that a name without control characters is not touched. The tab is kept; all the other control characters, including the line feed and the NUL, and DEL, are replaced.
Definition at line 80 of file test.cpp.
References micro_os_plus::micro_test_plus::detail::append_control_escape and micro_os_plus::micro_test_plus::detail::escape_control_characters.
Referenced by micro_os_plus::micro_test_plus::located_name::located_name, micro_os_plus::micro_test_plus::located_name::located_name, micro_os_plus::micro_test_plus::located_name::located_name, micro_os_plus::micro_test_plus::located_name::located_name and micro_os_plus::micro_test_plus::detail::escape_control_characters.
reject_suite_body()
| constexpr noexcept |
Stops the compilation with a message that tells what the body of a suite takes.
Always fails the static assertion that applies, since it is called only when suite_body is not satisfied. A body that cannot be copied, or a body written for a test case, is recognised, to say so.
Called by the overloads of runner::add_suite() and of the static_suite constructor that are selected when the callable is not a valid body, as reject_test_body() is for the test cases.
- Template Parameters
-
Callable_T The type of the callable.
Args_T The types of the additional arguments.
- Parameters
None.
- Returns
Nothing.
Definition at line 448 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::dependent_false_v and micro_os_plus::micro_test_plus::detail::reject_suite_body.
Referenced by micro_os_plus::micro_test_plus::runner::add_suite and micro_os_plus::micro_test_plus::detail::reject_suite_body.
reject_test_body()
| constexpr noexcept |
Stops the compilation with a message that tells what the body of a test case takes.
Always fails the static assertion that applies, since it is called only when test_body is not satisfied. A body written for a suite is recognised, to say so.
Called by the overloads of test_case::test() and suite::test() that are selected when the callable is not a valid body, so that the diagnostic names the mistake in the terms of the application, instead of the concepts and the instantiation stack. Never called at run time.
- Template Parameters
-
Callable_T The type of the callable.
Args_T The types of the additional arguments.
- Parameters
None.
- Returns
Nothing.
Definition at line 422 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::dependent_false_v and micro_os_plus::micro_test_plus::detail::reject_test_body.
Referenced by micro_os_plus::micro_test_plus::detail::reject_test_body.
test_each_value()
|
Adds and runs a test case for each value.
For each value, the name is built in a local string, which lives while the test case runs, since a test case runs within the call to test(), and the test case is added with test(), with the location of the call to test_each(). The callable receives each value as a const lvalue, referring to the element itself; neither the values nor the callable are copied. The values of a range are iterated by a range-based for statement, and those of a tuple are expanded by std::apply(), in order.
The common implementation of test_case::test_each() and suite::test_each().
- Template Parameters
-
Self_T The type of the test case or suite.
Values_T The type of the range or tuple of values.
Callable_T The type of the callable object.
- Parameters
-
self The test case or suite to which the test cases are added.
name The common name of the test cases.
values The range or tuple of values.
callable The callable object, invoked with the test case and each value.
- Returns
Nothing.
Definition at line 1029 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::plain_text::append, micro_os_plus::micro_test_plus::located_name::location, micro_os_plus::micro_test_plus::located_name::name and micro_os_plus::micro_test_plus::detail::test_each_value.
Referenced by micro_os_plus::micro_test_plus::suite::test_each, micro_os_plus::micro_test_plus::suite::test_each, micro_os_plus::micro_test_plus::test_case::test_each, micro_os_plus::micro_test_plus::test_case::test_each and micro_os_plus::micro_test_plus::detail::test_each_value.
Variables
dependent_false_v
| constexpr |
A value that is always false, but depends on the template arguments.
Used as the condition of the static_assert of the functions that reject an argument, so that they fail only when instantiated, and their diagnostic has the message, not the concepts that were not satisfied.
- Template Parameters
-
Ts The template arguments to depend on.
Definition at line 1258 of file test.h.
Referenced by micro_os_plus::micro_test_plus::detail::reject_suite_body and micro_os_plus::micro_test_plus::detail::reject_test_body.
File Listing
The file content with the documentation metadata removed is:
Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.