47#if __has_include("micro-os-plus/diag/trace.h")
48#include "micro-os-plus/diag/trace.h"
59#pragma GCC diagnostic ignored "-Waggregate-return"
61#pragma clang diagnostic ignored "-Wunknown-warning-option"
62#pragma clang diagnostic ignored "-Wc++98-compat"
63#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
64#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
70#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_ENABLED)
116 size_t pos = text.find (
'\033');
117 while (pos != std::string_view::npos)
120 size_t end = pos + 1;
121 if (end < text.size () && text[end] ==
'[')
124 while (end < text.size ()
125 && ((text[end] >=
'0' && text[end] <=
'9')
126 || text[end] ==
';'))
130 if (end < text.size () && text[end] ==
'm')
134 const std::string_view chunk
135 = text.substr (start, pos - start);
136 fwrite (chunk.data (), 1, chunk.size (), file);
140 pos = text.find (
'\033', pos + 1);
143 const std::string_view chunk = text.substr (start);
144 fwrite (chunk.data (), 1, chunk.size (), file);
165#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
166 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
174 fprintf (stderr,
"error: failed to open output file '%s'\n",
196#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
197 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
293#if defined(MICRO_OS_PLUS_STARTUP_ENABLED) \
294 && defined(MICRO_OS_PLUS_DIAG_TRACE_ENABLED)
340 return failed ? std::string_view{
buffer_ } : std::string_view{};
358 fwrite (text.data (), 1, text.size (), stdout);
387 bool is_first =
true;
388 for (
size_t i = 0; i < count; ++i)
447 va_start (args, format);
448 vfprintf (stdout, format, args);
466 va_start (args, format);
493 va_start (args, format);
495 va_copy (args_copy, args);
497 char local_text[128];
499 = vsnprintf (local_text,
sizeof (local_text), format, args);
508 const size_t size =
static_cast<size_t> (length);
509 std::string long_text;
510 std::string_view text{ local_text, size };
511 if (size >=
sizeof (local_text))
515 long_text.resize (size);
516 vsnprintf (long_text.data (), size + 1, format, args_copy);
528 fwrite (text.data (), 1, text.size (), stdout);
551 if (!arguments.empty ())
556 line.append (
"Running: ");
561 for (
size_t i = 1; i < arguments.size (); ++i)
564 line.append (arguments[i]);
577 line.append (
"Built with ");
578#if defined(__clang__)
579 line.append (
"clang " __VERSION__);
580#elif defined(__GNUC__)
581 line.append (
"GCC " __VERSION__);
582#elif defined(_MSC_VER)
583 line.append (
"MSVC");
585 snprintf (msvc_ver,
sizeof (msvc_ver),
" - %d", _MSC_VER);
586 line.append (msvc_ver);
588 line.append (
"an unknown compiler");
590#if !(defined(__APPLE__) || defined(__linux__) || defined(__unix__) \
593#if defined(__ARM_PCS_VFP) || defined(__ARM_FP)
594 line.append (
", with FP");
596 line.append (
", no FP");
599#if defined(__cpp_exceptions)
600 line.append (
", with exceptions");
602 line.append (
", no exceptions");
604#if defined(MICRO_OS_PLUS_DEBUG_ENABLED)
605 line.append (
", with MICRO_OS_PLUS_DEBUG_ENABLED");
607#if defined(MICRO_OS_PLUS_DIAG_TRACE_ENABLED)
608 line.append (
", with MICRO_OS_PLUS_DIAG_TRACE_ENABLED");
611 write_line (to_console,
"%s\n", line.c_str ());
728 buffer_.append (v ?
"true" :
"false");
756 if (message.empty ())
774 const size_t begin =
buffer_.size ();
816 snprintf (message,
sizeof (message),
817 ", time: %" PRIu32
".%03" PRIu32
" ms",
818 static_cast<uint32_t
> (elapsed / 1000),
819 static_cast<uint32_t
> (elapsed % 1000));
841 = 21 + (std::numeric_limits<size_t>::digits10 + 1);
853 constexpr const char*
856 return count == 1 ?
"" :
"s";
878 snprintf (message,
sizeof (message),
901 >= 54 + 4 * (std::numeric_limits<size_t>::digits10 + 1)
902 + 2 * (fragment_size - 1),
903 "totals_size_ too small for the session totals");
908 char message_skipped_test_cases[fragment_size];
911 char message_skipped_suites[fragment_size];
914 snprintf (message,
sizeof (message),
923 message_skipped_test_cases, suites_count, plural (suites_count),
924 message_skipped_suites);
938 char message_skipped[fragment_size];
941 if (totals.
passed ()) [[likely]]
943 snprintf (message,
sizeof (message),
953 snprintf (message,
sizeof (message),
975 if (totals.
passed ()) [[likely]]
977 snprintf (message,
sizeof (message),
983 char message_test_cases[fragment_size] =
"";
986 snprintf (message_test_cases,
sizeof (message_test_cases),
988 " test case%s failed",
993 snprintf (message,
sizeof (message),
Aggregated check and test case counters for a node in the test tree.
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 passed_checks(void) const noexcept
Returns the number of checks that passed.
size_t failed_test_cases(void) const noexcept
Returns the number of executed test cases that failed.
size_t failed_checks(void) const noexcept
Returns the number of checks that failed.
Abstract base class for the reporters that display test results, including operand values for failure...
bool has_output_file_error(void) const noexcept
Returns whether the output file could not be opened.
std::string buffer_
Output accumulation buffer.
bool has_output_file_error_
Whether the output file could not be opened.
bool writes_passed_checks(void) const noexcept
Returns whether the passed checks are written anywhere.
virtual void output_fail_prefix(const std::string &message, const bool has_expression, const reflection::source_location &location, const test_case &test_case)=0
Outputs the prefix for a failing condition.
const micro_test_plus::verbosity verbosity_
The verbosity level for test reporting.
FILE * output_file_
Optional output file, receiving a copy of the test report.
void end_line(void)
Appends a line ending to the internal output buffer.
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.
virtual const char * comment_prefix(void) const noexcept=0
Returns the comment-prefix string used by this reporter format.
void write_buffer_to_file(void)
Writes the current buffered content to the output file.
void announce_output_file(void)
Tells the console where the output file was written.
void fail(const failure_info &failure, const std::string &expression, const test_case &test_case)
Reports a failed condition.
reporter & operator<<(std::string_view sv)
Output operator for std::string_view.
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.
virtual ~reporter()
Virtual destructor for the reporter class.
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.
bool suite_displayed_
Whether the heading of the current suite was displayed on the console.
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.
virtual void output_pass_suffix(const test_case &test_case)=0
Outputs the suffix for a passing condition.
virtual void commit_buffer(void)=0
Writes the results buffered for the outer test case before a nested test case begins or is skipped.
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.
bool buffer_has_failures_
Whether the output buffer contains a failed check.
virtual const char * error_prefix(void) const noexcept
Returns the prefix of the lines that report an error.
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.
std::string output_file_path_
Path of the optional output file.
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.
void pass(const std::string &message, const std::string &expression, const test_case &test_case)
Reports a passed condition.
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,...
virtual void output_fail_suffix(const reflection::source_location &location, check_kind kind, const test_case &test_case)=0
Outputs the suffix for a failing condition.
void display_open_test_cases(bool include_last)
Displays the headings not yet displayed, of the open test cases.
virtual void output_pass_prefix(const std::string &message, const test_case &test_case)=0
Outputs the prefix for a passing condition.
output_route route(record_kind kind) const noexcept
Tells where a kind of record is written.
virtual void display_open_heading(const open_test_case &open, bool is_first)=0
Writes the heading of an open test case.
const counters & totals(void) const noexcept
Returns the totals of the node.
Measures the elapsed time of an operation.
std::chrono::microseconds elapsed(void) const noexcept
Returns the time elapsed between start() and stop().
The configuration of a test session, and its command-line parser.
std::string output_file_path
Path of the optional output file.
size_t skipped_suites_count(void) const noexcept
Returns the count of the test suites skipped by the filter.
const counters & totals(void) const noexcept
Returns the totals of the test session.
size_t total_suites_count(void) const noexcept
Returns the count of all the test suites.
A named, runnable test suite registered with the test runner.
C++ header file with declarations for the µTest++ counters.
#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.
void format_skipped(size_t count, char(&message)[fragment_size])
Formats the number of items skipped by the filter.
constexpr size_t fragment_size
Size of the array that receives a fragment of the totals.
constexpr const char * plural(size_t count) noexcept
Returns the plural suffix for a count.
void write_without_colours(FILE *file, std::string_view text)
Writes a text to a file, without the ANSI colour sequences.
Internal implementation details for the µTest++ framework.
reporter & endl(reporter &stream)
Output stream manipulator for ending a line in test reports.
record_kind
The kinds of records written by the reporters.
@ test_case_heading
The heading that marks the beginning of a test case.
@ abort
The report of an aborted test execution.
@ info
The informational lines written at the beginning of the session.
@ passed_check
The line of a passed check.
@ failed_check
The lines of a failed check, or the failure of a suite.
@ total
The totals of the session.
C++ header file with declarations for the µTest++ test reporter.
C++ header file with declarations for the µTest++ test runner.
C++ header file with declarations for the µTest++ stopwatch.
The details of a check, displayed when it fails.
bool has_expression
Indicates whether the check has an associated expression.
reflection::source_location location
The source location of the check.
std::string message
The message passed via operator<<(), if any.
check_kind kind
The kind of the check.
Parameterised stream manipulator for outputting indentation.
size_t level
Number of four-space indentation levels.
The destinations of a record.
bool console
Whether the record is written to the console.
A test case that has begun and not yet ended.
bool name_displayed
Whether the heading of the test case was displayed.
C++ header file with declarations for the µTest++ test hierarchy.
C++ header file with declarations for the µTest++ utility helpers.