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#if defined(MICRO_OS_PLUS_TRACE)
54#include <micro-os-plus/diag/trace.h>
68#pragma GCC diagnostic ignored "-Waggregate-return"
70#pragma clang diagnostic ignored "-Wunknown-warning-option"
71#pragma clang diagnostic ignored "-Wc++98-compat"
72#pragma clang diagnostic ignored "-Wc++98-c++11-c++14-compat"
73#pragma clang diagnostic ignored "-Wpre-c++17-compat"
92 return static_cast<runner&> (static_runner_ref);
118#if defined(MICRO_OS_PLUS_TRACE) \
119 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
121#pragma GCC diagnostic push
122#if defined(__clang__)
123#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
126 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
128#pragma GCC diagnostic pop
142#if defined(MICRO_OS_PLUS_TRACE) \
143 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
145#pragma GCC diagnostic push
146#if defined(__clang__)
147#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
150 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
152#pragma GCC diagnostic pop
164#if defined(MICRO_OS_PLUS_TRACE) \
165 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
166 trace::printf ("%s\n", __PRETTY_FUNCTION__);
173#pragma GCC diagnostic push
174#if defined(__clang__)
175#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
193#if defined(MICRO_OS_PLUS_TRACE) \
194 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
195 trace::printf ("%s\n", __PRETTY_FUNCTION__);
198#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
199#if defined(MICRO_OS_PLUS_DEBUG)
200 trace::printf ("argv[");
201 for (int i = 0; i < argc; ++i)
205 trace::printf (", ");
207 trace::printf ("'%s'", argv[i]);
213 if (strlen (top_suite_name) > 0)
225 if (argc > 0 && argv != nullptr && argv[0] != nullptr)
230 const auto dot_pos = top_suite_name_view.rfind ('.');
231 if (dot_pos != std::string_view::npos)
233 top_suite_name_view = top_suite_name_view.substr (0, dot_pos);
245 std::vector<std::string_view> argvs (argv, argv + argc);
247 std::string_view reporter_name{ "tap" };
248 static constexpr std::string_view reporter_prefix{ "--reporter=" };
249 for (size_t i = 0; i < argvs.size (); ++i)
251 if (argvs[i].starts_with (reporter_prefix))
253 reporter_name = argvs[i].substr (reporter_prefix.size ());
256 == reporter_prefix.substr (0, reporter_prefix.size () - 1))
258 if (i + 1 < argvs.size ())
260 reporter_name = argvs[++i];
264 fprintf (stderr, "error: --reporter option requires a "
265 "reporter name argument\n");
272 if (reporter_name == "human")
274 reporter_ = std::make_unique<reporter_human> (
275 std::make_unique<std::vector<std::string_view>> (
278 else if (reporter_name == "tap")
280 reporter_ = std::make_unique<reporter_tap> (
281 std::make_unique<std::vector<std::string_view>> (
286 fprintf (stderr, "error: unknown reporter '%.*s'\n",
287 static_cast<int> (reporter_name.size ()),
288 reporter_name.data ());
303#pragma GCC diagnostic pop
318#if defined(MICRO_OS_PLUS_TRACE) \
319 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
321#pragma GCC diagnostic push
322#if defined(__clang__)
323#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
326 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite->name ());
328#pragma GCC diagnostic pop
353 for (size_t i = 0; i < n; ++i)
356 for (size_t j = i + 1; j < n; ++j)
366 for (size_t i = 0; i < n; ++i)
371 suite_ptr->own_index (i + 1 + 1);
379 totals_ += suite_ptr->totals ();
395#if defined(MICRO_OS_PLUS_TRACE) \
396 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
397 trace::printf ("%s\n", __PRETTY_FUNCTION__);
402 fprintf (stderr, "error: test runner not initialised\n");
415 const int result = totals_.was_successful () ? 0 : 1;
417#if defined(MICRO_OS_PLUS_TRACE) \
418 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
420#pragma GCC diagnostic push
421#if defined(__clang__)
422#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
425 trace::printf ("%s -> %d\n", __PRETTY_FUNCTION__, result);
427#pragma GCC diagnostic pop
442#if defined(MICRO_OS_PLUS_TRACE) \
443 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
444 trace::printf ("%s\n", __PRETTY_FUNCTION__);
448#pragma GCC diagnostic push
449#if defined(__clang__)
450#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
453 fprintf (stderr, "\nerror: test execution aborted at %s:%u\n",
456#pragma GCC diagnostic pop
494#if defined(MICRO_OS_PLUS_TRACE) \
495 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
497#pragma GCC diagnostic push
498#if defined(__clang__)
499#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
502 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
504#pragma GCC diagnostic pop
516 : runner{ top_suite_name }
518#if defined(MICRO_OS_PLUS_TRACE) \
519 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
521#pragma GCC diagnostic push
522#if defined(__clang__)
523#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
526 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
528#pragma GCC diagnostic pop
543#if defined(MICRO_OS_PLUS_TRACE) \
544 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_CONSTRUCTORS_ENABLED)
545 trace::printf ("%s\n", __PRETTY_FUNCTION__);
593#if defined(MICRO_OS_PLUS_TRACE) \
594 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
595 trace::printf ("%s\n", __PRETTY_FUNCTION__);
607 for (size_t i = 0; i < n; ++i)
610 for (size_t j = i + 1; j < n; ++j)
612 if (std::string_view{ suites[j]->name () }
613 < std::string_view{ suites[min_idx]->name () })
617 std::swap (suites[i], suites[min_idx]);
620 for (size_t i = 0; i < n; ++i)
622 auto* suite_ptr = suites[i];
632 totals_ += suite_ptr->totals ();
649#if defined(MICRO_OS_PLUS_TRACE) \
650 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
652#pragma GCC diagnostic push
653#if defined(__clang__)
654#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
657 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite.name ());
659#pragma GCC diagnostic pop
663 if (runner.static_children_suites_ == nullptr)
665#if defined(MICRO_OS_PLUS_TRACE) \
666 && defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_TRACE_ENABLED)
667 trace::printf ("%s new static_children_suites_ array\n",
668 __PRETTY_FUNCTION__);
670 runner.static_children_suites_ = new std::vector<static_suite*>;
672 runner.static_children_suites_->push_back (&suite);
Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.