located_name Class
A name of a suite or of a test case, with the location where it was given. More...
Declaration
Included Headers
Public Constructors Index
template <std::size_t N> | |
| located_name (const char(&name)[N], const reflection::source_location &location=reflection::source_location::current()) | |
|
Constructs the name from an array of characters, capturing the location of the caller. More... | |
| located_name (const std::string &name, const reflection::source_location &location=reflection::source_location::current()) | |
|
Constructs the name from a standard string, capturing the location of the caller. More... | |
template <typename Pointer_T> | |
| 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. More... | |
| located_name (std::string &&name, const reflection::source_location &location=reflection::source_location::current()) | |
|
Constructs the name from a temporary standard string, capturing the location of the caller. More... | |
| located_name (std::string_view name, const reflection::source_location &location=reflection::source_location::current()) | |
|
Constructs the name from a string view, capturing the location of the caller. More... | |
Public Member Functions Index
| const reflection::source_location & | location (void) const noexcept |
|
Returns the location where the name was given. More... | |
| const char * | name (void) const noexcept |
|
Returns the name. More... | |
Private Member Attributes Index
| reflection::source_location | location_ |
|
The location where the name was given. More... | |
| std::string | name_ |
|
The copy of the name. More... | |
Description
A name of a suite or of a test case, with the location where it was given.
The name parameter of suite::test(), test_case::test(), test_each(), runner::add_suite(), runner::add_top_suite(), and the static_suite constructors. The constructors are not explicit, so a string literal, a const char*, a std::string, or a std::string_view passed as the name converts implicitly; the default argument of the constructors is evaluated at the place of the conversion, which is the call in the user code, so the location is captured without an additional argument (which could not follow the variadic arguments of these functions).
The name is copied, so the argument need not outlive the call, and a std::string_view need not be null-terminated; a temporary std::string is moved. The copy of a test case name lives until the end of the call to test(), within which the test case runs, so the memory used does not grow with the number of test cases; the suites, which run later, keep their name, moved, until they are destroyed.
The location of a test case is used to report a failure that is not associated with a check, such as an exception escaping the test case body; the suites keep their location, but do not report it.
Since a conversion sequence may include only one user-defined conversion, an argument that converts to const char*, to std::string, or to std::string_view via a user-defined conversion operator must be converted explicitly.
A helper function that adds test cases on behalf of its caller can take a const located_name& parameter and pass it to test(), so that the reported location is that of the call to the helper, not that of the call to test() inside the helper.
- Example
- Since
6.0.0
Definition at line 176 of file test.h.
Public Constructors
located_name()
|
Constructs the name from an array of characters, capturing the location of the caller.
Selected for the arrays, including the string literals. The name ends at the first null character or at the end of the array, whichever comes first, so that an array that is full, without a terminator, such as a fixed-size name field, is not read beyond its end.
- Template Parameters
-
N The number of elements of the array.
- Parameters
-
name The name or description, used in reports; copied.
location The location of the conversion, defaulting to the call in the user code.
Copies the characters up to the first null character, or all the elements of the array if there is none, and stores the location; when called implicitly, the location is the place of the conversion, in the user code.
Declaration at line 219 of file test.h, definition at line 116 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::escape_control_characters, location, location_, name and name_.
located_name()
| inline |
Constructs the name from a standard string, capturing the location of the caller.
- Parameters
-
name The name or description, used in reports; copied.
location The location of the conversion, defaulting to the call in the user code.
Copies the content of the string, and stores the location; when called implicitly, the location is the place of the conversion, in the user code.
Declaration at line 231 of file test.h, definition at line 131 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::escape_control_characters, location, location_, name and name_.
located_name()
|
Constructs the name from a C string, capturing the location of the caller.
Selected for the char pointers; the text must be null-terminated. The arrays, including the string literals, are taken by the constructor for arrays, which does not read beyond the array.
- Template Parameters
-
Pointer_T The pointer type: a pointer to char, possibly const, or std::nullptr_t.
- Parameters
-
name The name or description, used in reports; copied. A null pointer is an empty name.
location The location of the conversion, defaulting to the call in the user code.
Copies the name, or stores an empty name if the pointer is null, and the location; the control characters of the name are escaped. When called implicitly, the location is the place of the conversion, in the user code.
Declaration at line 199 of file test.h, definition at line 101 of file test-inlines.h.
References located_name, location, name and name_.
Referenced by located_name.
located_name()
| inline |
Constructs the name from a temporary standard string, capturing the location of the caller.
- Parameters
-
name The name or description, used in reports; moved.
location The location of the conversion, defaulting to the call in the user code.
Takes over the content of the string, without copying it, and stores the location; when called implicitly, the location is the place of the conversion, in the user code.
Declaration at line 243 of file test.h, definition at line 144 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::escape_control_characters, location, location_, name and name_.
located_name()
| inline |
Constructs the name from a string view, capturing the location of the caller.
- Parameters
-
name The name or description, used in reports; copied, so the view need not be null-terminated.
location The location of the conversion, defaulting to the call in the user code.
Copies the characters of the view, which need not be null-terminated, and stores the location; when called implicitly, the location is the place of the conversion, in the user code.
Declaration at line 256 of file test.h, definition at line 157 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::escape_control_characters, location, location_, name and name_.
Public Member Functions
location()
| inline nodiscard noexcept |
Returns the location where the name was given.
- Parameters
None.
- Returns
A reference to the stored source location.
Returns a reference to the location stored in location_.
Declaration at line 279 of file test.h, definition at line 179 of file test-inlines.h.
Reference location_.
Referenced by located_name, located_name, located_name, located_name, located_name, micro_os_plus::micro_test_plus::detail::runnable_base::accepts_test_case, micro_os_plus::micro_test_plus::runner::add_top_suite, micro_os_plus::micro_test_plus::test_case::fail_unexpected_exception, micro_os_plus::micro_test_plus::runner::reject_call, micro_os_plus::micro_test_plus::test_case::report_misdirected_test and micro_os_plus::micro_test_plus::detail::test_each_value.
name()
| inline nodiscard noexcept |
Returns the name.
- Parameters
None.
- Returns
A pointer to the null-terminated name, valid while this object exists and is not modified.
Returns name_.c_str().
Declaration at line 269 of file test.h, definition at line 169 of file test-inlines.h.
Reference name_.
Referenced by located_name, located_name, located_name, located_name, located_name, micro_os_plus::micro_test_plus::suite::suite, micro_os_plus::micro_test_plus::detail::runnable_base::accepts_test_case, micro_os_plus::micro_test_plus::runner::add_suite, micro_os_plus::micro_test_plus::runner::add_top_suite, micro_os_plus::micro_test_plus::test_case::report_misdirected_test, micro_os_plus::micro_test_plus::suite::test, micro_os_plus::micro_test_plus::test_case::test and micro_os_plus::micro_test_plus::detail::test_each_value.
Private Member Attributes
location_
|
The location where the name was given.
Captured by the default argument of the constructor, at the place of the conversion to located_name.
Definition at line 298 of file test.h.
Referenced by located_name, located_name, located_name, located_name and location.
name_
|
The copy of the name.
Owned, so that the name does not depend on the lifetime of the argument; the name of the node points into it.
Definition at line 289 of file test.h.
Referenced by located_name, located_name, located_name, located_name, located_name and name.
The documentation for this class was generated from the following files:
Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.