C++ source file with implementations for the µTest++ test runner methods. More...
Namespaces Index
Description
C++ source file with implementations for the µTest++ test runner methods.
This source file contains the core implementations for the test runner facilities of the µTest++ framework. It provides the logic for initialising the test environment, registering and managing test suites, handling command-line arguments, orchestrating test execution, and determining the overall test result. The implementation supports automated discovery and execution of test suites, flexible verbosity control, and robust mechanisms for aborting test execution in critical scenarios.
All definitions reside within the micro_os_plus::micro_test_plus namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.
This file must be included when building the µTest++ library.
File Listing
The file content with the documentation metadata removed is:
46#if __has_include("micro-os-plus/diag/trace.h")
47#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-c++11-c++14-compat"
61#pragma clang diagnostic ignored "-Wpre-c++17-compat"
62#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
68#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_ENABLED)
85 return static_cast<runner&> (static_runner_ref);
111#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
112 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
125#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
126 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
137#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
138 trace::printf ("%s\n", __PRETTY_FUNCTION__);
145#pragma GCC diagnostic push
147#if defined(__clang__)
148#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
167#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
168 trace::printf ("%s\n", __PRETTY_FUNCTION__);
170#if !(defined(MICRO_OS_PLUS_STARTUP_ENABLED) \
171 && defined(MICRO_OS_PLUS_DIAG_TRACE_ENABLED))
172#if defined(MICRO_OS_PLUS_DEBUG_ENABLED)
173 trace::printf ("argv[");
174 for (int i = 0; i < argc; ++i)
178 trace::printf (", ");
180 trace::printf ("'%s'", argv[i]);
187 if (strlen (top_suite_name) > 0)
199 if (argc > 0 && argv != nullptr && argv[0] != nullptr)
204 const auto dot_pos = top_suite_name_view.rfind ('.');
205 if (dot_pos != std::string_view::npos)
207 top_suite_name_view = top_suite_name_view.substr (0, dot_pos);
219 std::vector<std::string_view> argvs (argv, argv + argc);
221 std::string_view reporter_name{ "tap" };
222 static constexpr std::string_view reporter_prefix{ "--reporter=" };
223 for (size_t i = 0; i < argvs.size (); ++i)
225 if (argvs[i].starts_with (reporter_prefix))
227 reporter_name = argvs[i].substr (reporter_prefix.size ());
230 == reporter_prefix.substr (0, reporter_prefix.size () - 1))
232 if (i + 1 < argvs.size ())
234 reporter_name = argvs[++i];
238 fprintf (stderr, "error: --reporter option requires a "
239 "reporter name argument\n");
246 if (reporter_name == "human")
248 reporter_ = std::make_unique<reporter_human> (
249 std::make_unique<std::vector<std::string_view>> (
252 else if (reporter_name == "tap")
254 reporter_ = std::make_unique<reporter_tap> (
255 std::make_unique<std::vector<std::string_view>> (
260 fprintf (stderr, "error: unknown reporter '%.*s'\n",
261 static_cast<int> (reporter_name.size ()),
262 reporter_name.data ());
278#pragma GCC diagnostic pop
293#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
294 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite->name ());
318 for (size_t i = 0; i < n; ++i)
321 for (size_t j = i + 1; j < n; ++j)
331 for (size_t i = 0; i < n; ++i)
336 suite_ptr->own_index (i + 1 + 1);
344 totals_ += suite_ptr->totals ();
360#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
361 trace::printf ("%s\n", __PRETTY_FUNCTION__);
366 fprintf (stderr, "error: test runner not initialised\n");
379 const int result = totals_.was_successful () ? 0 : 1;
381#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
382 trace::printf ("%s -> %d\n", __PRETTY_FUNCTION__, result);
396#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
397 trace::printf ("%s\n", __PRETTY_FUNCTION__);
400 fprintf (stderr, "\nerror: test execution aborted at %s:%u\n",
438#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
439 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
450 : runner{ top_suite_name }
452#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
453 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
467#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
468 trace::printf ("%s\n", __PRETTY_FUNCTION__);
516#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
517 trace::printf ("%s\n", __PRETTY_FUNCTION__);
529 for (size_t i = 0; i < n; ++i)
532 for (size_t j = i + 1; j < n; ++j)
534 if (std::string_view{ suites[j]->name () }
535 < std::string_view{ suites[min_idx]->name () })
539 std::swap (suites[i], suites[min_idx]);
542 for (size_t i = 0; i < n; ++i)
544 auto* suite_ptr = suites[i];
554 totals_ += suite_ptr->totals ();
571#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
572 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite.name ());
575 if (runner.static_children_suites_ == nullptr)
577#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
578 trace::printf ("%s new static_children_suites_ array\n",
579 __PRETTY_FUNCTION__);
581 runner.static_children_suites_ = new std::vector<static_suite*>;
583 runner.static_children_suites_->push_back (&suite);
Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.