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:
44#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
45#include <micro-os-plus/config.h>
48#if defined(MICRO_OS_PLUS_TRACE)
49#include <micro-os-plus/diag/trace.h>
60#pragma GCC diagnostic ignored "-Waggregate-return"
62#pragma clang diagnostic ignored "-Wc++98-compat"
63#pragma clang diagnostic ignored "-Wc++98-c++11-c++14-compat"
64#pragma clang diagnostic ignored "-Wpre-c++17-compat"
83 return static_cast<runner&> (static_runner_ref);
109#if defined(MICRO_OS_PLUS_TRACE) \
110 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
112#pragma GCC diagnostic push
113#if defined(__clang__)
114#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
117 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
119#pragma GCC diagnostic pop
133#if defined(MICRO_OS_PLUS_TRACE) \
134 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
136#pragma GCC diagnostic push
137#if defined(__clang__)
138#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
141 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
143#pragma GCC diagnostic pop
155#if defined(MICRO_OS_PLUS_TRACE) \
156 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
157 trace::printf ("%s\n", __PRETTY_FUNCTION__);
164#pragma GCC diagnostic push
165#if defined(__clang__)
166#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
184#if defined(MICRO_OS_PLUS_TRACE) \
185 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
186 trace::printf ("%s\n", __PRETTY_FUNCTION__);
189#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
190#if defined(MICRO_OS_PLUS_DEBUG)
191 trace::printf ("argv[");
192 for (int i = 0; i < argc; ++i)
196 trace::printf (", ");
198 trace::printf ("'%s'", argv[i]);
204 if (strlen (top_suite_name) > 0)
216 if (argc > 0 && argv != nullptr && argv[0] != nullptr)
221 const auto dot_pos = top_suite_name_view.rfind ('.');
222 if (dot_pos != std::string_view::npos)
224 top_suite_name_view = top_suite_name_view.substr (0, dot_pos);
236 std::vector<std::string_view> argvs (argv, argv + argc);
238 std::string_view reporter_name{ "tap" };
239 static constexpr std::string_view reporter_prefix{ "--reporter=" };
240 for (size_t i = 0; i < argvs.size (); ++i)
242 if (argvs[i].starts_with (reporter_prefix))
244 reporter_name = argvs[i].substr (reporter_prefix.size ());
247 == reporter_prefix.substr (0, reporter_prefix.size () - 1))
249 if (i + 1 < argvs.size ())
251 reporter_name = argvs[++i];
255 fprintf (stderr, "error: --reporter option requires a "
256 "reporter name argument\n");
263 if (reporter_name == "human")
265 reporter_ = std::make_unique<reporter_human> (
266 std::make_unique<std::vector<std::string_view>> (
269 else if (reporter_name == "tap")
271 reporter_ = std::make_unique<reporter_tap> (
272 std::make_unique<std::vector<std::string_view>> (
277 fprintf (stderr, "error: unknown reporter '%.*s'\n",
278 static_cast<int> (reporter_name.size ()),
279 reporter_name.data ());
294#pragma GCC diagnostic pop
309#if defined(MICRO_OS_PLUS_TRACE) \
310 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
312#pragma GCC diagnostic push
313#if defined(__clang__)
314#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
317 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite->name ());
319#pragma GCC diagnostic pop
344 for (size_t i = 0; i < n; ++i)
347 for (size_t j = i + 1; j < n; ++j)
357 for (size_t i = 0; i < n; ++i)
362 suite_ptr->own_index (i + 1 + 1);
370 totals_ += suite_ptr->totals ();
386#if defined(MICRO_OS_PLUS_TRACE) \
387 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
388 trace::printf ("%s\n", __PRETTY_FUNCTION__);
393 fprintf (stderr, "error: test runner not initialised\n");
406 const int result = totals_.was_successful () ? 0 : 1;
408#if defined(MICRO_OS_PLUS_TRACE) \
409 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
411#pragma GCC diagnostic push
412#if defined(__clang__)
413#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
416 trace::printf ("%s -> %d\n", __PRETTY_FUNCTION__, result);
418#pragma GCC diagnostic pop
433#if defined(MICRO_OS_PLUS_TRACE) \
434 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
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_TRACE) \
486 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
488#pragma GCC diagnostic push
489#if defined(__clang__)
490#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
493 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
495#pragma GCC diagnostic pop
507 : runner{ top_suite_name }
509#if defined(MICRO_OS_PLUS_TRACE) \
510 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
512#pragma GCC diagnostic push
513#if defined(__clang__)
514#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
517 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, name ());
519#pragma GCC diagnostic pop
534#if defined(MICRO_OS_PLUS_TRACE) \
535 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS_CONSTRUCTORS)
536 trace::printf ("%s\n", __PRETTY_FUNCTION__);
584#if defined(MICRO_OS_PLUS_TRACE) \
585 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
586 trace::printf ("%s\n", __PRETTY_FUNCTION__);
598 for (size_t i = 0; i < n; ++i)
601 for (size_t j = i + 1; j < n; ++j)
603 if (std::string_view{ suites[j]->name () }
604 < std::string_view{ suites[min_idx]->name () })
608 std::swap (suites[i], suites[min_idx]);
611 for (size_t i = 0; i < n; ++i)
613 auto* suite_ptr = suites[i];
623 totals_ += suite_ptr->totals ();
640#if defined(MICRO_OS_PLUS_TRACE) \
641 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
643#pragma GCC diagnostic push
644#if defined(__clang__)
645#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
648 trace::printf ("%s '%s'\n", __PRETTY_FUNCTION__, suite.name ());
650#pragma GCC diagnostic pop
654 if (runner.static_children_suites_ == nullptr)
656#if defined(MICRO_OS_PLUS_TRACE) \
657 && defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
658 trace::printf ("%s new static_children_suites_ array\n",
659 __PRETTY_FUNCTION__);
661 runner.static_children_suites_ = new std::vector<static_suite*>;
663 runner.static_children_suites_->push_back (&suite);
Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.