@micro-os-plus/micro-test-plus 3.0.1 → 3.1.1
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 +49 -4
- package/README.md +117 -97
- package/meson.build +1 -1
- package/package.json +71 -428
- package/src/test-runner.cpp +11 -4
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,51 @@ Please check
|
|
|
6
6
|
[GitHub](https://github.com/micro-os-plus/micro-test-plus-xpack/issues/)
|
|
7
7
|
and close existing issues and pull requests.
|
|
8
8
|
|
|
9
|
+
## 2022-07-30
|
|
10
|
+
|
|
11
|
+
* v3.1.1
|
|
12
|
+
* 41d0acf update mps2 config
|
|
13
|
+
* 7c4cf61 #7: package.json: use inheritance
|
|
14
|
+
* 736a885 bump deps
|
|
15
|
+
* 6221d1f #6: remove STM32F4DISCOVERY test
|
|
16
|
+
* b080101 test-runner.cpp: conditional verbosity
|
|
17
|
+
|
|
18
|
+
## 2022-07-28
|
|
19
|
+
|
|
20
|
+
* ec67074 CI.yml do not trigger on tags
|
|
21
|
+
|
|
22
|
+
## 2022-07-25
|
|
23
|
+
|
|
24
|
+
* af5ae81 package.json minimumXpmRequired
|
|
25
|
+
|
|
26
|
+
## 2022-07-12
|
|
27
|
+
|
|
28
|
+
* 2b15c56 CMake: xpack_display_greetings() with arg
|
|
29
|
+
* 4459cc9 package.json: bump deps
|
|
30
|
+
|
|
31
|
+
## 2022-06-04
|
|
32
|
+
|
|
33
|
+
* v3.1.0
|
|
34
|
+
* b8994fb revert sections.ld
|
|
35
|
+
|
|
36
|
+
## 2022-06-03
|
|
37
|
+
|
|
38
|
+
* 1e30b5f tests: update for sections-flash.ld
|
|
39
|
+
* 0e434ea test-runner.cpp: show FP only for non-native
|
|
40
|
+
|
|
41
|
+
## 2022-04-19
|
|
42
|
+
|
|
43
|
+
* 3.0.2
|
|
44
|
+
* cd697a4 README reworks
|
|
45
|
+
|
|
46
|
+
## 2022-04-10
|
|
47
|
+
|
|
48
|
+
* d53ee24 package.json: bump build-helper 2.7.1
|
|
49
|
+
|
|
50
|
+
## 2022-04-07
|
|
51
|
+
|
|
52
|
+
* b43ce71 test-all.yml: remove Raspberry Pi OS test
|
|
53
|
+
|
|
9
54
|
## 2022-04-05
|
|
10
55
|
|
|
11
56
|
* 3.0.1
|
|
@@ -51,7 +96,7 @@ and close existing issues and pull requests.
|
|
|
51
96
|
## 2022-03-23
|
|
52
97
|
|
|
53
98
|
* 255d4e5 README updates
|
|
54
|
-
* c837032 package.json: bump
|
|
99
|
+
* c837032 package.json: bump build-helper 2.6.2
|
|
55
100
|
* 49a3129 package.json: bump gcc 11.2.0-3.3
|
|
56
101
|
* 568d799 revert to interface library
|
|
57
102
|
|
|
@@ -137,7 +182,7 @@ and close existing issues and pull requests.
|
|
|
137
182
|
* 2f5efdd move casts to literals.h
|
|
138
183
|
* b1a0b55 move struct value to type_traits
|
|
139
184
|
* a9ec726 split literals.h
|
|
140
|
-
* bd64244 more
|
|
185
|
+
* bd64244 more type_traits moves
|
|
141
186
|
* 5a98f64 remove unused struct type_
|
|
142
187
|
* 8176edc move op & _constants to type_traits.h
|
|
143
188
|
* 658bf72 silence warnings
|
|
@@ -235,7 +280,7 @@ and close existing issues and pull requests.
|
|
|
235
280
|
* f921bf0 sample-test: cleanup globals
|
|
236
281
|
* 66df97e add support for test-all
|
|
237
282
|
* f6c19d2 cmake globals add -fdiagnostics-color=always
|
|
238
|
-
* 28efe4b add
|
|
283
|
+
* 28efe4b add parametrised tests and combinatorics
|
|
239
284
|
* 560b678 add run_test_case variadic template
|
|
240
285
|
* 436a1ae deprecate run_test_case(func, name)
|
|
241
286
|
* 0a6a46b add start_test_case()
|
|
@@ -315,7 +360,7 @@ and close existing issues and pull requests.
|
|
|
315
360
|
* 6f55a37 package.json: rename dependencies to device-*
|
|
316
361
|
* fde47e6 package.json: move toolchain files to folder
|
|
317
362
|
* 041c252 cmake: rename platform-qemu-mps2-an386
|
|
318
|
-
* 1230c9b cmake: update for
|
|
363
|
+
* 1230c9b cmake: update for devices-qemu-cortexm
|
|
319
364
|
* 10304ab rename platform-qemu-mps2-an386
|
|
320
365
|
|
|
321
366
|
## 2022-01-28
|
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
[](https://github.com/micro-os-plus/micro-test-plus-xpack/blob/xpack/LICENSE)
|
|
2
|
+
[](https://github.com/micro-os-plus/micro-test-plus-xpack/actions/workflows/CI.yml)
|
|
3
3
|
|
|
4
|
-
# A source library xPack with µTest++, a testing framework for embedded platforms
|
|
4
|
+
# A source library xPack with µTest++, a lightweight testing framework for embedded platforms
|
|
5
5
|
|
|
6
|
-
The **µTest++** project (_micro test plus_) provides a
|
|
6
|
+
The **µTest++** project (_micro test plus_) provides a small memory footprint
|
|
7
7
|
testing framework, intended for running unit tests on embedded
|
|
8
8
|
platforms.
|
|
9
9
|
|
|
@@ -20,7 +20,7 @@ For maintainer info, please see the
|
|
|
20
20
|
|
|
21
21
|
## Install
|
|
22
22
|
|
|
23
|
-
As a source library
|
|
23
|
+
As a source library xPack, the easiest way to add it to a project is via
|
|
24
24
|
**xpm**, but it can also be used as any Git project, for example as a submodule.
|
|
25
25
|
|
|
26
26
|
### Prerequisites
|
|
@@ -33,7 +33,7 @@ For details please follow the instructions in the
|
|
|
33
33
|
|
|
34
34
|
### xpm
|
|
35
35
|
|
|
36
|
-
This package is available as
|
|
36
|
+
This package is available from npmjs.com as
|
|
37
37
|
[`@micro-os-plus/micro-test-plus`](https://www.npmjs.com/package/@micro-os-plus/micro-test-plus)
|
|
38
38
|
from the `npmjs.com` registry:
|
|
39
39
|
|
|
@@ -49,14 +49,16 @@ ls -l xpacks/micro-os-plus-micro-test-plus
|
|
|
49
49
|
### Git submodule
|
|
50
50
|
|
|
51
51
|
If, for any reason, **xpm** is not available, the next recommended
|
|
52
|
-
solution is to link it as a Git submodule below an `xpacks`
|
|
52
|
+
solution is to link it as a Git submodule, preferably below an `xpacks`
|
|
53
|
+
folder.
|
|
53
54
|
|
|
54
55
|
```sh
|
|
55
56
|
cd my-project
|
|
56
57
|
git init # Unless already a Git project
|
|
57
58
|
mkdir -p xpacks
|
|
58
59
|
|
|
59
|
-
git submodule add
|
|
60
|
+
git submodule add \
|
|
61
|
+
https://github.com/micro-os-plus/micro-test-plus-xpack.git \
|
|
60
62
|
xpacks/micro-os-plus-micro-test-plus
|
|
61
63
|
```
|
|
62
64
|
|
|
@@ -75,14 +77,14 @@ into `xpack`.
|
|
|
75
77
|
|
|
76
78
|
## Developer info
|
|
77
79
|
|
|
78
|
-
The xPack Build
|
|
79
|
-
testing frameworks:
|
|
80
|
+
The xPack Build Framework already includes ready to use
|
|
81
|
+
support for several testing frameworks:
|
|
80
82
|
|
|
81
83
|
- [Google Test](https://github.com/xpack-3rd-party/googletest-xpack)
|
|
82
84
|
- [Catch2](https://github.com/xpack-3rd-party/catch2-xpack)
|
|
83
|
-
- [Boost UT](https://github.com/xpack-3rd-party/boost-ut-xpack)
|
|
85
|
+
- [Boost UT](https://github.com/xpack-3rd-party/boost-ut-xpack)
|
|
84
86
|
|
|
85
|
-
However, they all are quite heavy in terms of memory resources
|
|
87
|
+
However, they all are quite heavy in terms of memory resources; also the
|
|
86
88
|
learning curve for mastering them is quite steep.
|
|
87
89
|
|
|
88
90
|
Thus, for embedded projects, a simpler solution, with a smaller
|
|
@@ -97,35 +99,38 @@ The later v3.x was a full rework inspired by
|
|
|
97
99
|
|
|
98
100
|
The main characteristics of µTest++, basically inherited from Boost UT, are:
|
|
99
101
|
|
|
100
|
-
- intended to test both C and C
|
|
102
|
+
- intended to test **both C and C++** projects
|
|
101
103
|
- modern C++ 20 code (this was also the reason
|
|
102
104
|
to raise the bar to C++ 20 for the entire µOS++ project)
|
|
103
|
-
- macro free (while preserving the nice feature of being able to report
|
|
105
|
+
- **macro free** (while preserving the nice feature of being able to report
|
|
104
106
|
the file name and line number for failed tests)
|
|
105
|
-
- expectations
|
|
106
|
-
- test cases
|
|
107
|
+
- **expectations**, **assumptions**, **exceptions**
|
|
108
|
+
- **test cases**, **test suites**
|
|
107
109
|
- automatic test suites registration
|
|
108
110
|
|
|
109
111
|
As major differentiator from Boost UT:
|
|
110
112
|
|
|
111
|
-
- reduced memory footprint
|
|
113
|
+
- **reduced memory footprint**, since there are no dependencies on
|
|
112
114
|
the standard C++ stream library
|
|
113
|
-
- a slightly simplified API
|
|
115
|
+
- a slightly **simplified API**
|
|
114
116
|
|
|
115
117
|
### Concepts and features
|
|
116
118
|
|
|
117
119
|
- for complex applications, test cases can be grouped in test suites
|
|
118
|
-
- test suites can be located in separate compilation units
|
|
120
|
+
- test suites can be located in separate compilation units; they automatically
|
|
119
121
|
register themselves to the runner;
|
|
120
|
-
- a test suite is a named sequence of test cases;
|
|
121
|
-
- a test case is a sequence of test conditions
|
|
122
|
-
|
|
122
|
+
- a **test suite** is a named sequence of test cases;
|
|
123
|
+
- a **test case** is a sequence of **test conditions**
|
|
124
|
+
(or simply **tests**, or **checks**),
|
|
125
|
+
which are expectations/assumptions,
|
|
126
|
+
i.e. conditions expected to be true;
|
|
123
127
|
- tests are based on logical expressions, which usually
|
|
124
128
|
compute a result and compare it to an expected value
|
|
125
129
|
- for C++ projects: it is also possible to check if, while evaluating
|
|
126
|
-
an expression, exceptions are thrown or not;
|
|
127
|
-
- each test either succeeds or fails;
|
|
128
|
-
-
|
|
130
|
+
an expression, **exceptions** are thrown or not;
|
|
131
|
+
- each test either succeeds or fails;
|
|
132
|
+
- for **expectations**, the runner keeps counts of them;
|
|
133
|
+
- **assumptions** are hard conditions expected to be true in order for the test
|
|
129
134
|
to be able to run;
|
|
130
135
|
- failed assumptions abort the test;
|
|
131
136
|
- the test progress is shown on STDOUT, with each tests on a
|
|
@@ -136,7 +141,7 @@ As major differentiator from Boost UT:
|
|
|
136
141
|
exit code.
|
|
137
142
|
|
|
138
143
|
A test suite is considered successful
|
|
139
|
-
if there is at least one successful
|
|
144
|
+
if there is at least one successful expectation
|
|
140
145
|
and there are no failed tests.
|
|
141
146
|
|
|
142
147
|
If all tests suites are successful, the process returns 0 as exit value.
|
|
@@ -146,13 +151,13 @@ If all tests suites are successful, the process returns 0 as exit value.
|
|
|
146
151
|
The **International Software Testing Qualification Board** defines some terms
|
|
147
152
|
used in testing frameworks:
|
|
148
153
|
|
|
149
|
-
- test condition
|
|
154
|
+
- **test condition**: a testable aspect of a component or system identified
|
|
150
155
|
as a basis for testing (implemented in µTest++ as calls to `expect()` or
|
|
151
156
|
`assume()` functions);
|
|
152
|
-
- test case
|
|
157
|
+
- **test case**: a set of preconditions, inputs, actions (where applicable),
|
|
153
158
|
expected results and postconditions, developed based on test conditions
|
|
154
159
|
(implemented in µTest++ as calls to the `test_case()` function)
|
|
155
|
-
- test suite
|
|
160
|
+
- **test suite**: a set of test scripts or test procedures to be executed in
|
|
156
161
|
a specific test run (implemented in µTest++ as instances of the
|
|
157
162
|
`test_suite` class).
|
|
158
163
|
|
|
@@ -184,11 +189,11 @@ main(int argc, char* argv[])
|
|
|
184
189
|
When running this test, the output looks like:
|
|
185
190
|
|
|
186
191
|
```console
|
|
187
|
-
Minimal - test suite started
|
|
192
|
+
• Minimal - test suite started
|
|
188
193
|
|
|
189
194
|
✓ Check truth - test case passed (1 check)
|
|
190
195
|
|
|
191
|
-
Minimal - test suite passed (1 check in 1 test case)
|
|
196
|
+
✓ Minimal - test suite passed (1 check in 1 test case)
|
|
192
197
|
```
|
|
193
198
|
|
|
194
199
|
A slightly more useful example would check the result of a computed value;
|
|
@@ -211,7 +216,7 @@ main(int argc, char* argv[])
|
|
|
211
216
|
initialize(argc, argv, "The Answer");
|
|
212
217
|
|
|
213
218
|
test_case ("Check answer", [] {
|
|
214
|
-
expect (compute_answer() == 42
|
|
219
|
+
expect (compute_answer() == 42) << "answer is 42";
|
|
215
220
|
});
|
|
216
221
|
|
|
217
222
|
return exit_code ();
|
|
@@ -219,14 +224,14 @@ main(int argc, char* argv[])
|
|
|
219
224
|
```
|
|
220
225
|
|
|
221
226
|
```console
|
|
222
|
-
The Answer - test suite started
|
|
227
|
+
• The Answer - test suite started
|
|
223
228
|
|
|
224
229
|
✓ Check answer - test case passed (1 check)
|
|
225
230
|
|
|
226
|
-
The Answer - test suite passed (1 check passed, 0 checks failed, in 1 test case)
|
|
231
|
+
✓ The Answer - test suite passed (1 check passed, 0 checks failed, in 1 test case)
|
|
227
232
|
```
|
|
228
233
|
|
|
229
|
-
In case
|
|
234
|
+
In case the function returns the wrong answer, the test will fail;
|
|
230
235
|
for example:
|
|
231
236
|
|
|
232
237
|
```c++
|
|
@@ -240,20 +245,20 @@ compute_answer()
|
|
|
240
245
|
In this case the test will fail with:
|
|
241
246
|
|
|
242
247
|
```console
|
|
243
|
-
The Answer - test suite started
|
|
248
|
+
• The Answer - test suite started
|
|
244
249
|
|
|
245
250
|
• Check answer - test case started
|
|
246
251
|
✗ answer is 42 FAILED (answer.cpp:17)
|
|
247
252
|
✗ Check answer - test case FAILED (0 checks passed, 1 check failed)
|
|
248
253
|
|
|
249
|
-
The Answer - test suite FAILED (0 checks passed, 1 check failed, in 1 test case)
|
|
254
|
+
✗ The Answer - test suite FAILED (0 checks passed, 1 check failed, in 1 test case)
|
|
250
255
|
```
|
|
251
256
|
|
|
252
257
|
The output identifies the failed test as located at line 17, but does not
|
|
253
258
|
provide more details, for example it does not tell what was the actual
|
|
254
259
|
wrong answer.
|
|
255
260
|
|
|
256
|
-
To get such useful information, the test should be slightly more elaborate,
|
|
261
|
+
To get such a useful information, the test should be slightly more elaborate,
|
|
257
262
|
and must use some custom comparators or operators; for example:
|
|
258
263
|
|
|
259
264
|
```c++
|
|
@@ -285,7 +290,7 @@ main(int argc, char* argv[])
|
|
|
285
290
|
The result would look like:
|
|
286
291
|
|
|
287
292
|
```console
|
|
288
|
-
The Answer - test suite started
|
|
293
|
+
• The Answer - test suite started
|
|
289
294
|
|
|
290
295
|
• Check answer with comparator - test case started
|
|
291
296
|
✗ answer is 42 FAILED (answer.cpp:17, 43 == 42)
|
|
@@ -296,24 +301,27 @@ The Answer - test suite started
|
|
|
296
301
|
✗ answer is 42 FAILED (answer.cpp:25, 43 == 42)
|
|
297
302
|
✗ Check answer with operator - test case FAILED (0 checks passed, 1 check failed)
|
|
298
303
|
|
|
299
|
-
The Answer - test suite FAILED (0 checks passed, 3 checks failed, in 2 test cases)
|
|
304
|
+
✗ The Answer - test suite FAILED (0 checks passed, 3 checks failed, in 2 test cases)
|
|
300
305
|
```
|
|
301
306
|
|
|
302
307
|
In the first case, `eq()` is a function that basically compares almost
|
|
303
|
-
everything and is able to keep track of its operands.
|
|
304
|
-
functions for all comparisons.
|
|
308
|
+
everything and is able to keep track of the values of its operands.
|
|
309
|
+
There are similar functions for all comparisons.
|
|
305
310
|
|
|
306
311
|
In the second case, a custom operator is used. To avoid interferences
|
|
307
|
-
with other operators,
|
|
308
|
-
|
|
312
|
+
with other operators, this custom operator is defined in a separate namespace
|
|
313
|
+
(which must
|
|
314
|
+
be explicitly referred to as shown) and matches only operands of
|
|
315
|
+
some specific types.
|
|
309
316
|
|
|
310
|
-
To cast the integer constant `42` to
|
|
317
|
+
To cast the integer constant `42` to such a specific type, a custom literal
|
|
311
318
|
is available (`_i`), which is also defined in a separate namespace.
|
|
312
319
|
|
|
313
320
|
In addition to literals used to define constants, there are also definitions
|
|
314
321
|
which can be used to cast expressions.
|
|
315
322
|
|
|
316
|
-
For the
|
|
323
|
+
For the custom operators to match, it is necessary for at least one of
|
|
324
|
+
the operands
|
|
317
325
|
to be of the specific type, usually the constant using a literal, but if both
|
|
318
326
|
are expression, at least one of them must be casted.
|
|
319
327
|
|
|
@@ -337,7 +345,8 @@ a boolean or use custom comparators/operators derived from an
|
|
|
337
345
|
internal `detail::op` type.
|
|
338
346
|
|
|
339
347
|
For generic checks performed outside the testing framework, the results can
|
|
340
|
-
be reported with `expect(true)` or `expect(false)
|
|
348
|
+
be reported with `expect(true)` or `expect(false)` (see the example testing
|
|
349
|
+
multiple exceptions below).
|
|
341
350
|
|
|
342
351
|
#### Assumptions
|
|
343
352
|
|
|
@@ -349,12 +358,12 @@ bool assume(const Expr_T& expr);
|
|
|
349
358
|
```
|
|
350
359
|
|
|
351
360
|
Similarly, the template matches only expressions that evaluate to
|
|
352
|
-
a boolean
|
|
361
|
+
a boolean and use custom comparators/operators derived from a
|
|
353
362
|
internal `detail::op` type.
|
|
354
363
|
|
|
355
364
|
#### Function comparators
|
|
356
365
|
|
|
357
|
-
Expectations and assumptions
|
|
366
|
+
Expectations and assumptions can test any expression evaluating to a
|
|
358
367
|
boolean value, but in order to nicely report the difference between expected
|
|
359
368
|
and actual values in failed
|
|
360
369
|
conditions, the following generic comparators are available:
|
|
@@ -408,7 +417,8 @@ actual values compared during the test; for example:
|
|
|
408
417
|
### Logical function operators
|
|
409
418
|
|
|
410
419
|
Complex expressions can be checked in a single line, using the logical
|
|
411
|
-
`_and()`, `_or()` and `_not()` functions. The names are prefixed
|
|
420
|
+
`_and()`, `_or()` and `_not()` functions. The names are prefixed with
|
|
421
|
+
underscore since
|
|
412
422
|
`and`, `or` and `not` are reserved words in C/C++.
|
|
413
423
|
|
|
414
424
|
```c++
|
|
@@ -436,15 +446,15 @@ as shown below.
|
|
|
436
446
|
In C/C++, plain strings are actually pointers to characters, and simply
|
|
437
447
|
comparing them does not compare the content but the memory addresses.
|
|
438
448
|
|
|
439
|
-
For string comparisons to compare the content, use `string_view
|
|
449
|
+
For string comparisons to compare the content, use `string_view` objects:
|
|
440
450
|
|
|
441
451
|
```c++
|
|
442
452
|
#include <string_view>
|
|
443
453
|
using namespace std::literals; // For the "sv" literal.
|
|
444
454
|
// ...
|
|
445
455
|
|
|
446
|
-
expect (eq (std::string_view{ compute_ultimate_answer () }, "
|
|
447
|
-
<< "ultimate_answer is '
|
|
456
|
+
expect (eq (std::string_view{ compute_ultimate_answer () }, "forty-two"sv))
|
|
457
|
+
<< "ultimate_answer is 'forty-two'";
|
|
448
458
|
```
|
|
449
459
|
|
|
450
460
|
#### Comparing containers
|
|
@@ -539,8 +549,8 @@ using namespace std::literals; // For the "sv" literal.
|
|
|
539
549
|
test_case ("Operators", [] {
|
|
540
550
|
using namespace micro_test_plus::operators;
|
|
541
551
|
|
|
542
|
-
expect (std::string_view{ compute_ultimate_answer () } == "
|
|
543
|
-
<< "ultimate answer == '
|
|
552
|
+
expect (std::string_view{ compute_ultimate_answer () } == "forty-two"sv)
|
|
553
|
+
<< "ultimate answer == 'forty-two'";
|
|
544
554
|
|
|
545
555
|
expect (std::vector<int>{ 1, 2 } == std::vector<int>{ 1, 2 })
|
|
546
556
|
<< "vector{ 1, 2 } == vector{ 1, 2 }";
|
|
@@ -654,8 +664,8 @@ expect (_f {expression} == 42_f);
|
|
|
654
664
|
|
|
655
665
|
#### Function comparators vs. operators & literals
|
|
656
666
|
|
|
657
|
-
|
|
658
|
-
overloaded operators
|
|
667
|
+
Which to use, functions like `eq()` or the
|
|
668
|
+
overloaded operators? A very good question!
|
|
659
669
|
|
|
660
670
|
Functions guarantee that the nice feature of showing the actual values
|
|
661
671
|
when expectations fail is always available. Also the syntax is more on the
|
|
@@ -666,9 +676,11 @@ but require the hack with the type wrappers and literals to enforce the
|
|
|
666
676
|
types, otherwise the actual values will not be displayed when the
|
|
667
677
|
expectations fail.
|
|
668
678
|
|
|
669
|
-
Both syntaxes are functional, and, once
|
|
679
|
+
Both syntaxes are functional, and, once the differences understood,
|
|
670
680
|
the issue is a matter of personal preferences.
|
|
671
681
|
|
|
682
|
+
For example, the µOS++ projects favour explicit comparator functions.
|
|
683
|
+
|
|
672
684
|
#### Explicit namespace
|
|
673
685
|
|
|
674
686
|
If for any reasons, the definitions in the `micro_test_plus` namespace
|
|
@@ -690,11 +702,11 @@ Example:
|
|
|
690
702
|
|
|
691
703
|
#### Exceptions
|
|
692
704
|
|
|
693
|
-
|
|
705
|
+
A C++ testing framework must be able to check if an expression
|
|
694
706
|
(usually a function call), throws or not an exception.
|
|
695
707
|
|
|
696
|
-
The following function templates allow to check
|
|
697
|
-
|
|
708
|
+
The following function templates allow to check various exceptions related
|
|
709
|
+
conditions:
|
|
698
710
|
|
|
699
711
|
```C++
|
|
700
712
|
// Check for any exception.
|
|
@@ -786,7 +798,7 @@ name, which is used for the default test suite:
|
|
|
786
798
|
void initialize (int argc, char* argv[], const char* name = "Main");
|
|
787
799
|
```
|
|
788
800
|
|
|
789
|
-
The arguments
|
|
801
|
+
The arguments can be used for controlling the verbosity level.
|
|
790
802
|
|
|
791
803
|
#### Return the test result
|
|
792
804
|
|
|
@@ -836,11 +848,13 @@ order (since the order in which the
|
|
|
836
848
|
static constructors are invoked is not specified);
|
|
837
849
|
thus there should be no dependencies between test suites.
|
|
838
850
|
|
|
839
|
-
|
|
851
|
+
The registered test suites are executed when the function
|
|
852
|
+
`exit_code()` is invoked.
|
|
840
853
|
|
|
841
854
|
Examples:
|
|
842
855
|
|
|
843
856
|
```c++
|
|
857
|
+
// Test suite with generic parameters.
|
|
844
858
|
static void
|
|
845
859
|
test_suite_args (int ic, int iv, int& ir, int* ip1, int* ip2)
|
|
846
860
|
{
|
|
@@ -915,35 +929,41 @@ TODO: add a test to show how to do this.
|
|
|
915
929
|
|
|
916
930
|
#### Verbosity
|
|
917
931
|
|
|
918
|
-
By default, the test reporter shows detailed results only for
|
|
919
|
-
|
|
932
|
+
By default, the test reporter shows detailed results only for the failed
|
|
933
|
+
test cases; successful test cases are shown as a single line with
|
|
920
934
|
the total counts of passed/failed checks.
|
|
921
935
|
|
|
922
|
-
To control the verbosity use one of the following command line options:
|
|
936
|
+
To control the verbosity, use one of the following command line options:
|
|
923
937
|
|
|
924
|
-
- `--verbose
|
|
925
|
-
- `--quiet
|
|
926
|
-
- `--silent
|
|
938
|
+
- `--verbose` - show all expectations, regardless of the result
|
|
939
|
+
- `--quiet` - show only the test suite totals
|
|
940
|
+
- `--silent` - suppress all output and only return the exit code
|
|
927
941
|
|
|
928
942
|
### Memory footprint
|
|
929
943
|
|
|
930
944
|
The memory footprint of unit tests based on µTest++ is definitely smaller than
|
|
931
|
-
that of traditional C++ testing framework,
|
|
932
|
-
used.
|
|
945
|
+
that of traditional C++ testing framework, mainly because the `iostream`
|
|
946
|
+
library is not used.
|
|
933
947
|
|
|
934
948
|
However, the use of templates for implementing the comparators and
|
|
935
949
|
operators should be carefully observed for platforms with really
|
|
936
950
|
limited amounts of memory, since each pair of different operands
|
|
937
951
|
contributes to the program size.
|
|
938
952
|
|
|
939
|
-
At the limit, µTest++ can be used
|
|
940
|
-
without custom comparators and operators
|
|
953
|
+
At the limit, µTest++ can be used
|
|
954
|
+
without custom comparators and operators
|
|
955
|
+
(only with regular boolean expressions), and still be able to provide
|
|
941
956
|
the basic functionality of testing various conditions, but without
|
|
942
957
|
the optional features of displaying the actual values compared.
|
|
943
958
|
|
|
944
|
-
Also, please note that the memory footprint on `debug
|
|
959
|
+
Also, please note that the memory footprint on `debug` (built with `-O0`),
|
|
945
960
|
is significantly larger than on `release`. If necessary, the optimization
|
|
946
|
-
for the `debug` build can be increased to `-Og`,
|
|
961
|
+
for the `debug` build can be increased to `-Og`, to save some memory.
|
|
962
|
+
|
|
963
|
+
### Status
|
|
964
|
+
|
|
965
|
+
The **µTest++** source library is fully functional and is used to test the
|
|
966
|
+
µOS++ packages.
|
|
947
967
|
|
|
948
968
|
### Build & integration info
|
|
949
969
|
|
|
@@ -952,23 +972,23 @@ written in C++ too, but the tested code can also be written in plain C.
|
|
|
952
972
|
The framework source code was compiled with GCC 11, clang 12
|
|
953
973
|
and arm-none-eabi-gcc 10, and should be warning free.
|
|
954
974
|
|
|
955
|
-
To run on embedded platforms
|
|
975
|
+
To run **on embedded platforms**, the test framework requires a minimum
|
|
956
976
|
of support from the system, like writing to the
|
|
957
977
|
output stream. Any such environments are acceptable, but for standalone
|
|
958
978
|
tests the most common solution is to use **Arm semihosting**.
|
|
959
979
|
|
|
960
980
|
To ease the integration of this package into user projects, there
|
|
961
|
-
are already made CMake and meson configuration files (see below).
|
|
981
|
+
are already made **CMake** and **meson** configuration files (see below).
|
|
962
982
|
|
|
963
983
|
For other build systems, consider the following details:
|
|
964
984
|
|
|
965
985
|
#### Include folders
|
|
966
986
|
|
|
967
|
-
The following
|
|
987
|
+
The following folders should be passed to the compiler during the build:
|
|
968
988
|
|
|
969
989
|
- `include`
|
|
970
990
|
|
|
971
|
-
The header
|
|
991
|
+
The header files to be included in user projects are:
|
|
972
992
|
|
|
973
993
|
```c++
|
|
974
994
|
#include <micro-os-plus/micro-test-plus.h>
|
|
@@ -976,7 +996,7 @@ The header file to be included is:
|
|
|
976
996
|
|
|
977
997
|
#### Source files
|
|
978
998
|
|
|
979
|
-
The source files to be added are:
|
|
999
|
+
The source files to be added to user projects are:
|
|
980
1000
|
|
|
981
1001
|
- `src/micro-test-plus.cpp`
|
|
982
1002
|
- `src/test-reporter.cpp`
|
|
@@ -1016,8 +1036,8 @@ namespace defines the literals (like `1_i`);
|
|
|
1016
1036
|
|
|
1017
1037
|
#### CMake
|
|
1018
1038
|
|
|
1019
|
-
To integrate the µTest++ source library into a CMake application,
|
|
1020
|
-
folder to the build:
|
|
1039
|
+
To integrate the µTest++ source library into a CMake application,
|
|
1040
|
+
add this folder to the build:
|
|
1021
1041
|
|
|
1022
1042
|
```cmake
|
|
1023
1043
|
add_subdirectory("xpacks/micro-os-plus-micro-test-plus")`
|
|
@@ -1035,8 +1055,8 @@ target_link_libraries(your-target PRIVATE
|
|
|
1035
1055
|
|
|
1036
1056
|
#### meson
|
|
1037
1057
|
|
|
1038
|
-
To integrate the µTest++ source library into a meson application,
|
|
1039
|
-
folder to the build:
|
|
1058
|
+
To integrate the µTest++ source library into a meson application,
|
|
1059
|
+
add this folder to the build:
|
|
1040
1060
|
|
|
1041
1061
|
```meson
|
|
1042
1062
|
subdir('xpacks/micro-os-plus-micro-test-plus')
|
|
@@ -1095,7 +1115,7 @@ main (int argc, char* argv[])
|
|
|
1095
1115
|
expect (compute_answer () != 43_i) << "answer != 43";
|
|
1096
1116
|
});
|
|
1097
1117
|
|
|
1098
|
-
test_case ("Check
|
|
1118
|
+
test_case ("Check parametrised", [] {
|
|
1099
1119
|
auto f = [] (int i) { return i + 42; };
|
|
1100
1120
|
expect (eq (f (1), 43)) << "lambda == 43";
|
|
1101
1121
|
});
|
|
@@ -1134,7 +1154,7 @@ $ xpm run test-native
|
|
|
1134
1154
|
1: Test timeout computed to be: 10000000
|
|
1135
1155
|
1: Built with clang Apple LLVM 13.0.0 (clang-1300.0.29.30), no FP, with exceptions.
|
|
1136
1156
|
1:
|
|
1137
|
-
1: Sample - test suite started
|
|
1157
|
+
1: • Sample - test suite started
|
|
1138
1158
|
1:
|
|
1139
1159
|
1: • Check various conditions - test case started
|
|
1140
1160
|
1: ✓ compute_one() == 1
|
|
@@ -1142,15 +1162,15 @@ $ xpm run test-native
|
|
|
1142
1162
|
1: ✓ condition() is true
|
|
1143
1163
|
1: ✓ Check various conditions - test case passed (3 checks)
|
|
1144
1164
|
1:
|
|
1145
|
-
1: • Check
|
|
1165
|
+
1: • Check parametrised - test case started
|
|
1146
1166
|
1: ✓ lambda == 43
|
|
1147
|
-
1: ✓ Check
|
|
1167
|
+
1: ✓ Check parametrised - test case passed (1 check)
|
|
1148
1168
|
1:
|
|
1149
1169
|
1: • Check exceptions - test case started
|
|
1150
1170
|
1: ✓ std::runtime_error thrown
|
|
1151
1171
|
1: ✓ Check exceptions - test case passed (1 check)
|
|
1152
1172
|
1:
|
|
1153
|
-
1: Sample - test suite passed (5 tests in 3 test cases)
|
|
1173
|
+
1: ✓ Sample - test suite passed (5 tests in 3 test cases)
|
|
1154
1174
|
1/2 Test #1: sample-test ...................... Passed 0.00 sec
|
|
1155
1175
|
...
|
|
1156
1176
|
```
|
|
@@ -1170,11 +1190,11 @@ The project is fully tested via GitHub
|
|
|
1170
1190
|
[Actions](https://github.com/micro-os-plus/micro-test-plus-xpack/actions/)
|
|
1171
1191
|
on each push.
|
|
1172
1192
|
|
|
1173
|
-
The test platforms are GNU/Linux
|
|
1174
|
-
compiled with GCC and clang; tests for embedded platforms are compiled
|
|
1175
|
-
with arm-none-eabi-gcc and run via QEMU
|
|
1193
|
+
The test platforms are **GNU/Linux**, **macOS** and **Windows**; native tests
|
|
1194
|
+
are compiled with GCC and clang; tests for embedded platforms are compiled
|
|
1195
|
+
with **arm-none-eabi-gcc** and run via **QEMU**.
|
|
1176
1196
|
|
|
1177
|
-
There are two
|
|
1197
|
+
There are two sets of tests, one that runs on every push, with a
|
|
1178
1198
|
limited number of tests, and a set that is triggered manually,
|
|
1179
1199
|
usually before releases, and runs all tests on all supported
|
|
1180
1200
|
platforms.
|
|
@@ -1198,12 +1218,12 @@ backwards incompatible changes are introduced to the public API.
|
|
|
1198
1218
|
The incompatible changes, in reverse chronological order,
|
|
1199
1219
|
are:
|
|
1200
1220
|
|
|
1201
|
-
- v3.x
|
|
1221
|
+
- **v3.x**: major rework, with full set of comparators, exceptions,
|
|
1202
1222
|
function templates for test cases and class templates for test suites;
|
|
1203
|
-
- v2.3.x
|
|
1223
|
+
- **v2.3.x**: deprecate `run_test_case(func, name)` in favour o
|
|
1204
1224
|
`run_test_case(name, func)`, to prepare for variadic templates
|
|
1205
|
-
- v2.x
|
|
1206
|
-
- v1.x
|
|
1225
|
+
- **v2.x**: the C++ namespace was renamed from `os` to `micro_os_plus`;
|
|
1226
|
+
- **v1.x**: the code was extracted from the mono-repo µOS++ project.
|
|
1207
1227
|
|
|
1208
1228
|
## Credits
|
|
1209
1229
|
|
package/meson.build
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
#
|
|
17
17
|
# `subdir('xpacks/micro-os-plus-micro-test-plus')`
|
|
18
18
|
#
|
|
19
|
-
# The result is a library and a dependency that can be
|
|
19
|
+
# The result is a library and a dependency that can be referred as:
|
|
20
20
|
#
|
|
21
21
|
# `dependencies: [micro_os_plus_micro_test_plus_dependency],`
|
|
22
22
|
|