@micro-os-plus/micro-test-plus 3.1.1 → 3.2.0

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.
@@ -23,7 +23,7 @@
23
23
 
24
24
  // ----------------------------------------------------------------------------
25
25
 
26
- //#include <functional>
26
+ // #include <functional>
27
27
  #include <string_view>
28
28
  #include <string>
29
29
 
@@ -47,6 +47,10 @@ namespace micro_os_plus::micro_test_plus
47
47
  {
48
48
  // --------------------------------------------------------------------------
49
49
 
50
+ /**
51
+ * @brief Colours used to highlight pass vs. fail.
52
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
53
+ */
50
54
  struct colors
51
55
  {
52
56
  const char* none = "\033[0m";
@@ -54,6 +58,10 @@ namespace micro_os_plus::micro_test_plus
54
58
  const char* fail = "\033[31m";
55
59
  };
56
60
 
61
+ /**
62
+ * @brief The verbosity levels.
63
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
64
+ */
57
65
  enum class verbosity
58
66
  {
59
67
  silent = 0, // Nothing, only return the exit code
@@ -74,6 +82,7 @@ namespace micro_os_plus::micro_test_plus
74
82
  /**
75
83
  * @brief Reporter to display the test results. For failed
76
84
  * tests it prints the actual values of the operands, with their types.
85
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
77
86
  */
78
87
  class test_reporter
79
88
  {
@@ -176,9 +185,10 @@ namespace micro_os_plus::micro_test_plus
176
185
  /**
177
186
  * @brief Output operator to display containers. Iterate all members.
178
187
  */
179
- template <class T, type_traits::requires_t<
180
- type_traits::is_container_v<
181
- T> and not type_traits::has_npos_v<T>> = 0>
188
+ template <class T,
189
+ type_traits::requires_t<type_traits::is_container_v<T>
190
+ and not type_traits::has_npos_v<T>>
191
+ = 0>
182
192
  test_reporter&
183
193
  operator<< (T&& t);
184
194
 
@@ -44,8 +44,9 @@ namespace micro_os_plus::micro_test_plus
44
44
  // --------------------------------------------------------------------------
45
45
 
46
46
  /**
47
- * @brief The test runner. It maintaines a list of test suites which
47
+ * @brief The test runner. It maintains a list of test suites which
48
48
  * automatically register themselves in their constructors.
49
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
49
50
  */
50
51
  class test_runner
51
52
  {
@@ -66,7 +67,7 @@ namespace micro_os_plus::micro_test_plus
66
67
 
67
68
  /**
68
69
  * @brief Pass the main arguments explicitly, if the default
69
- * contructor was used.
70
+ * constructor was used.
70
71
  */
71
72
  void
72
73
  initialize (int argc, char* argv[], const char* name);
@@ -44,14 +44,15 @@ namespace micro_os_plus::micro_test_plus
44
44
  // --------------------------------------------------------------------------
45
45
 
46
46
  /**
47
- * @brief Test suites are classes that represent a named group of
48
- * test cases which self registers to the runner.
47
+ * @brief Base class for all test suites.
48
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
49
49
  */
50
50
  class test_suite_base
51
51
  {
52
52
  public:
53
53
  /**
54
- * @brief Construct the default suite used in main().
54
+ * @brief Construct a test suite.
55
+ * @param [in] name The test suite name.
55
56
  */
56
57
  test_suite_base (const char* name);
57
58
 
@@ -69,24 +70,38 @@ namespace micro_os_plus::micro_test_plus
69
70
 
70
71
  /**
71
72
  * @brief Run the sequence of test cases in the suite.
73
+ * @par Parameters
74
+ * None.
75
+ * @par Returns
76
+ * Nothing.
72
77
  */
73
78
  virtual void
74
79
  run (void);
75
80
 
76
81
  /**
77
- * @brief Mark the begining of a named test case.
82
+ * @brief Mark the beginning of a named test case.
83
+ * @param [in] name The test case name.
84
+ * @par Returns
85
+ * Nothing.
78
86
  */
79
87
  void
80
88
  begin_test_case (const char* name);
81
89
 
82
90
  /**
83
91
  * @brief Mark the end of a test case.
92
+ * @par Parameters
93
+ * None.
94
+ * @par Returns
95
+ * Nothing.
84
96
  */
85
97
  void
86
98
  end_test_case (void);
87
99
 
88
100
  /**
89
101
  * @brief Get the suite name.
102
+ * @par Parameters
103
+ * None.
104
+ * @return A pointer to the null terminated test suite name.
90
105
  */
91
106
  [[nodiscard]] constexpr const char*
92
107
  name ()
@@ -95,19 +110,30 @@ namespace micro_os_plus::micro_test_plus
95
110
  }
96
111
 
97
112
  /**
98
- * @brief Count one more passed test condition.
113
+ * @brief Count one more passed test conditions.
114
+ * @par Parameters
115
+ * None.
116
+ * @par Returns
117
+ * Nothing.
99
118
  */
100
119
  void
101
120
  increment_successful (void);
102
121
 
103
122
  /**
104
- * @brief Count one more failed test condition.
123
+ * @brief Count one more failed test conditions.
124
+ * @par Parameters
125
+ * None.
126
+ * @par Returns
127
+ * Nothing.
105
128
  */
106
129
  void
107
130
  increment_failed (void);
108
131
 
109
132
  /**
110
133
  * @brief Get the number of conditions that passed.
134
+ * @par Parameters
135
+ * None.
136
+ * @return An integer with the number checks that passed.
111
137
  */
112
138
  [[nodiscard]] constexpr int
113
139
  successful_checks (void)
@@ -117,6 +143,9 @@ namespace micro_os_plus::micro_test_plus
117
143
 
118
144
  /**
119
145
  * @brief Get the number of conditions that failed.
146
+ * @par Parameters
147
+ * None.
148
+ * @return An integer with the number checks that failed.
120
149
  */
121
150
  [[nodiscard]] constexpr int
122
151
  failed_checks (void)
@@ -126,6 +155,9 @@ namespace micro_os_plus::micro_test_plus
126
155
 
127
156
  /**
128
157
  * @brief Get the number of test cases.
158
+ * @par Parameters
159
+ * None.
160
+ * @return An integer with the number of test cases.
129
161
  */
130
162
  [[nodiscard]] constexpr int
131
163
  test_cases (void)
@@ -135,18 +167,29 @@ namespace micro_os_plus::micro_test_plus
135
167
 
136
168
  /**
137
169
  * @brief Begin the execution of the test suite.
170
+ * @par Parameters
171
+ * None.
172
+ * @par Returns
173
+ * Nothing.
138
174
  */
139
175
  void
140
176
  begin_test_suite (void);
141
177
 
142
178
  /**
143
179
  * @brief Mark the end of the test suite.
180
+ * @par Parameters
181
+ * None.
182
+ * @par Returns
183
+ * Nothing.
144
184
  */
145
185
  void
146
186
  end_test_suite (void);
147
187
 
148
188
  /**
149
189
  * @brief Get the test suite result.
190
+ * @par Parameters
191
+ * None.
192
+ * @return True if the test suite was successful.
150
193
  */
151
194
  [[nodiscard]] constexpr bool
152
195
  was_successful (void)
@@ -155,6 +198,12 @@ namespace micro_os_plus::micro_test_plus
155
198
  return (failed_checks_ == 0 && successful_checks_ != 0);
156
199
  }
157
200
 
201
+ /**
202
+ * @brief If all counter are null, it is unused.
203
+ * @par Parameters
204
+ * None.
205
+ * @return True if the test suite is not used.
206
+ */
158
207
  [[nodiscard]] constexpr bool
159
208
  unused (void)
160
209
  {
@@ -197,9 +246,26 @@ namespace micro_os_plus::micro_test_plus
197
246
  } current_test_case{};
198
247
  };
199
248
 
249
+ /**
250
+ * @ingroup micro-test-plus-test-suites
251
+ * @brief Test suites are classes that represent a named group of
252
+ * test cases which self register to the runner.
253
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
254
+ */
200
255
  class test_suite : public test_suite_base
201
256
  {
202
257
  public:
258
+ /**
259
+ * @brief Construct a test suite.
260
+ * @tparam Callable_T The type of an object that can be called.
261
+ * @tparam Args_T The type of the callable arguments.
262
+ * @param [in] name The test case name or description.
263
+ * A short string used in the report.
264
+ * @param [in] callable A generic callable object,
265
+ * invoked to perform the test. Usually a lambda.
266
+ * @param [in] arguments A possibly empty list of arguments to be
267
+ * passed to the callable.
268
+ */
203
269
  template <typename Callable_T, typename... Args_T>
204
270
  test_suite (const char* name, Callable_T&& callable,
205
271
  Args_T&&... arguments);
@@ -45,22 +45,39 @@ namespace micro_os_plus::micro_test_plus
45
45
  */
46
46
  namespace type_traits
47
47
  {
48
+ /**
49
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
50
+ */
48
51
  template <class...>
49
52
  struct list
50
53
  {
51
54
  };
52
55
 
56
+ /**
57
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
58
+ */
53
59
  template <class T, class...>
54
60
  struct identity
55
61
  {
56
62
  using type = T;
57
63
  };
58
64
 
65
+ #if defined(__DOXYGEN__)
66
+ // error: Detected potential recursive class relation between class
67
+ // micro_os_plus::micro_test_plus::type_traits::function_traits and base
68
+ // class micro_os_plus::micro_test_plus::type_traits::function_traits<
69
+ // decltype(&T::operator())>!
70
+ // https://github.com/doxygen/doxygen/issues/9915
71
+ #else
59
72
  template <class T>
60
73
  struct function_traits : function_traits<decltype (&T::operator())>
61
74
  {
62
75
  };
76
+ #endif
63
77
 
78
+ /**
79
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
80
+ */
64
81
  template <class R, class... Args_T>
65
82
  struct function_traits<R (*) (Args_T...)>
66
83
  {
@@ -68,6 +85,9 @@ namespace micro_os_plus::micro_test_plus
68
85
  using args = list<Args_T...>;
69
86
  };
70
87
 
88
+ /**
89
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
90
+ */
71
91
  template <class R, class... Args_T>
72
92
  struct function_traits<R (Args_T...)>
73
93
  {
@@ -75,6 +95,9 @@ namespace micro_os_plus::micro_test_plus
75
95
  using args = list<Args_T...>;
76
96
  };
77
97
 
98
+ /**
99
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
100
+ */
78
101
  template <class R, class T, class... Args_T>
79
102
  struct function_traits<R (T::*) (Args_T...)>
80
103
  {
@@ -82,6 +105,9 @@ namespace micro_os_plus::micro_test_plus
82
105
  using args = list<Args_T...>;
83
106
  };
84
107
 
108
+ /**
109
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
110
+ */
85
111
  template <class R, class T, class... Args_T>
86
112
  struct function_traits<R (T::*) (Args_T...) const>
87
113
  {
@@ -107,9 +133,8 @@ namespace micro_os_plus::micro_test_plus
107
133
  }
108
134
 
109
135
  template <class T>
110
- static constexpr auto is_container_v
111
- = is_valid<T> ([] (auto t) -> decltype (t.begin (), t.end (),
112
- void ()) {});
136
+ static constexpr auto is_container_v = is_valid<T> (
137
+ [] (auto t) -> decltype (t.begin (), t.end (), void ()) {});
113
138
 
114
139
  template <class T>
115
140
  static constexpr auto has_npos_v
@@ -134,7 +159,7 @@ namespace micro_os_plus::micro_test_plus
134
159
 
135
160
  #if defined(__clang__) or defined(_MSC_VER)
136
161
  template <class From, class To>
137
- static constexpr auto is_convertible_v = __is_convertible_to(From, To);
162
+ static constexpr auto is_convertible_v = __is_convertible_to (From, To);
138
163
  #else
139
164
  template <class From, class To>
140
165
  constexpr auto
@@ -152,11 +177,17 @@ namespace micro_os_plus::micro_test_plus
152
177
  constexpr auto is_convertible_v = is_convertible<From, To> (0);
153
178
  #endif
154
179
 
180
+ /**
181
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
182
+ */
155
183
  template <bool>
156
184
  struct requires_
157
185
  {
158
186
  };
159
187
 
188
+ /**
189
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
190
+ */
160
191
  template <>
161
192
  struct requires_<true>
162
193
  {
@@ -168,6 +199,7 @@ namespace micro_os_plus::micro_test_plus
168
199
 
169
200
  /**
170
201
  * @brief Empty base class of all operators.
202
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
171
203
  */
172
204
  struct op
173
205
  {
@@ -176,6 +208,7 @@ namespace micro_os_plus::micro_test_plus
176
208
  /**
177
209
  * @brief A generic integral constant.
178
210
  * It has a getter and a '-' operator to return the negative value.
211
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
179
212
  */
180
213
  template <auto N>
181
214
  struct integral_constant : op
@@ -189,7 +222,8 @@ namespace micro_os_plus::micro_test_plus
189
222
  return integral_constant<-N>{};
190
223
  }
191
224
 
192
- [[nodiscard]] constexpr explicit operator value_type () const
225
+ [[nodiscard]] constexpr explicit
226
+ operator value_type () const
193
227
  {
194
228
  return N;
195
229
  }
@@ -205,6 +239,7 @@ namespace micro_os_plus::micro_test_plus
205
239
  * @brief A generic floating point constant, with custom size
206
240
  * and precision.
207
241
  * It has a getter and a '-' operator to return the negative value.
242
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
208
243
  */
209
244
  template <class T, auto N, auto D, auto Size, auto P = 1>
210
245
  struct floating_point_constant : op
@@ -221,7 +256,8 @@ namespace micro_os_plus::micro_test_plus
221
256
  return floating_point_constant<T, N, D, Size, -1>{};
222
257
  }
223
258
 
224
- [[nodiscard]] constexpr explicit operator value_type () const
259
+ [[nodiscard]] constexpr explicit
260
+ operator value_type () const
225
261
  {
226
262
  return value;
227
263
  }
@@ -233,6 +269,9 @@ namespace micro_os_plus::micro_test_plus
233
269
  }
234
270
  };
235
271
 
272
+ /**
273
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
274
+ */
236
275
  template <class T>
237
276
  struct genuine_integral_value : op
238
277
  {
@@ -242,7 +281,8 @@ namespace micro_os_plus::micro_test_plus
242
281
  {
243
282
  }
244
283
 
245
- [[nodiscard]] constexpr explicit operator T () const
284
+ [[nodiscard]] constexpr explicit
285
+ operator T () const
246
286
  {
247
287
  return value_;
248
288
  }
@@ -257,10 +297,11 @@ namespace micro_os_plus::micro_test_plus
257
297
  };
258
298
 
259
299
  template <class T>
260
- inline constexpr auto is_op_v = __is_base_of(type_traits::op, T);
300
+ inline constexpr auto is_op_v = __is_base_of (type_traits::op, T);
261
301
 
262
302
  /**
263
303
  * @brief Class defining a generic value, accessible via a getter.
304
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
264
305
  */
265
306
  template <class T, class = int>
266
307
  struct value : type_traits::op
@@ -271,7 +312,8 @@ namespace micro_os_plus::micro_test_plus
271
312
  {
272
313
  }
273
314
 
274
- [[nodiscard]] constexpr explicit operator T () const
315
+ [[nodiscard]] constexpr explicit
316
+ operator T () const
275
317
  {
276
318
  return value_;
277
319
  }
@@ -290,6 +332,7 @@ namespace micro_os_plus::micro_test_plus
290
332
  * in addition to the actual value, has an epsilon, to use the
291
333
  * desired precision during comparisons.
292
334
  * If missing, the default is 1 / (10^decimals).
335
+ * @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
293
336
  */
294
337
  template <class T>
295
338
  struct value<T,
@@ -312,7 +355,8 @@ namespace micro_os_plus::micro_test_plus
312
355
  {
313
356
  }
314
357
 
315
- [[nodiscard]] constexpr explicit operator T () const
358
+ [[nodiscard]] constexpr explicit
359
+ operator T () const
316
360
  {
317
361
  return value_;
318
362
  }
package/meson.build CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  # This file is intended to be consumed by applications with:
16
16
  #
17
- # `subdir('xpacks/micro-os-plus-micro-test-plus')`
17
+ # `subdir('xpacks/@micro-os-plus/micro-test-plus')`
18
18
  #
19
19
  # The result is a library and a dependency that can be referred as:
20
20
  #
@@ -29,18 +29,21 @@ message('Processing xPack @micro-os-plus/micro-test-plus...')
29
29
 
30
30
  # -----------------------------------------------------------------------------
31
31
 
32
- xpack_common_args = []
33
- xpack_c_args = []
34
- xpack_cpp_args = []
35
- xpack_include_directories = []
36
- xpack_sources = []
37
- xpack_compile_definitions = []
32
+ _local_compile_args = [] # Common C/C++ args.
33
+ _local_compile_c_args = []
34
+ _local_compile_cpp_args = []
35
+ _local_include_directories = []
36
+ _local_sources = []
37
+ _local_compile_definitions = []
38
+ _local_dependencies = []
39
+ _local_link_args = []
40
+ _local_link_with = []
38
41
 
39
- xpack_include_directories += [
42
+ _local_include_directories += [
40
43
  'include',
41
44
  ]
42
45
 
43
- xpack_sources += [
46
+ _local_sources += [
44
47
  'src/micro-test-plus.cpp',
45
48
  'src/test-runner.cpp',
46
49
  'src/test-reporter.cpp',
@@ -49,18 +52,21 @@ xpack_sources += [
49
52
 
50
53
  # https://mesonbuild.com/Reference-manual_functions.html#declare_dependency
51
54
  micro_os_plus_micro_test_plus_dependency = declare_dependency(
52
- include_directories: include_directories(xpack_include_directories),
53
- compile_args: xpack_common_args,
54
- sources: files(xpack_sources),
55
+ include_directories: include_directories(_local_include_directories),
56
+ compile_args: _local_compile_args,
57
+ sources: files(_local_sources),
58
+ dependencies: _local_dependencies,
59
+ link_args: _local_link_args,
60
+ link_with: _local_link_with,
55
61
  )
62
+ # meson dependencies cannot differentiate c/cpp args; pass them separately.
63
+ micro_os_plus_micro_test_plus_dependency_compile_c_args = _local_compile_c_args
64
+ micro_os_plus_micro_test_plus_dependency_compile_cpp_args = _local_compile_cpp_args
56
65
 
57
- # micro_os_plus_micro_test_plus_dependency_c_args = xpack_c_args
58
- # micro_os_plus_micro_test_plus_dependency_cpp_args = xpack_cpp_args
59
-
60
- foreach name : xpack_include_directories
66
+ foreach name : _local_include_directories
61
67
  message('+ -I ' + name)
62
68
  endforeach
63
- foreach name : xpack_sources + xpack_common_args
69
+ foreach name : _local_sources + _local_compile_definitions + _local_compile_args + _local_compile_c_args + _local_compile_cpp_args
64
70
  message('+ ' + name)
65
71
  endforeach
66
72
  message('> micro_os_plus_micro_test_plus_dependency')