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:
41#if __has_include(<micro-os-plus/project-config.h>)
42#include <micro-os-plus/project-config.h>
43#elif __has_include(<micro-os-plus/config.h>)
45 "micro-os-plus/config.h is deprecated, rename to micro-os-plus/project-config.h and include it instead of micro-os-plus/config.h"
46#include <micro-os-plus/config.h>
49#if __has_include(<micro-os-plus/micro-test-plus-defines.h>)
50#include <micro-os-plus/micro-test-plus-defines.h>
53#include <micro-os-plus/diag/trace.h>
66#pragma GCC diagnostic ignored "-Waggregate-return"
68#pragma clang diagnostic ignored "-Wunknown-warning-option"
69#pragma clang diagnostic ignored "-Wc++98-compat"
70#pragma clang diagnostic ignored "-Wc++98-c++11-c++14-compat"
71#pragma clang diagnostic ignored "-Wpre-c++17-compat"
90 return static_cast<runner&> (static_runner_ref);
116#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
118#pragma GCC diagnostic push
119#if defined(__clang__)
120#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
123 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
125#pragma GCC diagnostic pop
139#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
141#pragma GCC diagnostic push
142#if defined(__clang__)
143#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
146 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
148#pragma GCC diagnostic pop
160#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
161 trace::printf ("%s\n", __PRETTY_FUNCTION__);
168#pragma GCC diagnostic push
169#if defined(__clang__)
170#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
188#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
189 trace::printf ("%s\n", __PRETTY_FUNCTION__);
192#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) \
193 && defined(MICRO_OS_PLUS_DIAG_TRACE_ENABLED))
194#if defined(MICRO_OS_PLUS_DEBUG)
195 trace::printf ("argv[");
196 for (int i = 0; i < argc; ++i)
200 trace::printf (", ");
202 trace::printf ("'%s'", argv[i]);
208 if (strlen (top_suite_name) > 0)
220 if (argc > 0 && argv != nullptr && argv[0] != nullptr)
225 const auto dot_pos = top_suite_name_view.rfind ('.');
226 if (dot_pos != std::string_view::npos)
228 top_suite_name_view = top_suite_name_view.substr (0, dot_pos);
240 std::vector<std::string_view> argvs (argv, argv + argc);
242 std::string_view reporter_name{ "tap" };
243 static constexpr std::string_view reporter_prefix{ "--reporter=" };
244 for (size_t i = 0; i < argvs.size (); ++i)
246 if (argvs[i].starts_with (reporter_prefix))
248 reporter_name = argvs[i].substr (reporter_prefix.size ());
251 == reporter_prefix.substr (0, reporter_prefix.size () - 1))
253 if (i + 1 < argvs.size ())
255 reporter_name = argvs[++i];
259 fprintf (stderr, "error: --reporter option requires a "
260 "reporter name argument\n");
267 if (reporter_name == "human")
269 reporter_ = std::make_unique<reporter_human> (
270 std::make_unique<std::vector<std::string_view>> (
273 else if (reporter_name == "tap")
275 reporter_ = std::make_unique<reporter_tap> (
276 std::make_unique<std::vector<std::string_view>> (
281 fprintf (stderr, "error: unknown reporter '%.*s'\n",
282 static_cast<int> (reporter_name.size ()),
283 reporter_name.data ());
298#pragma GCC diagnostic pop
313#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
315#pragma GCC diagnostic push
316#if defined(__clang__)
317#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
320 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite->name ());
322#pragma GCC diagnostic pop
347 for (size_t i = 0; i < n; ++i)
350 for (size_t j = i + 1; j < n; ++j)
360 for (size_t i = 0; i < n; ++i)
365 suite_ptr->own_index (i + 1 + 1);
373 totals_ += suite_ptr->totals ();
389#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
390 trace::printf ("%s\n", __PRETTY_FUNCTION__);
395 fprintf (stderr, "error: test runner not initialised\n");
408 const int result = totals_.was_successful () ? 0 : 1;
410#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
412#pragma GCC diagnostic push
413#if defined(__clang__)
414#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
417 trace::printf ("%s -> %d\n", __PRETTY_FUNCTION__, result);
419#pragma GCC diagnostic pop
434#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
435 trace::printf ("%s\n", __PRETTY_FUNCTION__);
439#pragma GCC diagnostic push
440#if defined(__clang__)
441#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
444 fprintf (stderr, "\nerror: test execution aborted at %s:%u\n",
447#pragma GCC diagnostic pop
485#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
487#pragma GCC diagnostic push
488#if defined(__clang__)
489#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
492 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
494#pragma GCC diagnostic pop
506 : runner{ top_suite_name }
508#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
510#pragma GCC diagnostic push
511#if defined(__clang__)
512#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
515 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
517#pragma GCC diagnostic pop
532#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
533 trace::printf ("%s\n", __PRETTY_FUNCTION__);
581#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
582 trace::printf ("%s\n", __PRETTY_FUNCTION__);
594 for (size_t i = 0; i < n; ++i)
597 for (size_t j = i + 1; j < n; ++j)
599 if (std::string_view{ suites[j]->name () }
600 < std::string_view{ suites[min_idx]->name () })
604 std::swap (suites[i], suites[min_idx]);
607 for (size_t i = 0; i < n; ++i)
609 auto* suite_ptr = suites[i];
619 totals_ += suite_ptr->totals ();
636#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
638#pragma GCC diagnostic push
639#if defined(__clang__)
640#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
643 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite.name ());
645#pragma GCC diagnostic pop
649 if (runner.static_children_suites_ == nullptr)
651#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
652 trace::printf ("%s new static_children_suites_ array\n",
653 __PRETTY_FUNCTION__);
655 runner.static_children_suites_ = new std::vector<static_suite*>;
657 runner.static_children_suites_->push_back (&suite);
Generated via doxygen2docusaurus 2.2.1 by Doxygen 1.17.0.