Skip to main content

The test-runner.cpp File Reference

C++ source file with implementations for the µTest++ test runner methods. More...

Included Headers

#include <micro-os-plus/micro-test-plus.h>
#include <stdio.h>
#include <vector>

Namespaces Index

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespacemicro_os_plus::micro_test_plus

Primary namespace for the µTest++ testing framework. More...

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:

1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
10 *
11 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12 * released under the terms of the Boost Version 1 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE&#95;1&#95;0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
38
39// ----------------------------------------------------------------------------
40
41#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
42#include <micro-os-plus/config.h>
43#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
44
46
47#include <stdio.h>
48#include <vector>
49
50// ----------------------------------------------------------------------------
51
52#pragma GCC diagnostic ignored "-Waggregate-return"
53#if defined(__clang__)
54#pragma clang diagnostic ignored "-Wc++98-compat"
55#pragma clang diagnostic ignored "-Wc++98-c++11-c++14-compat"
56#pragma clang diagnostic ignored "-Wunknown-warning-option"
57#endif
58
60{
61 // --------------------------------------------------------------------------
62
73 {
74#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
75 printf ("%s\n", __PRETTY_FUNCTION__);
76#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
77 }
78
79#pragma GCC diagnostic push
80#if defined(__clang__)
81#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
82#endif
95 void
96 test_runner::initialize (int argc, char* argv[], const char* name)
97 {
98#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
99 printf ("%s\n", __PRETTY_FUNCTION__);
100#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
101
102 argc_ = argc;
103 argv_ = argv;
104
106
107#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
108#if defined(MICRO_OS_PLUS_DEBUG)
109 printf ("argv[");
110 for (int i = 0; i < argc; ++i)
111 {
112 if (i > 0)
113 {
114 printf (", ");
115 }
116 printf ("'%s'", argv[i]);
117 }
118 puts ("]");
119#endif // defined(MICRO_OS_PLUS_DEBUG)
120#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
121
123 for (int i = 0; i < argc; ++i)
124 {
125 if (strcmp (argv[i], "--verbose") == 0)
126 {
128 }
129 else if (strcmp (argv[i], "--quiet") == 0)
130 {
132 }
133 else if (strcmp (argv[i], "--silent") == 0)
134 {
136 }
137 }
138
139 // Pass the verbosity to the reporter.
140 reporter.verbosity = verbosity;
141
142 // ------------------------------------------------------------------------
143
144#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
146 {
147#if defined(__clang__)
148 printf ("Built with clang " __VERSION__);
149#elif defined(__GNUC__)
150 printf ("Built with GCC " __VERSION__);
151#elif defined(_MSC_VER)
153 printf ("Built with MSVC %d", _MSC_VER);
154#else
155 printf ("Built with an unknown compiler");
156#endif
157#if !(defined(__APPLE__) || defined(__linux__) || defined(__unix__) \
158 || defined(WIN32))
159// This is relevant only on bare-metal.
160#if defined(__ARM_PCS_VFP) || defined(__ARM_FP)
161 printf (", with FP");
162#else
163 printf (", no FP");
164#endif
165#endif
166#if defined(__EXCEPTIONS)
167 printf (", with exceptions");
168#else
169 printf (", no exceptions");
170#endif
171#if defined(MICRO_OS_PLUS_DEBUG)
172 printf (", with MICRO_OS_PLUS_DEBUG");
173#endif
174 puts (".");
175 }
176#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
177
178 // ------------------------------------------------------------------------
179
182
183 // Deferred to first test case or test suite end, to allow various
184 // initialisations to display their messages.
185 // default_test_suite_->begin_test_suite ();
186 }
187#pragma GCC diagnostic pop
188
189 int
191 {
192 bool was_successful = true;
193
194 if (!default_test_suite_->unused ())
195 {
196 default_test_suite_->end_test_suite ();
197 was_successful = default_test_suite_->was_successful ();
198 }
199
200 if (suites_ != nullptr)
201 {
202 for (auto suite : *suites_)
203 {
204 current_test_suite = suite;
205
206 suite->begin_test_suite ();
207 suite->run ();
208 suite->end_test_suite ();
209
210 was_successful &= suite->was_successful ();
211 }
212 if (reporter.verbosity != verbosity::silent)
213 {
214 // printf ("\n");
215 }
216 }
217 return was_successful ? 0 : 1;
218 }
219
231 void
233 {
234#if 0 // defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
235 printf ("%s\n", __PRETTY_FUNCTION__);
236#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
237
238 if (suites_ == nullptr)
239 {
240 suites_ = new std::vector<test_suite_base*> ();
241 }
242 suites_->push_back (suite);
243 }
244
254 void
256 {
257 ::abort ();
258 }
259
260 // --------------------------------------------------------------------------
261} // namespace micro_os_plus::micro_test_plus
262
263// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.