43#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
44#include <micro-os-plus/config.h>
47#if defined(MICRO_OS_PLUS_TRACE)
48#include <micro-os-plus/diag/trace.h>
56#pragma GCC diagnostic ignored "-Waggregate-return"
58#pragma clang diagnostic ignored "-Wunknown-warning-option"
59#pragma clang diagnostic ignored "-Wc++98-compat"
60#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
81#if defined(MICRO_OS_PLUS_TRACE) \
82 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
83 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
86 std::string_view output_file_sv{};
88 argvs_ = std::move (argvs);
90 static constexpr std::string_view output_file_prefix{
"--output-file=" };
93 const auto& args = *
argvs_;
94 for (
size_t i = 0; i < args.size (); ++i)
96 if (args[i] ==
"--verbose")
100 else if (args[i] ==
"--quiet")
104 else if (args[i] ==
"--silent")
108 else if (args[i].starts_with (output_file_prefix))
110 output_file_sv = args[i].substr (output_file_prefix.size ());
113 == output_file_prefix.substr (
114 0, output_file_prefix.size () - 1))
116 if (i + 1 < args.size ())
118 output_file_sv = args[++i];
122 fprintf (stderr,
"error: --output-file option requires a "
123 "file path argument\n");
130 if (!output_file_sv.empty ())
138#pragma GCC diagnostic push
139#if defined(__clang__)
140#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
143 fprintf (stderr,
"error: Failed to open output file '%.*s'\n",
144 static_cast<int> (output_file_sv.size ()),
145 output_file_sv.data ());
147#pragma GCC diagnostic pop
169#if defined(MICRO_OS_PLUS_TRACE) \
170 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
171 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
180#pragma GCC diagnostic push
181#if defined(__clang__)
182#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
187#pragma GCC diagnostic pop
240 printf (
"%s",
buffer_.c_str ());
278 line.append (
"Running: ");
281 const std::string_view arg0 = args[0];
282 const auto sep = arg0.rfind (
'/');
283 line.append ((sep != std::string_view::npos) ? arg0.substr (sep + 1)
286 for (
size_t i = 1; i < args.size (); ++i)
289 line.append (args[i]);
296#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
299 printf (
"%s", line.c_str ());
309 line.append (
"Built with ");
310#if defined(__clang__)
311 line.append (
"clang " __VERSION__);
312#elif defined(__GNUC__)
313 line.append (
"GCC " __VERSION__);
314#elif defined(_MSC_VER)
315 line.append (
"MSVC");
317 snprintf (msvc_ver,
sizeof (msvc_ver),
" - %d", _MSC_VER);
318 line.append (msvc_ver);
320 line.append (
"an unknown compiler");
322#if !(defined(__APPLE__) || defined(__linux__) || defined(__unix__) \
325#if defined(__ARM_PCS_VFP) || defined(__ARM_FP)
326 line.append (
", with FP");
328 line.append (
", no FP");
331#if defined(__EXCEPTIONS)
332 line.append (
", with exceptions");
334 line.append (
", no exceptions");
336#if defined(MICRO_OS_PLUS_DEBUG)
337 line.append (
", with MICRO_OS_PLUS_DEBUG");
339#if defined(MICRO_OS_PLUS_TRACE)
340 line.append (
", with MICRO_OS_PLUS_TRACE");
348#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
351 printf (
"%s\n", line.c_str ());
449 if (message.empty ())
464 const std::string&
expression,
bool has_expression,
Local implementation of source location information for diagnostics.
virtual const char * get_comment_prefix(void) override
Returns an empty comment prefix string.
Reporter to display test results, including operand values and types for failures.
void fail(bool abort, std::string &message, const std::string &expression, bool has_expression, const reflection::source_location &location, subtest &subtest)
Report a failed condition.
reporter(std::unique_ptr< std::vector< std::string_view > > argvs)
Constructor for the reporter class.
std::unique_ptr< std::vector< std::string_view > > argvs_
Owns the command-line arguments passed to the test runner.
virtual void output_pass_suffix_(subtest &subtest)=0
Outputs the suffix for a passing condition.
virtual ~reporter()
Virtual destructor for the reporter class.
void pass(std::string &message, const std::string &expression, subtest &subtest)
Report a passed condition.
FILE * output_file_
Optional output file for redirecting test report output.
void write_buffer_to_stdout(void)
Output the current buffered content.
virtual void output_fail_prefix_(std::string &message, const bool has_expression, const reflection::source_location &location, subtest &subtest)=0
Outputs the prefix for a failing condition.
std::string buffer_
Output accumulation buffer.
void write_info_(void)
Appends informational (non-result) text to the output buffer.
virtual const char * get_comment_prefix(void)=0
Returns the comment-prefix string used by this reporter format.
virtual void output_pass_prefix_(std::string &message, subtest &subtest)=0
Outputs the prefix for a passing condition.
const char * output_file_path_
Optional file path for redirecting test report output.
detail::expression_formatter & expression()
Provides access to the expression formatter for this reporter.
reporter & operator<<(std::string_view sv)
Output operator for std::string_view.
void write_buffer_to_file_(void)
void flush(void)
Flush the current buffered content.
enum verbosity verbosity_
The verbosity level for test reporting.
void endline(void)
Inserts a line ending into the output buffer.
virtual void output_fail_suffix_(const reflection::source_location &location, bool abort, subtest &subtest)=0
Outputs the suffix for a failing condition.
A named, runnable test case that lives inside a suite.
Primary namespace for the µTest++ testing framework.
reporter & endl(reporter &stream)
Output stream manipulator for ending a line in test reports.
C++ header file with declarations for the µTest++ test reporter.