@micro-os-plus/micro-test-plus 3.1.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +325 -1
- package/CMakeLists.txt +9 -11
- package/README.md +12 -1221
- package/include/micro-os-plus/detail.h +54 -36
- package/include/micro-os-plus/inlines.h +46 -7
- package/include/micro-os-plus/literals.h +154 -25
- package/include/micro-os-plus/micro-test-plus.h +253 -67
- package/include/micro-os-plus/reflection.h +9 -5
- package/include/micro-os-plus/test-reporter-inlines.h +2 -2
- package/include/micro-os-plus/test-reporter.h +11 -4
- package/include/micro-os-plus/test-runner.h +2 -2
- package/include/micro-os-plus/test-suite.h +70 -6
- package/include/micro-os-plus/type-traits.h +22 -10
- package/meson.build +23 -17
- package/package.json +25 -892
- package/src/micro-test-plus.cpp +43 -0
- package/src/test-reporter.cpp +11 -1
- package/src/test-runner.cpp +15 -4
package/src/micro-test-plus.cpp
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
34
34
|
#pragma clang diagnostic ignored "-Wexit-time-destructors"
|
|
35
35
|
#pragma clang diagnostic ignored "-Wglobal-constructors"
|
|
36
|
+
#pragma clang diagnostic ignored "-Wunknown-warning-option"
|
|
36
37
|
#endif
|
|
37
38
|
|
|
38
39
|
namespace micro_os_plus::micro_test_plus
|
|
@@ -40,6 +41,18 @@ namespace micro_os_plus::micro_test_plus
|
|
|
40
41
|
// --------------------------------------------------------------------------
|
|
41
42
|
// Public API.
|
|
42
43
|
|
|
44
|
+
/**
|
|
45
|
+
* @details
|
|
46
|
+
* All tests include a default test suite, which runs the test cases
|
|
47
|
+
* defined in the main function.
|
|
48
|
+
*
|
|
49
|
+
* This function forwards the process arguments to the test framework
|
|
50
|
+
* and initialises the runner.
|
|
51
|
+
*
|
|
52
|
+
* The name is used to identify the default test suite.
|
|
53
|
+
*
|
|
54
|
+
* The arguments can be used to control the verbosity level.
|
|
55
|
+
*/
|
|
43
56
|
void
|
|
44
57
|
initialize (int argc, char* argv[], const char* name)
|
|
45
58
|
{
|
|
@@ -49,6 +62,18 @@ namespace micro_os_plus::micro_test_plus
|
|
|
49
62
|
runner.initialize (argc, argv, name);
|
|
50
63
|
}
|
|
51
64
|
|
|
65
|
+
/**
|
|
66
|
+
* @details
|
|
67
|
+
* In addition to the test cases defined in `main()`, there can be
|
|
68
|
+
* more separate **test suites**, defined as static objects in the same
|
|
69
|
+
* file or in other files,
|
|
70
|
+
* and self-registered via the static constructors mechanism.
|
|
71
|
+
*
|
|
72
|
+
* This function triggers the execution of the globally
|
|
73
|
+
* registered test suites
|
|
74
|
+
* (if any) and returns the test result as the process exit code
|
|
75
|
+
* (0 = success).
|
|
76
|
+
*/
|
|
52
77
|
int
|
|
53
78
|
exit_code (void)
|
|
54
79
|
{
|
|
@@ -63,7 +88,12 @@ namespace micro_os_plus::micro_test_plus
|
|
|
63
88
|
const char*
|
|
64
89
|
short_name (const char* name)
|
|
65
90
|
{
|
|
91
|
+
#pragma GCC diagnostic push
|
|
92
|
+
#if defined(__clang__)
|
|
93
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
|
|
94
|
+
#endif
|
|
66
95
|
const char* p = strrchr (name, '/');
|
|
96
|
+
#pragma GCC diagnostic pop
|
|
67
97
|
if (p != nullptr)
|
|
68
98
|
return p + 1;
|
|
69
99
|
else
|
|
@@ -74,6 +104,19 @@ namespace micro_os_plus::micro_test_plus
|
|
|
74
104
|
|
|
75
105
|
namespace utility
|
|
76
106
|
{
|
|
107
|
+
/**
|
|
108
|
+
* @details
|
|
109
|
+
* For tests comparing strings, in addition to exact matches,
|
|
110
|
+
* it is also possible to check matches with patterns like `*`
|
|
111
|
+
* (for any characters) and `?` (for a single character)
|
|
112
|
+
*
|
|
113
|
+
* @par Examples
|
|
114
|
+
*
|
|
115
|
+
* ```cpp
|
|
116
|
+
* expect (utility::is_match ("abc", "a?c")) << "abc matches a?c";
|
|
117
|
+
* expect (utility::is_match ("abc", "a*c")) << "abc matches a*c";
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
77
120
|
[[nodiscard]] bool
|
|
78
121
|
is_match (std::string_view input, std::string_view pattern)
|
|
79
122
|
{
|
package/src/test-reporter.cpp
CHANGED
|
@@ -84,8 +84,18 @@ namespace micro_os_plus::micro_test_plus
|
|
|
84
84
|
*this << " ";
|
|
85
85
|
}
|
|
86
86
|
*this << colors_.fail << "FAILED" << colors_.none;
|
|
87
|
+
#pragma GCC diagnostic push
|
|
88
|
+
#if defined(__clang__)
|
|
89
|
+
#pragma clang diagnostic ignored "-Wsign-conversion"
|
|
90
|
+
#elif defined(__GNUC__)
|
|
91
|
+
#pragma GCC diagnostic ignored "-Wnarrowing"
|
|
92
|
+
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
|
93
|
+
#endif
|
|
87
94
|
*this << " (" << reflection::short_name (location.file_name ()) << ":"
|
|
88
|
-
<< type_traits::genuine_integral_value<int>{
|
|
95
|
+
<< type_traits::genuine_integral_value<unsigned int>{
|
|
96
|
+
location.line ()
|
|
97
|
+
};
|
|
98
|
+
#pragma GCC diagnostic pop
|
|
89
99
|
}
|
|
90
100
|
|
|
91
101
|
void
|
package/src/test-runner.cpp
CHANGED
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
#if defined(__clang__)
|
|
32
32
|
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
33
33
|
#pragma clang diagnostic ignored "-Wc++98-c++11-c++14-compat"
|
|
34
|
+
#pragma clang diagnostic ignored "-Wunknown-warning-option"
|
|
34
35
|
#endif
|
|
35
36
|
|
|
36
37
|
namespace micro_os_plus::micro_test_plus
|
|
@@ -44,6 +45,10 @@ namespace micro_os_plus::micro_test_plus
|
|
|
44
45
|
#endif // MICRO_TEST_PLUS_TRACE
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
#pragma GCC diagnostic push
|
|
49
|
+
#if defined(__clang__)
|
|
50
|
+
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
|
|
51
|
+
#endif
|
|
47
52
|
void
|
|
48
53
|
test_runner::initialize (int argc, char* argv[], const char* name)
|
|
49
54
|
{
|
|
@@ -56,6 +61,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
56
61
|
|
|
57
62
|
default_suite_name_ = name;
|
|
58
63
|
|
|
64
|
+
#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
|
|
59
65
|
#if defined(MICRO_OS_PLUS_DEBUG)
|
|
60
66
|
printf ("argv[");
|
|
61
67
|
for (int i = 0; i < argc; ++i)
|
|
@@ -67,7 +73,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
67
73
|
printf ("'%s'", argv[i]);
|
|
68
74
|
}
|
|
69
75
|
puts ("]");
|
|
70
|
-
#endif
|
|
76
|
+
#endif // defined(MICRO_OS_PLUS_DEBUG)
|
|
77
|
+
#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
|
|
71
78
|
|
|
72
79
|
verbosity_t verbosity = verbosity::normal;
|
|
73
80
|
for (int i = 0; i < argc; ++i)
|
|
@@ -91,6 +98,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
91
98
|
|
|
92
99
|
// ------------------------------------------------------------------------
|
|
93
100
|
|
|
101
|
+
#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
|
|
94
102
|
if (verbosity == verbosity::normal || verbosity == verbosity::verbose)
|
|
95
103
|
{
|
|
96
104
|
#if defined(__clang__)
|
|
@@ -103,7 +111,8 @@ namespace micro_os_plus::micro_test_plus
|
|
|
103
111
|
#else
|
|
104
112
|
printf ("Built with an unknown compiler");
|
|
105
113
|
#endif
|
|
106
|
-
#if !(defined(__APPLE__) || defined(__linux__) || defined(__unix__)
|
|
114
|
+
#if !(defined(__APPLE__) || defined(__linux__) || defined(__unix__) \
|
|
115
|
+
|| defined(WIN32))
|
|
107
116
|
// This is relevant only on bare-metal.
|
|
108
117
|
#if defined(__ARM_PCS_VFP) || defined(__ARM_FP)
|
|
109
118
|
printf (", with FP");
|
|
@@ -121,6 +130,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
121
130
|
#endif
|
|
122
131
|
puts (".");
|
|
123
132
|
}
|
|
133
|
+
#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
|
|
124
134
|
|
|
125
135
|
// ------------------------------------------------------------------------
|
|
126
136
|
|
|
@@ -131,6 +141,7 @@ namespace micro_os_plus::micro_test_plus
|
|
|
131
141
|
// initialisations to display their messages.
|
|
132
142
|
// default_test_suite_->begin_test_suite ();
|
|
133
143
|
}
|
|
144
|
+
#pragma GCC diagnostic pop
|
|
134
145
|
|
|
135
146
|
int
|
|
136
147
|
test_runner::exit_code (void)
|
|
@@ -151,13 +162,13 @@ namespace micro_os_plus::micro_test_plus
|
|
|
151
162
|
|
|
152
163
|
suite->begin_test_suite ();
|
|
153
164
|
suite->run ();
|
|
154
|
-
suite->end_test_suite();
|
|
165
|
+
suite->end_test_suite ();
|
|
155
166
|
|
|
156
167
|
was_successful &= suite->was_successful ();
|
|
157
168
|
}
|
|
158
169
|
if (reporter.verbosity != verbosity::silent)
|
|
159
170
|
{
|
|
160
|
-
printf ("\n");
|
|
171
|
+
// printf ("\n");
|
|
161
172
|
}
|
|
162
173
|
}
|
|
163
174
|
return was_successful ? 0 : 1;
|