Skip to main content

anonymous{reporter.cpp} Namespace

Local helpers of the reporter base class. More...

Definition​

namespace micro_os_plus::micro_test_plus::detail::anonymous{reporter.cpp} { ... }

Functions Index​

voidformat_skipped (size_t count, char(&message)[fragment_size])

Formats the number of items skipped by the filter. More...

constexpr const char *plural (size_t count) noexcept

Returns the plural suffix for a count. More...

voidwrite_without_colours (FILE *file, std::string_view text)

Writes a text to a file, without the ANSI colour sequences. More...

Variables Index​

constexpr size_tfragment_size = 21 + (std::numeric_limits<size_t>::digits10 + 1)

Size of the array that receives a fragment of the totals. More...

Description​

Local helpers of the reporter base class.

The unnamed namespace gives the helpers internal linkage, so that they are visible only in this translation unit, and cannot conflict with the names of the application or of the other source files of the framework. They are not declared in any header.

The namespace is opened twice in this file, each time before the code that uses its helpers; Doxygen merges the two parts. The first part contains write_without_colours(), which copies the console output to the output file. The second part contains the helpers of the totals lines: fragment_size, plural(), and format_skipped().

Functions​

format_skipped()​

void micro_os_plus::micro_test_plus::detail::anonymous{reporter.cpp}::format_skipped (size_t count, char(&message)[fragment_size])

Formats the number of items skipped by the filter.

The text is ", <count> skipped", appended to the count of the items, or empty when no item was skipped, so that the totals lines of the runs without a filter are not longer.

Parameters
count

The number of skipped items.

message

The character array that receives the null-terminated text.

Returns

Nothing.

Definition at line 874 of file reporter.cpp.

874 format_skipped (size_t count, char (&message)[fragment_size])
875 {
876 if (count > 0)
877 {
878 snprintf (message, sizeof (message),
880 count);
881 }
882 else
883 {
884 message[0] = '\0';
885 }
886 }

References format_skipped, fragment_size and MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE.

Referenced by format_skipped.

plural()​

const char * micro_os_plus::micro_test_plus::detail::anonymous{reporter.cpp}::plural (size_t count)
constexpr noexcept

Returns the plural suffix for a count.

The totals lines are in English, where only the count 1 takes the singular form.

Parameters
count

The count that precedes the noun.

Returns

"" for 1, and "s" otherwise.

Definition at line 854 of file reporter.cpp.

854 plural (size_t count) noexcept
855 {
856 return count == 1 ? "" : "s";
857 }

Reference plural.

Referenced by plural.

write_without_colours()​

void micro_os_plus::micro_test_plus::detail::anonymous{reporter.cpp}::write_without_colours (FILE * file, std::string_view text)

Writes a text to a file, without the ANSI colour sequences.

The text may contain ANSI colour sequences, added when the console is a terminal, which must not reach the file. They are removed while writing: each ESC [, followed by any digits and semicolons, and terminated by m, is skipped, and the text between the sequences is written unchanged. Any other use of ESC is written as is. No line ending is appended.

Parameters
file

The file to write to; must not be null.

text

The text to write.

Returns

Nothing.

Definition at line 113 of file reporter.cpp.

113 write_without_colours (FILE* file, std::string_view text)
114 {
115 size_t start = 0;
116 size_t pos = text.find ('\033');
117 while (pos != std::string_view::npos)
118 {
119 // Parse `ESC [ <digits and semicolons> m`.
120 size_t end = pos + 1;
121 if (end < text.size () && text[end] == '[')
122 {
123 ++end;
124 while (end < text.size ()
125 && ((text[end] >= '0' && text[end] <= '9')
126 || text[end] == ';'))
127 {
128 ++end;
129 }
130 if (end < text.size () && text[end] == 'm')
131 {
132 // A colour sequence; write the preceding text and skip
133 // it.
134 const std::string_view chunk
135 = text.substr (start, pos - start);
136 fwrite (chunk.data (), 1, chunk.size (), file);
137 start = end + 1;
138 }
139 }
140 pos = text.find ('\033', pos + 1);
141 }
142
143 const std::string_view chunk = text.substr (start);
144 fwrite (chunk.data (), 1, chunk.size (), file);
145 }

Reference write_without_colours.

Referenced by write_without_colours.

Variables​

fragment_size​

size_t micro_os_plus::micro_test_plus::detail::anonymous{reporter.cpp}::fragment_size = 21 + (std::numeric_limits<size_t>::digits10 + 1)
constexpr

Size of the array that receives a fragment of the totals.

Large enough for ", N test cases failed", the longest fragment (20 characters and the count), and the terminator, with the count of the largest size_t value (10 digits on 32-bit targets, 20 on 64-bit ones, as in ", 18446744073709551615 test cases failed").

Definition at line 840 of file reporter.cpp.

841 = 21 + (std::numeric_limits<size_t>::digits10 + 1);

Referenced by format_skipped.


The documentation for this namespace was generated from the following file:


Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.