40#if __has_include("micro-os-plus/diag/trace.h")
41#include "micro-os-plus/diag/trace.h"
44#if defined(__APPLE__) || defined(__linux__) || defined(__unix__)
52#pragma GCC diagnostic ignored "-Waggregate-return"
54#pragma clang diagnostic ignored "-Wunknown-warning-option"
55#pragma clang diagnostic ignored "-Wc++98-compat"
56#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
57#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
63#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_ENABLED)
83#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
84 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
89#if defined(__APPLE__) || defined(__linux__) || defined(__unix__)
110#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
111 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
129#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
130 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
142 write_line (to_console,
"µTest++ human-readable report\n");
163#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
164 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
210#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
211 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
suite.
name ());
257#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
258 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
suite.
name ());
285 else if (!lines.empty ())
298 if (passed) [[likely]]
310 write_line (to_console,
"%s✗%s %s - %sFAILED%s (%s)%s\n",
336#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
337 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
suite.
name ());
369#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
370 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
suite.
name ());
373 const size_t begin =
buffer_.size ();
400#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
401 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
test_case.
name ());
454#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
476 const bool shows = to_console || !lines.empty ();
495 if (passed) [[likely]]
507 write_line (to_console,
"%s%s✗%s %s - %sFAILED%s (%s)\n",
559 *
this <<
indent (level + 1);
561 if (!message.empty ())
596 const std::string& message,
const bool has_expression,
600#pragma GCC diagnostic push
602#if defined(__clang__)
603#pragma clang diagnostic ignored "-Wsign-conversion"
604#elif defined(__GNUC__)
605#pragma GCC diagnostic ignored "-Wnarrowing"
606#pragma GCC diagnostic ignored "-Wsign-conversion"
612 *
this <<
indent (level + 1);
614 if (!message.empty ())
629#pragma GCC diagnostic pop
653#if defined(__cpp_exceptions)
654 *
this <<
" - test case stopped";
656 *
this <<
" - test execution aborted";
679#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
680 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
test_case.
name ());
752 [[maybe_unused]]
bool is_requirement)
754#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
755 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
763 const unsigned long line = location.
line ();
773 bool has_results = !lines.empty ()
777 has_results = has_results || !open.name_displayed;
797 write_line (to_console,
"%s✗%s Test execution aborted at %s:%lu\n",
bool passed(void) const noexcept
Checks whether all executed checks and test cases were successful.
size_t executed_test_cases(void) const noexcept
Returns the number of test cases that were executed.
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 output_pass_prefix(const std::string &message, const test_case &test_case) override
Outputs the prefix for a passing condition.
void begin_test_case(const test_case &test_case) override
Marks the beginning of a test case.
~reporter_human() override
Destructor for the reporter_human class.
void begin_suite(const suite &suite) override
Marks the beginning of a test suite.
void display_open_heading(const open_test_case &open, bool is_first) override
Writes the heading of an open test case.
void abort_session(const reflection::source_location &location, bool is_requirement) override
Reports the abort of the test execution.
void end_test_case(const test_case &test_case) override
Marks the end of a test case.
reporter_human(const runner_options &opts)
Constructor for the reporter_human class.
void begin_session(const runner &runner) override
Marks the beginning of a test session.
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.
void display_open_names(bool include_last)
Displays the headings not yet displayed, of the suite and of the open test cases.
void skip_suite(const suite &suite) override
Reports a test suite skipped by the filter.
void end_session(const runner &runner) override
Marks the end of a test session.
void commit_buffer(void) override
Writes the results buffered for the outer test case before a nested test case begins.
void output_pass_suffix(const test_case &test_case) override
Outputs the suffix for a passing condition.
void skip_test_case(const test_case &test_case) override
Reports a test case skipped by the filter.
const char * comment_prefix(void) const noexcept override
Returns an empty comment prefix string.
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 pass_without_text(const test_case &test_case) override
Ignores a passed check whose text is not written.
std::string buffer_
Output accumulation 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.
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.
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.
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.
bool buffer_has_failures_
Whether the output buffer contains a failed check.
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.
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.
const char * name(void) const noexcept
Returns the node name.
const counters & totals(void) const noexcept
Returns the totals of the node.
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.
colour_mode colour
Whether the console output uses colours.
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.
const counters & totals(void) const noexcept
Returns the totals of the test session.
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.
Internal implementation details for the µTest++ framework.
check_kind
The kind of a check, which determines what happens when it fails.
@ requirement
A check created by require().
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.
constexpr colours colours_red_green
Predefined colour set, with green for pass and red for fail.
@ 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++ human-readable reporter.
C++ header file with declarations for the µTest++ test runner.
const char * none
Terminal colour reset sequence.
const char * fail
Terminal colour sequence for failing tests.
const char * pass
Terminal colour sequence for passing tests.
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.