@micro-os-plus/micro-test-plus 3.1.1 → 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.
@@ -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,9 @@ namespace micro_os_plus::micro_test_plus
47
47
  {
48
48
  // --------------------------------------------------------------------------
49
49
 
50
+ /**
51
+ * @brief Colours used to highlight pass vs. fail.
52
+ */
50
53
  struct colors
51
54
  {
52
55
  const char* none = "\033[0m";
@@ -54,6 +57,9 @@ namespace micro_os_plus::micro_test_plus
54
57
  const char* fail = "\033[31m";
55
58
  };
56
59
 
60
+ /**
61
+ * @brief The verbosity levels.
62
+ */
57
63
  enum class verbosity
58
64
  {
59
65
  silent = 0, // Nothing, only return the exit code
@@ -176,9 +182,10 @@ namespace micro_os_plus::micro_test_plus
176
182
  /**
177
183
  * @brief Output operator to display containers. Iterate all members.
178
184
  */
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>
185
+ template <class T,
186
+ type_traits::requires_t<type_traits::is_container_v<T>
187
+ and not type_traits::has_npos_v<T>>
188
+ = 0>
182
189
  test_reporter&
183
190
  operator<< (T&& t);
184
191
 
@@ -44,7 +44,7 @@ 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
49
  */
50
50
  class test_runner
@@ -66,7 +66,7 @@ namespace micro_os_plus::micro_test_plus
66
66
 
67
67
  /**
68
68
  * @brief Pass the main arguments explicitly, if the default
69
- * contructor was used.
69
+ * constructor was used.
70
70
  */
71
71
  void
72
72
  initialize (int argc, char* argv[], const char* name);
@@ -44,14 +44,14 @@ 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.
49
48
  */
50
49
  class test_suite_base
51
50
  {
52
51
  public:
53
52
  /**
54
- * @brief Construct the default suite used in main().
53
+ * @brief Construct a test suite.
54
+ * @param [in] name The test suite name.
55
55
  */
56
56
  test_suite_base (const char* name);
57
57
 
@@ -69,24 +69,38 @@ namespace micro_os_plus::micro_test_plus
69
69
 
70
70
  /**
71
71
  * @brief Run the sequence of test cases in the suite.
72
+ * @par Parameters
73
+ * None.
74
+ * @par Returns
75
+ * Nothing.
72
76
  */
73
77
  virtual void
74
78
  run (void);
75
79
 
76
80
  /**
77
- * @brief Mark the begining of a named test case.
81
+ * @brief Mark the beginning of a named test case.
82
+ * @param [in] name The test case name.
83
+ * @par Returns
84
+ * Nothing.
78
85
  */
79
86
  void
80
87
  begin_test_case (const char* name);
81
88
 
82
89
  /**
83
90
  * @brief Mark the end of a test case.
91
+ * @par Parameters
92
+ * None.
93
+ * @par Returns
94
+ * Nothing.
84
95
  */
85
96
  void
86
97
  end_test_case (void);
87
98
 
88
99
  /**
89
100
  * @brief Get the suite name.
101
+ * @par Parameters
102
+ * None.
103
+ * @return A pointer to the null terminated test suite name.
90
104
  */
91
105
  [[nodiscard]] constexpr const char*
92
106
  name ()
@@ -95,19 +109,30 @@ namespace micro_os_plus::micro_test_plus
95
109
  }
96
110
 
97
111
  /**
98
- * @brief Count one more passed test condition.
112
+ * @brief Count one more passed test conditions.
113
+ * @par Parameters
114
+ * None.
115
+ * @par Returns
116
+ * Nothing.
99
117
  */
100
118
  void
101
119
  increment_successful (void);
102
120
 
103
121
  /**
104
- * @brief Count one more failed test condition.
122
+ * @brief Count one more failed test conditions.
123
+ * @par Parameters
124
+ * None.
125
+ * @par Returns
126
+ * Nothing.
105
127
  */
106
128
  void
107
129
  increment_failed (void);
108
130
 
109
131
  /**
110
132
  * @brief Get the number of conditions that passed.
133
+ * @par Parameters
134
+ * None.
135
+ * @return An integer with the number checks that passed.
111
136
  */
112
137
  [[nodiscard]] constexpr int
113
138
  successful_checks (void)
@@ -117,6 +142,9 @@ namespace micro_os_plus::micro_test_plus
117
142
 
118
143
  /**
119
144
  * @brief Get the number of conditions that failed.
145
+ * @par Parameters
146
+ * None.
147
+ * @return An integer with the number checks that failed.
120
148
  */
121
149
  [[nodiscard]] constexpr int
122
150
  failed_checks (void)
@@ -126,6 +154,9 @@ namespace micro_os_plus::micro_test_plus
126
154
 
127
155
  /**
128
156
  * @brief Get the number of test cases.
157
+ * @par Parameters
158
+ * None.
159
+ * @return An integer with the number of test cases.
129
160
  */
130
161
  [[nodiscard]] constexpr int
131
162
  test_cases (void)
@@ -135,18 +166,29 @@ namespace micro_os_plus::micro_test_plus
135
166
 
136
167
  /**
137
168
  * @brief Begin the execution of the test suite.
169
+ * @par Parameters
170
+ * None.
171
+ * @par Returns
172
+ * Nothing.
138
173
  */
139
174
  void
140
175
  begin_test_suite (void);
141
176
 
142
177
  /**
143
178
  * @brief Mark the end of the test suite.
179
+ * @par Parameters
180
+ * None.
181
+ * @par Returns
182
+ * Nothing.
144
183
  */
145
184
  void
146
185
  end_test_suite (void);
147
186
 
148
187
  /**
149
188
  * @brief Get the test suite result.
189
+ * @par Parameters
190
+ * None.
191
+ * @return True if the test suite was successful.
150
192
  */
151
193
  [[nodiscard]] constexpr bool
152
194
  was_successful (void)
@@ -155,6 +197,12 @@ namespace micro_os_plus::micro_test_plus
155
197
  return (failed_checks_ == 0 && successful_checks_ != 0);
156
198
  }
157
199
 
200
+ /**
201
+ * @brief If all counter are null, it is unused.
202
+ * @par Parameters
203
+ * None.
204
+ * @return True if the test suite is not used.
205
+ */
158
206
  [[nodiscard]] constexpr bool
159
207
  unused (void)
160
208
  {
@@ -197,9 +245,25 @@ namespace micro_os_plus::micro_test_plus
197
245
  } current_test_case{};
198
246
  };
199
247
 
248
+ /**
249
+ * @ingroup micro-test-plus-test-suites
250
+ * @brief Test suites are classes that represent a named group of
251
+ * test cases which self register to the runner.
252
+ */
200
253
  class test_suite : public test_suite_base
201
254
  {
202
255
  public:
256
+ /**
257
+ * @brief Construct a test suite.
258
+ * @tparam Callable_T The type of an object that can be called.
259
+ * @tparam Args_T The type of the callable arguments.
260
+ * @param [in] name The test case name or description.
261
+ * A short string used in the report.
262
+ * @param [in] callable A generic callable object,
263
+ * invoked to perform the test. Usually a lambda.
264
+ * @param [in] arguments A possibly empty list of arguments to be
265
+ * passed to the callable.
266
+ */
203
267
  template <typename Callable_T, typename... Args_T>
204
268
  test_suite (const char* name, Callable_T&& callable,
205
269
  Args_T&&... arguments);
@@ -56,10 +56,18 @@ namespace micro_os_plus::micro_test_plus
56
56
  using type = T;
57
57
  };
58
58
 
59
+ #if defined(__DOXYGEN__)
60
+ // error: Detected potential recursive class relation between class
61
+ // micro_os_plus::micro_test_plus::type_traits::function_traits and base
62
+ // class micro_os_plus::micro_test_plus::type_traits::function_traits<
63
+ // decltype(&T::operator())>!
64
+ // https://github.com/doxygen/doxygen/issues/9915
65
+ #else
59
66
  template <class T>
60
67
  struct function_traits : function_traits<decltype (&T::operator())>
61
68
  {
62
69
  };
70
+ #endif
63
71
 
64
72
  template <class R, class... Args_T>
65
73
  struct function_traits<R (*) (Args_T...)>
@@ -107,9 +115,8 @@ namespace micro_os_plus::micro_test_plus
107
115
  }
108
116
 
109
117
  template <class T>
110
- static constexpr auto is_container_v
111
- = is_valid<T> ([] (auto t) -> decltype (t.begin (), t.end (),
112
- void ()) {});
118
+ static constexpr auto is_container_v = is_valid<T> (
119
+ [] (auto t) -> decltype (t.begin (), t.end (), void ()) {});
113
120
 
114
121
  template <class T>
115
122
  static constexpr auto has_npos_v
@@ -134,7 +141,7 @@ namespace micro_os_plus::micro_test_plus
134
141
 
135
142
  #if defined(__clang__) or defined(_MSC_VER)
136
143
  template <class From, class To>
137
- static constexpr auto is_convertible_v = __is_convertible_to(From, To);
144
+ static constexpr auto is_convertible_v = __is_convertible_to (From, To);
138
145
  #else
139
146
  template <class From, class To>
140
147
  constexpr auto
@@ -189,7 +196,8 @@ namespace micro_os_plus::micro_test_plus
189
196
  return integral_constant<-N>{};
190
197
  }
191
198
 
192
- [[nodiscard]] constexpr explicit operator value_type () const
199
+ [[nodiscard]] constexpr explicit
200
+ operator value_type () const
193
201
  {
194
202
  return N;
195
203
  }
@@ -221,7 +229,8 @@ namespace micro_os_plus::micro_test_plus
221
229
  return floating_point_constant<T, N, D, Size, -1>{};
222
230
  }
223
231
 
224
- [[nodiscard]] constexpr explicit operator value_type () const
232
+ [[nodiscard]] constexpr explicit
233
+ operator value_type () const
225
234
  {
226
235
  return value;
227
236
  }
@@ -242,7 +251,8 @@ namespace micro_os_plus::micro_test_plus
242
251
  {
243
252
  }
244
253
 
245
- [[nodiscard]] constexpr explicit operator T () const
254
+ [[nodiscard]] constexpr explicit
255
+ operator T () const
246
256
  {
247
257
  return value_;
248
258
  }
@@ -257,7 +267,7 @@ namespace micro_os_plus::micro_test_plus
257
267
  };
258
268
 
259
269
  template <class T>
260
- inline constexpr auto is_op_v = __is_base_of(type_traits::op, T);
270
+ inline constexpr auto is_op_v = __is_base_of (type_traits::op, T);
261
271
 
262
272
  /**
263
273
  * @brief Class defining a generic value, accessible via a getter.
@@ -271,7 +281,8 @@ namespace micro_os_plus::micro_test_plus
271
281
  {
272
282
  }
273
283
 
274
- [[nodiscard]] constexpr explicit operator T () const
284
+ [[nodiscard]] constexpr explicit
285
+ operator T () const
275
286
  {
276
287
  return value_;
277
288
  }
@@ -312,7 +323,8 @@ namespace micro_os_plus::micro_test_plus
312
323
  {
313
324
  }
314
325
 
315
- [[nodiscard]] constexpr explicit operator T () const
326
+ [[nodiscard]] constexpr explicit
327
+ operator T () const
316
328
  {
317
329
  return value_;
318
330
  }
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')