C++ source file with implementations for the µTest++ test hierarchy member functions. More...
Namespaces Index
Functions Index
Description
C++ source file with implementations for the µTest++ test hierarchy member functions.
This source file contains the non-template implementations for the test hierarchy of the µTest++ framework: the constructors and destructors, the run() member functions of the test cases and suites, which call the reporter before and after invoking the stored callable, and the registration of the child test cases, including the accumulation of their totals.
All definitions reside within the micro_os_plus::micro_test_plus namespace.
This file must be included when building the µTest++ library.
Functions
escape_control_characters()
| void micro_os_plus::micro_test_plus::detail::escape_control_characters (std::string & name) |
|
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
-
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.
81 {
82 const auto is_control = [] (char c)
83 {
84 const auto unit = static_cast<unsigned char> (c);
85 return (unit < 0x20 && c != '\t') || unit == 0x7F;
86 };
87
88 std::size_t first = 0;
89 while (first < name.size () && !is_control (name[first]))
90 {
91 ++first;
92 }
93 if (first == name.size ())
94 {
95 return;
96 }
97
98 std::string escaped (name, 0, first);
99 escaped.reserve (name.size () + 8);
100 for (std::size_t i = first; i < name.size (); ++i)
101 {
102 if (is_control (name[i]))
103 {
105 }
106 else
107 {
108 escaped.push_back (name[i]);
109 }
110 }
111 name = std::move (escaped);
112 }
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.
File Listing
The file content with the documentation metadata removed is:
38#if __has_include("micro-os-plus/diag/trace.h")
39#include "micro-os-plus/diag/trace.h"
51#pragma clang diagnostic ignored "-Wunknown-warning-option"
52#pragma clang diagnostic ignored "-Wc++98-compat"
53#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
54#pragma clang diagnostic ignored "-Wc++20-compat"
55#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
57#pragma GCC diagnostic ignored "-Wredundant-tags"
58#pragma GCC diagnostic ignored "-Wsuggest-final-types"
59#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
65#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_ENABLED)
82 const auto is_control = [] (char c)
84 const auto unit = static_cast<unsigned char> (c);
85 return (unit < 0x20 && c != '\t') || unit == 0x7F;
88 std::size_t first = 0;
89 while (first < name.size () && !is_control (name[first]))
93 if (first == name.size ())
98 std::string escaped (name, 0, first);
99 escaped.reserve (name.size () + 8);
100 for (std::size_t i = first; i < name.size (); ++i)
102 if (is_control (name[i]))
108 escaped.push_back (name[i]);
111 name = std::move (escaped);
130#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
144#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
145 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name_);
168 return runner_.running_test_case_;
190 return runner_.options_.list_tests;
200 const suite& target) const noexcept
203 return running != nullptr && &running->parent_suite_ == ⌖
215 runner_.running_suite_ = running;
253 std::string message{ "test case '" };
255 message.append ("' started on suite '");
256 message.append (target.name ());
257 message.append ("', which is not running");
291 std::string message{ "unexpected exception in the body of suite '" };
292 message.append (name_);
293 message.append ("'");
408#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
409 trace::printf ("%s test case '%s' executed one more test case\n",
410 __PRETTY_FUNCTION__, name ());
423#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
424 trace::printf ("%s suite '%s' totals\n", __PRETTY_FUNCTION__,
450 std::string message{ "[check on test case '" };
451 message.append (name ());
452 message.append ("' while '");
453 message.append (running.name ());
454 message.append ("' runs] ");
456 result.init (false, kind, sl, running,
460 return std::move (std::move (result) << message);
476 std::string message{ "[test case '" };
478 message.append ("' started on test case '");
479 message.append (this->name ());
480 message.append ("' while '");
481 message.append (running.name ());
482 message.append ("' runs]");
500 std::move (result) << message;
514#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
515 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name_);
519#if defined(__cpp_exceptions)
540 .message = "unexpected exception",
541 .has_expression = false,
550 failure.message.append (" of unknown type");
553 const std::string expression{};
569#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
570 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name_);
606#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
607 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name_);
629#if defined(__cpp_exceptions)
653#if defined(__cpp_exceptions)
659 catch (const std::exception& e)
686#if defined(__cpp_exceptions)
705 std::string message{ "unexpected exception" };
708 message.append (" in the suite body: ");
709 message.append (what);
713 message.append (" of unknown type in the suite body");
740#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
741 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name_);
747 while (*slot != nullptr && std::strcmp ((*slot)->name_, name_) <= 0)
749 slot = &(*slot)->next_;
762 for (suite** slot = &first_; *slot != nullptr; slot = &(*slot)->next_)
786#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
787 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name);
801#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
802 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name_);
827#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
828 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name_);
Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.