42#if __has_include("micro-os-plus/diag/trace.h")
43#include "micro-os-plus/diag/trace.h"
53#pragma GCC diagnostic ignored "-Waggregate-return"
55#pragma clang diagnostic ignored "-Wunknown-warning-option"
56#pragma clang diagnostic ignored "-Wc++98-compat"
57#pragma clang diagnostic ignored "-Wc++98-c++11-c++14-compat"
58#pragma clang diagnostic ignored "-Wpre-c++17-compat"
59#pragma clang diagnostic ignored "-Wc++20-compat"
60#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
66#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_ENABLED)
98 " --verbose | --quiet | --silent\n"
99 " --list-tests, --list\n"
100 " --reporter=human|tap\n"
101 " --output-file=<path>\n"
102 " --colour[=always|never|auto], --color[=...]\n"
103 " --use-colour=yes|no|auto, --use-color=...\n"
104 " --filter=<pattern>\n"
105 " Run only the matching names; repeat the option for each\n"
106 " nesting level: the first pattern applies to the suite\n"
107 " names, the second to the test case names, and each\n"
108 " further one to the nested test cases. The patterns use\n"
109 " '*' and '?', and '|' separates alternatives.\n";
122#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
123 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
top_suite_.
name ());
127#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
138#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
139 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
top_suite_.
name ());
151#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
152 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
169#pragma GCC diagnostic push
171#if defined(__clang__)
172#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
176#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
198 return add_top_suite (top_suite_name !=
nullptr ? top_suite_name :
"");
218#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
219 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
221#if !(defined(MICRO_OS_PLUS_STARTUP_ENABLED) \
222 && defined(MICRO_OS_PLUS_DIAG_TRACE_ENABLED))
223#if defined(MICRO_OS_PLUS_DEBUG_ENABLED)
224 trace::printf (
"argv[");
225 for (
int i = 0; i < argc; ++i)
229 trace::printf (
", ");
231 trace::printf (
"'%s'", argv[i]);
275#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
276 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
281 fprintf (stderr,
"error: test execution aborted\n");
313 = std::make_unique<detail::reporter_human> (console_options);
318 = std::make_unique<detail::reporter_tap> (console_options);
323 fprintf (stderr,
"error: %s\n", error.c_str ());
326 reporter_->error_prefix (), error.c_str ());
332 "%sUse --help to list the options.\n",
343 "Usage: %s [options] [--] "
345 program, help_options);
369 "%sfailed to open output file '%s'\n",
387 ?
"All available test cases:"
388 :
"Matching test cases:");
422 const std::string_view requested_name{ top_suite_name.
name () };
424#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
425 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
430 fprintf (stderr,
"error: test execution aborted\n");
450 if (!requested_name.empty ())
467 const auto dot_pos = top_suite_name_view.rfind (
'.');
468 if (dot_pos != std::string_view::npos)
470 top_suite_name_view = top_suite_name_view.substr (0, dot_pos);
520#pragma GCC diagnostic pop
540 const size_t separator = alternatives.find (
'|');
545 if (separator == std::string_view::npos)
549 alternatives.remove_prefix (separator + 1);
601#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
602 trace::printf (
"%s '%s'\n", __PRETTY_FUNCTION__,
suite->name ());
631 std::string message{
"suite '" };
632 message.append (
name);
633 message.append (
"' added after run_suites() started, rejected");
663 fprintf (stderr,
"error: %s\n", message.c_str ());
675 "%serror: %s\n",
reporter_->comment_prefix (),
684 message, location !=
nullptr
699 "%serror: %s\n",
reporter_->comment_prefix (),
732 started = started->started_next_)
734 if (started == &test_runner)
736 test_runner.reject_suite (
suite.name (),
737 suite.located_name_.location ());
783 suite_ptr !=
nullptr; suite_ptr = suite_ptr->
next_)
786 if (&suite_ptr->test_runner () !=
this)
791 suite_ptr->own_index_ = ++own_index;
808 totals_ += suite_ptr->totals ();
842#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
843 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
848 fprintf (stderr,
"error: test execution aborted\n");
861 fprintf (stderr,
"error: test runner already running\n");
888 test_cases, (test_cases == 1) ?
"" :
"s", suites,
889 (suites == 1) ?
"" :
"s");
897 fprintf (stderr,
"error: the filters selected no test case\n");
900 "%serror: the filters selected no test case\n",
930 fprintf (stderr,
"error: no test suites\n");
932 "%serror: no test suites\n",
937 const bool selected_nothing = !has_no_suites
940 if (selected_nothing)
942 fprintf (stderr,
"error: the filters selected no test case\n");
944 "%serror: the filters selected no test case\n",
964#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
965 trace::printf (
"%s -> %d\n", __PRETTY_FUNCTION__,
exit_code_);
971#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
1031#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
1032 trace::printf (
"%s\n", __PRETTY_FUNCTION__);
1042 reporter_->abort_session (sl, is_requirement);
1050 const unsigned long line = sl.
line ();
1051 fprintf (stderr,
"error: test execution aborted at %s:%lu\n",
1078#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
1115 suite_ptr !=
nullptr; suite_ptr = suite_ptr->
next_)
1117 if (&suite_ptr->test_runner () ==
this)
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 increment_failed_checks(size_t count=1) noexcept
Increments the failed-checks counter.
size_t next_test_point_number(void) noexcept
Advances to the next child test point, and returns its number.
const char * name(void) const noexcept
Returns the node name.
counters totals_
Totals for the node.
const counters & totals(void) const noexcept
Returns the totals of the node.
const char * name_
The node name.
void stop(void) noexcept
Records the stop time, from the system clock.
void start(void) noexcept
Records the start time, from the system clock.
A name of a suite or of a test case, with the location where it was given.
const char * name(void) const noexcept
Returns the name.
const reflection::source_location & location(void) const noexcept
Returns the location where the name was given.
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.
bool has_unknown_option(void) const noexcept
Checks whether an unknown option was found while parsing the command line.
bool help
Whether to display the usage and the list of the options, instead of running the tests.
const std::vector< std::string > & errors(void) const noexcept
Returns the errors found while parsing the command line.
bool has_errors(void) const noexcept
Checks whether errors were found while parsing the command line.
std::vector< std::string > filter_patterns
The patterns that select the suites and the test cases to run, one per nesting level.
std::string output_file_path
Path of the optional output file.
const std::vector< std::string > & arguments(void) const noexcept
Returns the complete command line, including argv[0], if any.
bool list_tests
Whether the test cases are listed instead of run.
reporter_kind selected_reporter
The reporter that displays the results.
micro_test_plus::verbosity verbosity_level
The level of detail of the console output.
The test runner for the µTest++ framework.
void reject_suite(const char *name, const reflection::source_location &location)
Rejects a suite constructed after run_suites() has started.
class suite * running_suite_
The suite whose body is running, if any.
counters totals_
Totals of the test session.
void run_child_suites(void)
Runs all registered test suites.
void list_test_case(const class suite &suite, const class test_case &test_case)
Lists a test case, instead of running it.
abort_handler_t abort_handler_
The function called by abort(), if not null.
bool has_option_errors(void) const noexcept
Checks whether an option error was found by initialise().
detail::stopwatch stopwatch_
Stopwatch of this runner.
static void link_static_suite(runner &test_runner, class suite &suite) noexcept
Inserts a static suite into the list of suites, or reject it.
int exit_code_
The exit code computed by run_suites().
void register_suite(std::unique_ptr< class suite > suite)
Registers a test suite with the runner.
void suite(std::string_view name, Callable_T &&callable, Args_T &&... arguments)
Deprecated name of add_suite().
runner * started_next_
The next runner in the list of the started runners.
bool is_selected(const char *name, size_t level) const
Checks whether a suite or a test case is selected by the filter pattern of its nesting level.
size_t skipped_suites_count(void) const noexcept
Returns the count of the test suites skipped by the filter.
class suite & initialise(int argc, char *argv[], const char *top_suite_name)
Deprecated initialisation with the command-line arguments, which also adds the top suite.
bool has_top_suite_
Whether the top suite was added to the session.
void mark_rejected(void) noexcept
Records that a call was rejected.
runner(void)
Constructor for the runner class.
const char * name(void) const noexcept
Deprecated name of the runner.
static runner * started_first_
The head of the list of the runners that have started.
std::unique_ptr< detail::reporter > reporter_
Owning pointer to the test reporter used for outputting test results.
size_t static_suites_count(void) const noexcept
Returns the count of static test suites.
void reject_call(const std::string &message, const reflection::source_location *location=nullptr)
Reports a rejected call, and records it.
size_t suites_count(void) const noexcept
Deprecated count of the test suites added with add_suite(), plus the top suite.
int run_suites(void)
Runs the registered suites, ends the session, and returns the exit code.
session_state session_state_
The current state of the test session.
abort_handler_t set_abort_handler(abort_handler_t handler) noexcept
Sets the function called when test execution is aborted.
class suite & add_top_suite(const located_name &top_suite_name)
Adds the top suite and returns it.
void abort(const reflection::source_location &sl=reflection::source_location::current())
Aborts test execution immediately.
int exit_code(void)
Deprecated name of run_suites().
size_t listed_test_cases_count_
The number of listed test cases.
class top_suite top_suite_
The top suite, whose body is the code of main().
size_t added_suites_count(void) const noexcept
Returns the count of the test suites added with add_suite().
bool has_rejected_calls_
Whether a call was rejected.
class suite & add_top_suite(void)
Adds the top suite, without a name, and returns it.
void(*)(const reflection::source_location &sl) abort_handler_t
The type of the function called when test execution is aborted.
std::vector< std::unique_ptr< class suite > > children_suites_
Owning collection of dynamically registered child suites.
size_t total_suites_count(void) const noexcept
Returns the count of all the test suites.
size_t listed_suites_count_
The number of suites with listed test cases.
runner_options options_
The options of the test session.
test_case * running_test_case_
The innermost test case being run, if any.
bool aborted_
Whether the test execution was aborted.
size_t skipped_suites_count_
The number of suites skipped by the filter.
~runner()
Destructor for the runner class.
const class suite * listed_suite_
The suite whose name was listed last, if any.
A named, runnable test suite registered with the test runner.
static suite * first_
The first suite in the list of suites.
suite * next_
The next suite in the list of suites.
located_name located_name_
The name of the suite, with the location where it was given.
detail::stopwatch stopwatch_
Stopwatch of this suite.
A named, runnable test case that lives inside a suite.
void report_rejected_test(const std::string &message, const reflection::source_location &location)
Reports a rejected call as a failed check of this test case.
const located_name & located_name_
The name and the location of the call to test() that created 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.
bool is_match(std::string_view input, std::string_view pattern)
Checks whether a string matches a pattern with * and ? wildcards.
constexpr const char * help_options
The text displayed by --help, after the usage line.
Primary namespace for the µTest++ testing framework.
C++ header file with declarations for the µTest++ human-readable reporter.
C++ header file with declarations for the µTest++ TAP test reporter.
C++ header file with declarations for the µTest++ test runner.
C++ header file with declarations for the µTest++ utility helpers.