Skip to main content

The test_runner Class Reference

The test runner for the µTest++ framework. More...

Declaration

class micro_os_plus::micro_test_plus::test_runner { ... }

Included Headers

Public Constructors Index

test_runner ()

Default constructor for the test_runner class. More...

test_runner (const test_runner &)=delete

Deleted copy constructor to prevent copying. More...

test_runner (test_runner &&)=delete

Deleted move constructor to prevent moving. More...

Public Destructor Index

~test_runner ()=default

Destructor for the test_runner class. More...

Public Operators Index

test_runner &operator= (const test_runner &)=delete

Deleted copy assignment operator to prevent copying. More...

test_runner &operator= (test_runner &&)=delete

Deleted move assignment operator to prevent moving. More...

Public Member Functions Index

voidabort (void)

Aborts test execution immediately. More...

intexit_code (void)

Returns 0 if all tests were successful, 1 otherwise. More...

voidinitialize (int argc, char *argv[], const char *name)

Initialises the test runner with command-line arguments and an optional suite name. More...

constexpr const char *name (void)

Retrieves the name of the default test suite. More...

voidregister_test_suite (test_suite_base *suite)

Registers a test suite with the runner. More...

Protected Member Attributes Index

intargc_ = 0

Stores the argument count passed to the test runner. More...

char **argv_ = nullptr

Stores the argument vector passed to the test runner. More...

const char *default_suite_name_ = "Test"

The name of the default test suite. More...

test_suite_base *default_test_suite_

Pointer to the default test suite which groups the main tests. More...

std::vector< test_suite_base * > *suites_

Pointer to the array of registered test suites. More...

Description

The test runner for the µTest++ framework.

The test_runner class is responsible for managing the registration and execution of test suites within the µTest++ framework. It maintains a collection of test suites, each of which registers itself automatically upon construction, enabling seamless integration and execution of tests across different components and folders of a project.

The test runner provides methods for initialising the test environment, registering test suites, retrieving the runner's name, and determining the overall test result via an exit code. It also offers an abort mechanism for terminating test execution in exceptional circumstances.

All members and methods are defined within the micro_os_plus::micro_test_plus namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

Definition at line 96 of file test-runner.h.

Public Constructors

test_runner()

micro_os_plus::micro_test_plus::test_runner::test_runner ()

Default constructor for the test_runner class.

The rule of five is enforced to prevent accidental copying or moving.

The constructor initialises a new instance of the test_runner class, preparing the test runner for managing test suites and cases within the µTest++ framework. If tracing is enabled, it outputs the function signature for diagnostic purposes. This setup ensures the test runner is ready to coordinate the registration, execution, and reporting of tests across all test cases and folders.

Declaration at line 105 of file test-runner.h, definition at line 72 of file test-runner.cpp.

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 }

Referenced by test_runner, test_runner, operator= and operator=.

test_runner()

micro_os_plus::micro_test_plus::test_runner::test_runner (const test_runner &)
delete

Deleted copy constructor to prevent copying.

Definition at line 110 of file test-runner.h.

Reference test_runner.

test_runner()

micro_os_plus::micro_test_plus::test_runner::test_runner (test_runner &&)
delete

Deleted move constructor to prevent moving.

Definition at line 115 of file test-runner.h.

Reference test_runner.

Public Destructor

~test_runner()

micro_os_plus::micro_test_plus::test_runner::~test_runner ()
default

Destructor for the test_runner class.

Definition at line 134 of file test-runner.h.

Reference name.

Public Operators

operator=()

test_runner & micro_os_plus::micro_test_plus::test_runner::operator= (const test_runner &)
delete

Deleted copy assignment operator to prevent copying.

Definition at line 121 of file test-runner.h.

Reference test_runner.

operator=()

test_runner & micro_os_plus::micro_test_plus::test_runner::operator= (test_runner &&)
delete

Deleted move assignment operator to prevent moving.

Definition at line 128 of file test-runner.h.

Reference test_runner.

Public Member Functions

abort()

void micro_os_plus::micro_test_plus::test_runner::abort (void)

Aborts test execution immediately.

Parameters

None.

Returns

Nothing.

This method immediately terminates the process by invoking the standard C library abort() function. It is used to halt test execution in critical failure scenarios, ensuring that no further tests are run and that the cause of the failure can be promptly investigated. This approach provides a robust mechanism for enforcing strict test outcomes across all test cases and folders.

Declaration at line 192 of file test-runner.h, definition at line 255 of file test-runner.cpp.

256 {
257 ::abort ();
258 }

Reference abort.

Referenced by abort.

exit_code()

int micro_os_plus::micro_test_plus::test_runner::exit_code (void)

Returns 0 if all tests were successful, 1 otherwise.

Parameters

None.

Returns

Integer exit code representing the overall test result.

Declaration at line 157 of file test-runner.h, definition at line 190 of file test-runner.cpp.

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 }

References micro_os_plus::micro_test_plus::current_test_suite, default_test_suite_, micro_os_plus::micro_test_plus::reporter, micro_os_plus::micro_test_plus::silent and suites_.

initialize()

void micro_os_plus::micro_test_plus::test_runner::initialize (int argc, char * argv=[], const char * name)

Initialises the test runner with command-line arguments and an optional suite name.

Parameters
argc

The argument count from main().

argv

The argument vector from main().

name

The name of the default test suite.

Returns

Nothing.

This method initialises the test runner by capturing the command-line arguments and the default test suite name, configuring the framework for subsequent test execution. It parses the arguments to determine the desired verbosity level (normal, verbose, quiet, or silent) and applies this setting to the test reporter. The method also outputs build and environment information when appropriate, aiding diagnostics and transparency. Finally, it creates and registers the default test suite, preparing the framework to manage and execute all test cases and suites across the project’s folders.

Declaration at line 147 of file test-runner.h, definition at line 96 of file test-runner.cpp.

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)
152 // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170
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 }

References argc_, argv_, micro_os_plus::micro_test_plus::current_test_suite, default_suite_name_, default_test_suite_, name, micro_os_plus::micro_test_plus::normal, micro_os_plus::micro_test_plus::quiet, micro_os_plus::micro_test_plus::reporter, micro_os_plus::micro_test_plus::silent and micro_os_plus::micro_test_plus::verbose.

name()

const char * micro_os_plus::micro_test_plus::test_runner::name (void)
inline constexpr

Retrieves the name of the default test suite.

Parameters

None.

Returns

The name of the default test suite as a constant character pointer.

Definition at line 178 of file test-runner.h.

178 name (void)
179 {
181 }

Reference default_suite_name_.

Referenced by ~test_runner and initialize.

register_test_suite()

void micro_os_plus::micro_test_plus::test_runner::register_test_suite (test_suite_base * suite)

Registers a test suite with the runner.

Parameters
suite

Pointer to the test suite to register.

Returns

Nothing.

This method registers a new test suite with the test runner. If the internal collection of test suites has not yet been created, it is initialised at this point. The provided test suite is then added to the collection, enabling the framework to manage and execute multiple test suites across different files and folders within the project.

Called by test suite constructors to register themselves with the runner, enabling automatic management and execution.

Declaration at line 167 of file test-runner.h, definition at line 232 of file test-runner.cpp.

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 }

Reference suites_.

Protected Member Attributes

argc_

int micro_os_plus::micro_test_plus::test_runner::argc_ = 0
protected

Stores the argument count passed to the test runner.

Definition at line 198 of file test-runner.h.

198 int argc_ = 0;

Referenced by initialize.

argv_

char** micro_os_plus::micro_test_plus::test_runner::argv_ = nullptr
protected

Stores the argument vector passed to the test runner.

Definition at line 203 of file test-runner.h.

203 char** argv_ = nullptr;

Referenced by initialize.

default_suite_name_

const char* micro_os_plus::micro_test_plus::test_runner::default_suite_name_ = "Test"
protected

The name of the default test suite.

Definition at line 208 of file test-runner.h.

208 const char* default_suite_name_ = "Test";

Referenced by initialize and name.

default_test_suite_

test_suite_base* micro_os_plus::micro_test_plus::test_runner::default_test_suite_
protected

Pointer to the default test suite which groups the main tests.

Definition at line 213 of file test-runner.h.

Referenced by exit_code and initialize.

suites_

std::vector<test_suite_base*>* micro_os_plus::micro_test_plus::test_runner::suites_
protected

Pointer to the array of registered test suites.

Statically initialised to zero as BSS, such that test suites defined as static objects in different compilation units can be automatically executed.

Definition at line 223 of file test-runner.h.

223 std::vector<test_suite_base*>* suites_;

Referenced by exit_code and register_test_suite.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus by Doxygen 1.14.0.