micro-test-plus 3.3.1
µTest++ Testing Framework
Loading...
Searching...
No Matches
test-runner.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * 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 be
9 * obtained from https://opensource.org/licenses/mit.
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.0 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
44
45#ifndef MICRO_TEST_PLUS_TEST_RUNNER_H_
46#define MICRO_TEST_PLUS_TEST_RUNNER_H_
47
48// ----------------------------------------------------------------------------
49
50#ifdef __cplusplus
51
52// ----------------------------------------------------------------------------
53
54#include <functional>
55
56#include <time.h>
57
58// ----------------------------------------------------------------------------
59
60#if defined(__GNUC__)
61#pragma GCC diagnostic push
62#pragma GCC diagnostic ignored "-Wpadded"
63#if defined(__clang__)
64#pragma clang diagnostic ignored "-Wc++98-compat"
65#endif
66#endif
67
69{
70 // --------------------------------------------------------------------------
71
72 // Forward definition.
73 class test_suite_base;
74
75 // --------------------------------------------------------------------------
76
99 {
100 public:
107 test_runner ();
108
112 test_runner (const test_runner&) = delete;
113
118
124 = delete;
125
131 = delete;
132
136 ~test_runner () = default;
137
148 void
149 initialize (int argc, char* argv[], const char* name);
150
158 int
159 exit_code (void);
160
168 void
170
171 size_t
173 {
174 return (test_suites != nullptr) ? test_suites->size () + 1 : 1;
175 }
176
185 constexpr const char*
186 name (void)
187 {
188 return default_suite_name_;
189 }
190
199 [[noreturn]] void
200 abort (void);
201
202 // ------------------------------------------------------------------------
203 public:
212 std::vector<test_suite_base*>* test_suites; // DO NOT INITIALISE!
213
214 struct
215 {
220
224 size_t failed_checks = 0;
225
231
232#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
236 timespec begin_time{};
237
241 timespec end_time{};
242#endif
243
248
249 protected:
253 int argc_ = 0;
254
258 char** argv_ = nullptr;
259
263 const char* default_suite_name_ = "Test";
264 };
265
266 // --------------------------------------------------------------------------
267} // namespace micro_os_plus::micro_test_plus
268
269#if defined(__GNUC__)
270#pragma GCC diagnostic pop
271#endif
272
273// ----------------------------------------------------------------------------
274
275#endif // __cplusplus
276
277// ----------------------------------------------------------------------------
278
279#endif // MICRO_TEST_PLUS_TEST_RUNNER_H_
280
281// ----------------------------------------------------------------------------
char ** argv_
Stores the argument vector passed to the test runner.
void abort(void)
Aborts test execution immediately.
test_runner & operator=(const test_runner &)=delete
Deleted copy assignment operator to prevent copying.
test_runner(test_runner &&)=delete
Deleted move constructor to prevent moving.
size_t successful_checks
Total number of successful checks in the test suite.
test_runner()
Default constructor for the test_runner class.
constexpr const char * name(void)
Retrieves the name of the default test suite.
int argc_
Stores the argument count passed to the test runner.
~test_runner()=default
Destructor for the test_runner class.
std::vector< test_suite_base * > * test_suites
Pointer to the array of registered test suites.
size_t failed_checks
Total number of failed checks in the test suite.
test_runner(const test_runner &)=delete
Deleted copy constructor to prevent copying.
int exit_code(void)
Returns 0 if all tests were successful, 1 otherwise.
void initialize(int argc, char *argv[], const char *name)
Initialises the test runner with command-line arguments and an optional suite name.
void register_test_suite(test_suite_base *suite)
Registers a test suite with the runner.
struct micro_os_plus::micro_test_plus::test_runner::@203116162314165176152054201130262045267070023134 totals
test_suite_base * default_test_suite
Pointer to the default test suite which groups the main tests.
size_t test_cases_count
Total number of test cases in the test suite.
const char * default_suite_name_
The name of the default test suite.
Base class for all test suites.
Definition test-suite.h:100
Primary namespace for the µTest++ testing framework.