39#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_REPORTER_H_
40#define MICRO_OS_PLUS_MICRO_TEST_PLUS_REPORTER_H_
44#if defined(__cplusplus)
48#if __has_include("micro-os-plus/project-config.h")
49#include "micro-os-plus/project-config.h"
52#if __has_include("micro-os-plus/micro-test-plus-defines.h")
53#include "micro-os-plus/micro-test-plus-defines.h"
75#pragma GCC diagnostic push
77#pragma GCC diagnostic ignored "-Wpadded"
78#pragma GCC diagnostic ignored "-Waggregate-return"
80#pragma clang diagnostic ignored "-Wc++98-compat"
81#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
378 requires std::is_arithmetic_v<T>
395 template <
typename T>
396 requires (not std::is_same_v<T, char>)
471#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
490 [[deprecated (
"use runner::verbosity_level() (since 6.0.0)"),
511 pass (
const std::string& message,
const std::string& expression,
865 [[nodiscard]] std::string_view
933 __attribute__ ((format (printf, 2, 3)))
952 __attribute__ ((format (printf, 2, 3)))
977 write_line (
bool to_console,
const char* format, ...)
979 __attribute__ ((format (printf, 3, 4)))
994 write_info (
const std::vector<std::string>& arguments);
1083 = 94 + 6 * (std::numeric_limits<size_t>::digits10 + 1);
1231 const bool has_expression,
1472#if defined(__GNUC__)
1473#pragma GCC diagnostic pop
C++ header file with declarations for the µTest++ check result.
The result of one check, reported when destroyed.
Abstract base class for the reporters that display test results, including operand values for failure...
virtual void begin_session(const runner &runner)=0
Marks the beginning of a test session.
virtual void skip_suite(const suite &suite)=0
Reports a test suite skipped by the filter.
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 end_test_case(const test_case &test_case)=0
Marks the end of a test case.
virtual void skip_test_case(const test_case &test_case)=0
Reports a test case skipped by the filter.
virtual void fail_suite(const std::string &message, const suite &suite)=0
Reports a failure of a test suite outside its test cases.
virtual void end_session(const runner &runner)=0
Marks the end of a test session.
virtual void abort_session(const reflection::source_location &location, bool is_requirement)=0
Reports the abort of the test execution.
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.
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.
void fail(const failure_info &failure, const std::string &expression, const test_case &test_case)
Reports a failed condition.
auto verbosity(void) const noexcept -> micro_test_plus::verbosity
Deprecated access to the verbosity level.
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.
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.
virtual void pass_without_text(const test_case &test_case)=0
Reports a passed condition whose text is not written.
friend class micro_test_plus::runner
The runner, which lists the test cases.
colours colours_
ANSI colour codes for output formatting.
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.
virtual void end_suite(const suite &suite)=0
Marks the end of a test suite.
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.
virtual void begin_test_case(const test_case &test_case)=0
Marks the beginning of a test case.
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.
expression_formatter expression_
Expression formatter for pass and fail reporting.
virtual void begin_suite(const suite &suite)=0
Marks the beginning of a test suite.
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.
friend class check_result
The check result, which formats the expressions.
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.
Measures the elapsed time of an operation.
Local implementation of source location information for diagnostics.
The configuration of a test session, and its command-line parser.
The test runner for the µTest++ framework.
A named, runnable test suite registered with the test runner.
A named, runnable test case that lives inside a suite.
C++ header file with declarations for the µTest++ internals.
C++ header file with declarations for the µTest++ extension concepts.
verbosity
The verbosity levels for test reporting.
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.
record_kind
The kinds of records written by the reporters.
@ 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.
@ 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.
@ skipped
The line of a suite or of a test case skipped by the filter.
@ total
The totals of the session.
Primary namespace for the µTest++ testing framework.
C++ header file with declarations for the µTest++ reflection utilities.
C++ header file with inline implementations for the µTest++ test reporter.
C++ header file with declarations for the µTest++ runner options.
Colours used to highlight pass and fail results in test reports.
The details of a check, displayed when it fails.
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.
bool file
Whether the record is written to the output file.
A test case that has begun and not yet ended.
bool name_displayed
Whether the heading of the test case was displayed.
const test_case * test
The test case.