40#if __has_include("micro-os-plus/diag/trace.h")
41#include "micro-os-plus/diag/trace.h"
50#pragma GCC diagnostic ignored "-Waggregate-return"
52#pragma clang diagnostic ignored "-Wunknown-warning-option"
53#pragma clang diagnostic ignored "-Wc++98-compat"
54#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
55#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
61#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_ENABLED)
107 result.reserve (text.size ());
109 for (
size_t i = 0; i < text.size (); ++i)
111 const char c = text[i];
112 if (c ==
'\n' || c ==
'\r')
115 if (c ==
'\r' && i + 1 < text.size () && text[i + 1] ==
'\n')
119 result.push_back (
' ');
121 else if (escape && (c ==
'\\' || c ==
'#'))
123 result.push_back (
'\\');
124 result.push_back (c);
128 result.push_back (c);
136#pragma GCC diagnostic push
138#pragma GCC diagnostic ignored "-Wpadded"
170 if (std::string_view{ text }.find_first_of (escape ?
"\r\n\\#"
172 != std::string_view::npos)
239 [[nodiscard]]
const char*
272#pragma GCC diagnostic pop
296 constexpr std::string_view digits{
"0123456789ABCDEF" };
299 result.reserve (text.size () + 2);
301 result.push_back (
'"');
302 for (
const char c : text)
304 const auto u =
static_cast<unsigned char> (c);
308 result.append (
"\\\\");
311 result.append (
"\\\"");
314 result.append (
"\\0");
317 result.append (
"\\a");
320 result.append (
"\\b");
323 result.append (
"\\t");
326 result.append (
"\\n");
329 result.append (
"\\v");
332 result.append (
"\\f");
335 result.append (
"\\r");
338 result.append (
"\\e");
341 if (u < 0x20 || u == 0x7F)
343 result.append (
"\\x");
344 result.push_back (digits[
static_cast<std::size_t
> (u >> 4)]);
346 digits[
static_cast<std::size_t
> (u & 0x0F)]);
350 result.push_back (c);
355 result.push_back (
'"');
379 bool is_plain = !text.empty () && text.front () !=
'-';
380 for (
const char c : text)
382 const bool is_safe = (c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z')
383 || (c >=
'0' && c <=
'9') || c ==
'_'
384 || c ==
'.' || c ==
'+' || c ==
'/' || c ==
'-';
385 is_plain = is_plain && is_safe;
402#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
403 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
415#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
416 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
435#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
436 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
472#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
473 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
476 char message_summary[32];
477 snprintf (message_summary,
sizeof (message_summary),
494 write_line (to_console,
"%s\n# { total: %s%s }\n", message_summary,
495 message_totals, message_time);
516#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
517 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
suite.
name ());
520 const tap_name name{
suite.
name (),
false };
529 write_line (to_console,
"# Subtest: %s\n", name.c_str ());
561#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
578 const char* result = passed ?
"ok" :
"not ok";
579 const char* status = passed ?
"passed" :
"FAILED";
587 const tap_name name{
suite.
name (),
true };
617 " - %s # { %s, %s%s }\n",
627 " - %s # { %s, %s%s }\n",
629 message_totals, message_time);
655#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
656 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
suite.
name ());
659 const tap_name name{
suite.
name (),
true };
672 " - %s # SKIP filtered\n",
693#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
694 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
suite.
name ());
697 const size_t begin =
buffer_.size ();
700 << tap_text (message,
true) <<
endl;
724#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
725 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
test_case.
name ());
781#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
809 const char* result = passed ?
"ok" :
"not ok";
810 const char* status = passed ?
"passed" :
"FAILED";
823 const bool is_single_point
824 = to_console && passed
852 indent2.c_str (), plan_count);
861 indent2.c_str (), plan_count);
865 " - %s # { %s, %s }\n",
867 status, message_totals);
953 if (!message.empty ())
977 const std::string description = tap_text (
999 const std::string& message,
const bool has_expression,
1006 if (!message.empty ())
1008 *
this <<
" - " << tap_text (message,
true);
1014 *
this <<
indent (level + 1) <<
" ---";
1019 *
this <<
indent (level + 1) <<
" condition: ";
1063 const std::string condition = yaml_double_quoted (
1075 *
this <<
indent (level + 1) <<
" at:" <<
endl;
1076 *
this <<
indent (level + 1) <<
" fileName: "
1079 *
this <<
indent (level + 1) <<
" lineNumber: " << location.
line ()
1082 *
this <<
indent (level + 1) <<
" ..." <<
endl;
1102#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
1103 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
test_case.
name ());
1126 " - %s # SKIP filtered\n",
1160 bool is_requirement)
1162#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
1163 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
1169 const unsigned long line = location.
line ();
1171 const std::string file_name
1174 = is_requirement ?
"Requirement failed" :
"Test execution aborted";
1199 write_line (to_console,
"Bail out! %s at %s:%lu\n", reason,
1200 file_name.c_str (), line);
1270 const tap_name name{ open.
test->
name (),
false };
1302 path.append (
" > ");
1304 path.append (tap_name{ open.test->name (),
false }.c_str ());
1309 while (!rest.empty ())
1311 const size_t end = rest.find (
'\n');
1313 = (end == std::string_view::npos) ? rest.size () : end + 1;
1316 rest.remove_prefix (length);
bool passed(void) const noexcept
Checks whether all executed checks and test cases were successful.
size_t skipped_test_cases(void) const noexcept
Returns the number of test cases skipped by the filter.
size_t executed_test_cases(void) const noexcept
Returns the number of test cases that were executed.
size_t executed_checks(void) const noexcept
Returns the total number of checks executed.
size_t passed_checks(void) const noexcept
Returns the number of checks that passed.
size_t failed_checks(void) const noexcept
Returns the number of checks that failed.
bool is_copy_
Whether the name was copied into prepared_.
tap_name(const char *text, bool escape)
Prepares a name.
~tap_name()=default
Destructor.
tap_name(tap_name &&)=delete
Deleted move constructor.
std::string prepared_
The changed copy of the name.
tap_name(const tap_name &)=delete
Deleted copy constructor.
const char * text_
The original name.
const char * c_str(void) const noexcept
Retrieves the prepared name.
void begin_test_case(const test_case &test_case) override
Marks the beginning of a test case.
void begin_suite(const suite &suite) override
Marks the beginning of a test suite.
void end_suite(const suite &suite) override
Marks the end of a test suite.
void fail_suite(const std::string &message, const suite &suite) override
Reports a failure of a test suite outside its test cases.
void skip_suite(const suite &suite) override
Reports a test suite skipped by the filter.
void skip_test_case(const test_case &test_case) override
Reports a test case skipped by the filter.
void output_pass_suffix(const test_case &test_case) override
Outputs the suffix for a passing condition.
void output_fail_prefix(const std::string &message, const bool has_expression, const reflection::source_location &location, const test_case &test_case) override
Outputs the prefix for a failing condition.
void display_open_heading(const open_test_case &open, bool is_first) override
Writes the # Subtest: heading of an open test case.
void pass_without_text(const test_case &test_case) override
Records a passed check whose text is not written.
void write_quiet_failures(void)
Writes the failed checks of the quiet verbosity, as comments.
void end_session(const runner &runner) override
Marks the end of a test session.
reporter_tap(const runner_options &opts)
Constructor for the reporter_tap class.
const char * error_prefix(void) const noexcept override
Returns the TAP bail-out prefix string "Bail out! ".
void abort_session(const reflection::source_location &location, bool is_requirement) override
Reports the abort of the test execution.
void output_fail_suffix(const reflection::source_location &location, check_kind kind, const test_case &test_case) override
Outputs the suffix for a failing condition.
size_t description_begin_
The position in the buffer where the description of a passed check begins.
void output_pass_prefix(const std::string &message, const test_case &test_case) override
Outputs the prefix for a passing condition.
void begin_session(const runner &runner) override
Marks the beginning of a test session.
size_t condition_begin_
The position in the buffer where the expression of a failed check begins.
void end_test_case(const test_case &test_case) override
Marks the end of a test case.
void commit_buffer(void) override
Writes the results buffered for the outer test case before a nested test case begins.
const char * comment_prefix(void) const noexcept override
Returns the TAP comment prefix string "# ".
~reporter_tap() override
Destructor for the reporter_tap class.
std::string buffer_
Output accumulation buffer.
const micro_test_plus::verbosity verbosity_
The verbosity level for test reporting.
static constexpr size_t elapsed_time_size_
Size of the array that receives the elapsed time text.
void mark_failure(size_t begin)
Records that the lines appended to the buffer from a given position are a failure.
void write_buffer_to_file(void)
Writes the current buffered content to the output file.
bool add_empty_line_
Whether to write an empty line before the next console output.
void announce_output_file(void)
Tells the console where the output file was written.
static void format_suite_totals(const suite &suite, char(&message)[totals_size_])
Formats the totals of a suite.
void clear_buffer(void)
Clears the output buffer.
void commit_outer_results(void)
Writes the results of the outer test case, if any, before a nested test case begins or is skipped.
void enter_suite(const suite &suite, bool displayed)
Notes the suite that begins, for the headings displayed later.
static void format_test_case_totals(const test_case &test_case, char(&message)[totals_size_])
Formats the totals of a test case.
friend class micro_test_plus::runner
The runner, which lists the test cases.
void write_info(const std::vector< std::string > &arguments)
Writes the informational (non-result) lines to the console and to the output file.
static void format_session_totals(const runner &runner, char(&message)[totals_size_])
Formats the totals of the test session.
reporter(const runner_options &opts)
Constructor for the reporter class.
static constexpr size_t indent_size_
Number of spaces per nesting level.
void flush_streams(void)
Flushes the standard output stream and the output file.
void write_console_text(std::string_view text)
Writes a text to the console, unchanged.
friend class micro_test_plus::test_case
The test case, which creates the checks.
void write_file(const char *format,...)
Writes formatted text to the output file.
void write_line(bool to_console, const char *format,...)
Writes formatted lines to the output file and, when requested, to the console.
static constexpr size_t totals_size_
Size of the array that receives the totals text.
std::string failures_
The lines of the failed checks, for the quiet verbosity.
void write_console(const char *format,...)
Writes formatted text to the console.
static void format_elapsed_time(const stopwatch &stopwatch, char(&message)[elapsed_time_size_])
Formats the elapsed time of a suite or of the session.
const suite * current_suite_
The suite that has begun and not yet ended.
std::vector< open_test_case > open_test_cases_
The test cases that have begun and not yet ended, outermost first.
std::string_view console_lines(bool failed) const noexcept
Returns the buffered lines that the console displays when a test case or a suite ends,...
void display_open_test_cases(bool include_last)
Displays the headings not yet displayed, of the open test cases.
output_route route(record_kind kind) const noexcept
Tells where a kind of record is written.
size_t own_index_
The test index, counting from 1.
const char * name(void) const noexcept
Returns the node name.
const counters & totals(void) const noexcept
Returns the totals of the node.
size_t test_point_number_
The number of the most recent child test point.
size_t child_test_cases_count_
The number of direct child test cases.
Local implementation of source location information for diagnostics.
constexpr auto file_name(void) const noexcept
Returns the file name associated with this source location.
constexpr auto line(void) const noexcept
Returns the line number associated with this source location.
The configuration of a test session, and its command-line parser.
const std::vector< std::string > & arguments(void) const noexcept
Returns the complete command line, including argv[0], if any.
detail::stopwatch stopwatch_
Stopwatch of this runner.
size_t total_suites_count(void) const noexcept
Returns the count of all the test suites.
runner_options options_
The options of the test session.
A named, runnable test suite registered with the test runner.
detail::stopwatch stopwatch_
Stopwatch of this suite.
size_t nesting_depth(void) const noexcept
Returns the nesting depth of this test case.
#define MICRO_OS_PLUS_MICRO_TEST_PLUS_PRI_SIZE
Portable printf() conversion for the size_t values.
const char * extract_file_name(const char *path) noexcept
Extracts the file name component from a full path.
std::string yaml_scalar(std::string_view text)
Formats a text as a YAML scalar, double-quoted only when needed.
std::string yaml_double_quoted(std::string_view text)
Formats a text as a YAML double-quoted scalar.
std::string tap_text(std::string_view text, bool escape)
Prepares a text for a single TAP line.
Internal implementation details for the µTest++ framework.
check_kind
The kind of a check, which determines what happens when it fails.
reporter & endl(reporter &stream)
Output stream manipulator for ending a line in test reports.
indentation indent(size_t level)
Factory function that creates an indentation manipulator.
@ test_case_result
The result line of a test case.
@ test_case_heading
The heading that marks the beginning of a test case.
@ abort
The report of an aborted test execution.
@ suite_result
The result line of a suite.
@ suite_heading
The heading that marks the beginning of a suite.
@ skipped
The line of a suite or of a test case skipped by the filter.
@ total
The totals of the session.
C++ header file with declarations for the µTest++ TAP test reporter.
C++ header file with declarations for the µTest++ test runner.
bool console
Whether the record is written to the console.
A test case that has begun and not yet ended.
const test_case * test
The test case.
C++ header file with declarations for the µTest++ test hierarchy.
C++ header file with declarations for the µTest++ utility helpers.