@micro-os-plus/micro-test-plus 2.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 +145 -0
- package/CMakeLists.txt +98 -0
- package/LICENSE +21 -0
- package/README.md +456 -0
- package/include/micro-os-plus/micro-test-plus.h +152 -0
- package/meson.build +44 -0
- package/package.json +826 -0
- package/src/micro-test-plus.cpp +252 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Change & release log
|
|
2
|
+
|
|
3
|
+
Releases in reverse chronological order.
|
|
4
|
+
|
|
5
|
+
Please check
|
|
6
|
+
[GitHub](https://github.com/micro-os-plus/micro-test-plus-xpack/issues/)
|
|
7
|
+
and close existing issues and pull requests.
|
|
8
|
+
|
|
9
|
+
## 2022-02-05
|
|
10
|
+
|
|
11
|
+
- v2.2.1
|
|
12
|
+
- 473d3f3 package.json: use npmjs.com deps
|
|
13
|
+
- b88b767 CI.yml try to enable qemu-cmake on Windows
|
|
14
|
+
- 518645c package.json: enable cortexm builds on windows
|
|
15
|
+
- e342558 meson create symbolic link at build time
|
|
16
|
+
- 00ff79d cmake revert to .. instead of top symlink
|
|
17
|
+
- 68053a5 package.json: bump build-helper
|
|
18
|
+
- 65918f6 cmake notice that -flto fails on embedded
|
|
19
|
+
- 868c55d meson native with_linux_clang_lto
|
|
20
|
+
- a223600 meson: notice that -flto fails on embedded
|
|
21
|
+
- bb3628a meson always include warnings
|
|
22
|
+
- 1d1e612 meson revert to warning_level = 0
|
|
23
|
+
- cc41eac meson native without -flto
|
|
24
|
+
- d562a5e cmake native add --gc-sections
|
|
25
|
+
4bee003 cmake globals -flto for release
|
|
26
|
+
- c2c7972 package.json: bump devices-stm32f4-extras
|
|
27
|
+
- 6139edb meson: disable -flto for clang on linux
|
|
28
|
+
|
|
29
|
+
## 2022-02-04
|
|
30
|
+
|
|
31
|
+
- v2.2.0
|
|
32
|
+
- 18219ef package.json: bump deps
|
|
33
|
+
- d30ea7d updates for device-*cortexm
|
|
34
|
+
- 33e2244 cmake: add xpack_display_target_lists
|
|
35
|
+
- 4f7324b package.json: add stm32f4discovery meson
|
|
36
|
+
|
|
37
|
+
## 2022-02-03
|
|
38
|
+
|
|
39
|
+
- d64bd80 cmake update qemu-mps2
|
|
40
|
+
- 18955fa cmake update stm32f4discovery
|
|
41
|
+
- e4541e9 cmake update for interface
|
|
42
|
+
|
|
43
|
+
## 2022-02-02
|
|
44
|
+
|
|
45
|
+
- e703fa9 .vscode/launch.json: add qemu launchers
|
|
46
|
+
- 3055967 cmake: rework test commands
|
|
47
|
+
|
|
48
|
+
## 2022-02-01
|
|
49
|
+
|
|
50
|
+
- 90e894f add meson qemu
|
|
51
|
+
- 6f55a37 package.json: rename dependencies to device-*
|
|
52
|
+
- fde47e6 package.json: move toolchain files to folder
|
|
53
|
+
- 041c252 cmake: rename platform-qemu-mps2-an386
|
|
54
|
+
- 1230c9b cmake: update for device-qemu-cortexm
|
|
55
|
+
- 10304ab rename platform-qemu-mps2-an386
|
|
56
|
+
|
|
57
|
+
## 2022-01-28
|
|
58
|
+
|
|
59
|
+
- 829ffbd separate top CMake config for tests
|
|
60
|
+
- 920a928 add top symbolic link
|
|
61
|
+
- 9a5987e sample-test.cpp: static variables
|
|
62
|
+
- 82c83d8 sample-test.cpp: test args
|
|
63
|
+
|
|
64
|
+
## 2022-01-26
|
|
65
|
+
|
|
66
|
+
- 15d6fe9 package.json: skip qemu tests on windows
|
|
67
|
+
- v2.1.0
|
|
68
|
+
- rework CMake
|
|
69
|
+
|
|
70
|
+
## 2022-01-03
|
|
71
|
+
|
|
72
|
+
- v2.0.5
|
|
73
|
+
|
|
74
|
+
## 2022-01-02
|
|
75
|
+
|
|
76
|
+
- CI.yml: remove native-cmake
|
|
77
|
+
- package.json: add meson gcc/clang
|
|
78
|
+
- PLATFORM_STM32F4DISCOVERY_WITHOUT_HAL
|
|
79
|
+
|
|
80
|
+
## 2022-01-01
|
|
81
|
+
|
|
82
|
+
- meson.build: add /utf-8 to msvc options
|
|
83
|
+
- [#4] add support for MSVC
|
|
84
|
+
- package.json: use posix paths on windows
|
|
85
|
+
|
|
86
|
+
## 2021-12-29
|
|
87
|
+
|
|
88
|
+
- stm32f4discovery test functional
|
|
89
|
+
- add native meson tests
|
|
90
|
+
- package.json: add clang12 test
|
|
91
|
+
- add explicit CMakeLists.txt
|
|
92
|
+
|
|
93
|
+
## 2021-12-26
|
|
94
|
+
|
|
95
|
+
- package.json: move devDeps to configs
|
|
96
|
+
- CI.yml: test-native
|
|
97
|
+
- package.json: migrate native to xpack actions
|
|
98
|
+
|
|
99
|
+
## 2021-03-13
|
|
100
|
+
|
|
101
|
+
- v2.0.4
|
|
102
|
+
- remove -pedantic-errors, use -Werror only on bare-metal
|
|
103
|
+
|
|
104
|
+
## 2021-03-10
|
|
105
|
+
|
|
106
|
+
- v2.0.3
|
|
107
|
+
- bump devDeps
|
|
108
|
+
|
|
109
|
+
## 2021-03-09
|
|
110
|
+
|
|
111
|
+
- v2.0.2
|
|
112
|
+
- fix/silence warnings
|
|
113
|
+
- remove warning flags from cmake
|
|
114
|
+
|
|
115
|
+
## 2021-03-02
|
|
116
|
+
|
|
117
|
+
- v2.0.1
|
|
118
|
+
- fix warnings, add -Wall..., -Werrror
|
|
119
|
+
|
|
120
|
+
## 2021-03-01
|
|
121
|
+
|
|
122
|
+
- v2.0.0
|
|
123
|
+
|
|
124
|
+
## 2021-02-28
|
|
125
|
+
|
|
126
|
+
- rename micro_os_plus
|
|
127
|
+
|
|
128
|
+
## 2021-02-12
|
|
129
|
+
|
|
130
|
+
- add support for CMake find_package()
|
|
131
|
+
|
|
132
|
+
## 2021-02-07
|
|
133
|
+
|
|
134
|
+
- prepare v2.0.0-pre
|
|
135
|
+
- [#1] - rename micro_test_plus::session
|
|
136
|
+
- [#2] - sample-test: conditional exceptions
|
|
137
|
+
- [#3] - add stm32f4discovery tests
|
|
138
|
+
|
|
139
|
+
## 2021-02-05
|
|
140
|
+
|
|
141
|
+
- prepare v1.1.1-pre
|
|
142
|
+
|
|
143
|
+
## 2021-02-04
|
|
144
|
+
|
|
145
|
+
- release preliminary v1.1.0
|
package/CMakeLists.txt
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is part of the µOS++ distribution.
|
|
3
|
+
# (https://github.com/micro-os-plus)
|
|
4
|
+
# Copyright (c) 2021 Liviu Ionescu
|
|
5
|
+
#
|
|
6
|
+
# Permission to use, copy, modify, and/or distribute this software
|
|
7
|
+
# for any purpose is hereby granted, under the terms of the MIT license.
|
|
8
|
+
#
|
|
9
|
+
# If a copy of the license was not distributed with this file, it can
|
|
10
|
+
# be obtained from https://opensource.org/licenses/MIT/.
|
|
11
|
+
#
|
|
12
|
+
# -----------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
# This file is intended to be consumed by applications with:
|
|
15
|
+
#
|
|
16
|
+
# `add_subdirectory("xpacks/micro-os-plus-micro-test-plus")`
|
|
17
|
+
#
|
|
18
|
+
# The result is an interface library that can be added to the linker with:
|
|
19
|
+
#
|
|
20
|
+
# `target_link_libraries(your-target PUBLIC micro-os-plus::micro-test-plus)`
|
|
21
|
+
|
|
22
|
+
# -----------------------------------------------------------------------------
|
|
23
|
+
## Preamble ##
|
|
24
|
+
|
|
25
|
+
# https://cmake.org/cmake/help/v3.20/
|
|
26
|
+
cmake_minimum_required(VERSION 3.20)
|
|
27
|
+
|
|
28
|
+
project(
|
|
29
|
+
micro-os-plus-micro-test-plus
|
|
30
|
+
DESCRIPTION "µTest++"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
if(COMMAND xpack_get_package_name_and_version)
|
|
34
|
+
xpack_get_package_name_and_version("${CMAKE_CURRENT_SOURCE_DIR}/package.json")
|
|
35
|
+
message(VERBOSE "Processing xPack ${PACKAGE_JSON_NAME}@${PACKAGE_JSON_VERSION}...")
|
|
36
|
+
endif()
|
|
37
|
+
|
|
38
|
+
# -----------------------------------------------------------------------------
|
|
39
|
+
## The project library definitions ##
|
|
40
|
+
|
|
41
|
+
# https://cmake.org/cmake/help/v3.20/command/add_library.html?highlight=interface#normal-libraries
|
|
42
|
+
# PRIVATE: build definitions, used internally
|
|
43
|
+
# INTERFACE: usage definitions, passed up to targets linking to it
|
|
44
|
+
# PUBLIC: both
|
|
45
|
+
|
|
46
|
+
add_library(micro-os-plus-micro-test-plus-interface INTERFACE)
|
|
47
|
+
|
|
48
|
+
# -----------------------------------------------------------------------------
|
|
49
|
+
# Target settings.
|
|
50
|
+
|
|
51
|
+
target_include_directories(
|
|
52
|
+
micro-os-plus-micro-test-plus-interface
|
|
53
|
+
|
|
54
|
+
INTERFACE
|
|
55
|
+
"include"
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
target_sources(
|
|
59
|
+
micro-os-plus-micro-test-plus-interface
|
|
60
|
+
|
|
61
|
+
INTERFACE
|
|
62
|
+
"src/micro-test-plus.cpp"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
target_compile_definitions(
|
|
66
|
+
micro-os-plus-micro-test-plus-interface
|
|
67
|
+
|
|
68
|
+
INTERFACE
|
|
69
|
+
# ...
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
target_compile_options(
|
|
73
|
+
micro-os-plus-micro-test-plus-interface
|
|
74
|
+
|
|
75
|
+
INTERFACE
|
|
76
|
+
# ...
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
target_link_libraries(
|
|
80
|
+
micro-os-plus-micro-test-plus-interface
|
|
81
|
+
|
|
82
|
+
INTERFACE
|
|
83
|
+
# ...
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
if (COMMAND xpack_display_target_lists)
|
|
87
|
+
xpack_display_target_lists(micro-os-plus-micro-test-plus-interface)
|
|
88
|
+
endif()
|
|
89
|
+
|
|
90
|
+
# -----------------------------------------------------------------------------
|
|
91
|
+
# Aliases.
|
|
92
|
+
|
|
93
|
+
# https://cmake.org/cmake/help/v3.20/command/add_library.html#alias-libraries
|
|
94
|
+
add_library(micro-os-plus::micro-test-plus ALIAS micro-os-plus-micro-test-plus-interface)
|
|
95
|
+
message(VERBOSE "> micro-os-plus::micro-test-plus -> micro-os-plus-micro-test-plus-interface")
|
|
96
|
+
|
|
97
|
+
# -----------------------------------------------------------------------------
|
|
98
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Liviu Ionescu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
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?query=workflow%3A%22CI+on+Push%22)
|
|
3
|
+
|
|
4
|
+
# A source xPack with µTest++, a minimalistic testing framework
|
|
5
|
+
|
|
6
|
+
The **µTest++** project (_micro test plus_) provides a very simple
|
|
7
|
+
testing framework, intended for running unit tests on embedded
|
|
8
|
+
platforms.
|
|
9
|
+
|
|
10
|
+
The project is hosted on GitHub as
|
|
11
|
+
[micro-os-plus/micro-test-plus-xpack](https://github.com/micro-os-plus/micro-test-plus-xpack).
|
|
12
|
+
|
|
13
|
+
## Maintainer info
|
|
14
|
+
|
|
15
|
+
This page is addressed to developers who plan to include this package
|
|
16
|
+
into their own projects.
|
|
17
|
+
|
|
18
|
+
For maintainer infos, please see the
|
|
19
|
+
[README-MAINTAINER](README-MAINTAINER.md) file.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
As a source xPacks, the easiest way to add it to a project is via **xpm**,
|
|
24
|
+
but it can also be used as any Git project, for example as a submodule.
|
|
25
|
+
|
|
26
|
+
### Prerequisites
|
|
27
|
+
|
|
28
|
+
A recent [xpm](https://xpack.github.io/xpm/),
|
|
29
|
+
which is a portable [Node.js](https://nodejs.org/) command line application.
|
|
30
|
+
|
|
31
|
+
For details please follow the instructions in the
|
|
32
|
+
[install](https://xpack.github.io/install/) page.
|
|
33
|
+
|
|
34
|
+
### xpm
|
|
35
|
+
|
|
36
|
+
This package is available as
|
|
37
|
+
[`@micro-os-plus/micro-test-plus`](https://www.npmjs.com/package/@micro-os-plus/micro-test-plus)
|
|
38
|
+
from the `npmjs.com` registry:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
cd my-project
|
|
42
|
+
xpm init # Unless a package.json is already present
|
|
43
|
+
|
|
44
|
+
xpm install @micro-os-plus/micro-test-plus@latest
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Git submodule
|
|
48
|
+
|
|
49
|
+
If, for any reason, **xpm** is not available, the next recommended
|
|
50
|
+
solution is to link it as a Git submodule below an `xpacks` folder.
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
cd my-project
|
|
54
|
+
git init # Unless already a Git project
|
|
55
|
+
mkdir -p xpacks
|
|
56
|
+
|
|
57
|
+
git submodule add https://github.com/micro-os-plus/micro-test-plus-xpack.git \
|
|
58
|
+
xpacks/micro-os-plus-micro-test-plus
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Branches
|
|
62
|
+
|
|
63
|
+
Apart from the unused `master` branch, there are two active branches:
|
|
64
|
+
|
|
65
|
+
- `xpack`, with the latest stable version (default)
|
|
66
|
+
- `xpack-develop`, with the current development version
|
|
67
|
+
|
|
68
|
+
All development is done in the `xpack-develop` branch, and contributions via
|
|
69
|
+
Pull Requests should be directed to this branch.
|
|
70
|
+
|
|
71
|
+
When new releases are published, the `xpack-develop` branch is merged
|
|
72
|
+
into `xpack`.
|
|
73
|
+
|
|
74
|
+
## User info
|
|
75
|
+
|
|
76
|
+
The **µTest++** framework is inspired by [Node tap](https://node-tap.org),
|
|
77
|
+
but is way simpler and has only a limited number of primitives.
|
|
78
|
+
|
|
79
|
+
- test suites must be compiled as separate applications, one apllication
|
|
80
|
+
can return only the result of one test suite
|
|
81
|
+
- a test suite may include any number of test cases
|
|
82
|
+
- each test case may perform any number of tests checks
|
|
83
|
+
- each test check either succeeds or fails
|
|
84
|
+
- the test progress is shown on STDOUT, with each test check on a separate
|
|
85
|
+
line, prefixed with either a check sign (✓) or a cross sign (✗)
|
|
86
|
+
- the main result of the test is passed back as the process exit code
|
|
87
|
+
|
|
88
|
+
If there is at least one successful test and there are no failed tests,
|
|
89
|
+
the entire test suite is successful and the process returns
|
|
90
|
+
0 as exit value.
|
|
91
|
+
|
|
92
|
+
### Build & integration info
|
|
93
|
+
|
|
94
|
+
The project is written in C++, and the tests are expected to be
|
|
95
|
+
written in C++ too (although there are no
|
|
96
|
+
major reasons to prevent adding C wrappers).
|
|
97
|
+
|
|
98
|
+
On embedded platforms, the test applications should be built with
|
|
99
|
+
**Arm semihosting** support.
|
|
100
|
+
|
|
101
|
+
To ease the integration of this package into user projects, there
|
|
102
|
+
are already made CMake and meson configuration files (see below).
|
|
103
|
+
|
|
104
|
+
For other build systems, consider the following details:
|
|
105
|
+
|
|
106
|
+
#### Source folders
|
|
107
|
+
|
|
108
|
+
- `src`
|
|
109
|
+
|
|
110
|
+
The source file to be added to user projects is: `micro-test-plus.cpp`.
|
|
111
|
+
|
|
112
|
+
#### Include folders
|
|
113
|
+
|
|
114
|
+
- `include`
|
|
115
|
+
|
|
116
|
+
The header file to be included in user project is:
|
|
117
|
+
|
|
118
|
+
```c++
|
|
119
|
+
#include <micro-os-plus/micro-test-plus.h>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### Preprocessor definitions
|
|
123
|
+
|
|
124
|
+
- none required
|
|
125
|
+
|
|
126
|
+
#### Compiler options
|
|
127
|
+
|
|
128
|
+
- `-std=c++17` or higher for C++ sources
|
|
129
|
+
- `-std=c11` for C sources
|
|
130
|
+
|
|
131
|
+
#### C++ Namespaces
|
|
132
|
+
|
|
133
|
+
- `micro_os_plus::micro_test_plus`
|
|
134
|
+
|
|
135
|
+
`micro_os_plus` is the top µOS++ namespace, and `micro_test_plus` is the µTest++ namespace.
|
|
136
|
+
|
|
137
|
+
#### C++ Classes
|
|
138
|
+
|
|
139
|
+
- `micro_os_plus::micro_test_plus::session`
|
|
140
|
+
|
|
141
|
+
The project includes only one class, `session`. To automate
|
|
142
|
+
passing the file name and the line number, several macros were added.
|
|
143
|
+
|
|
144
|
+
#### CMake
|
|
145
|
+
|
|
146
|
+
To integrate the µTest++ source library into a CMake application, add this
|
|
147
|
+
folder to the build:
|
|
148
|
+
|
|
149
|
+
```cmake
|
|
150
|
+
add_subdirectory("xpacks/micro-os-plus-micro-test-plus")`
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The result is an interface library that can be added as an application
|
|
154
|
+
dependency with:
|
|
155
|
+
|
|
156
|
+
```cmake
|
|
157
|
+
target_link_libraries(
|
|
158
|
+
your-target
|
|
159
|
+
|
|
160
|
+
PUBLIC
|
|
161
|
+
...
|
|
162
|
+
micro-os-plus::micro-test-plus
|
|
163
|
+
)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### meson
|
|
167
|
+
|
|
168
|
+
To integrate the µTest++ source library into a meson application, add this
|
|
169
|
+
folder to the build:
|
|
170
|
+
|
|
171
|
+
```meson
|
|
172
|
+
subdir('xpacks/micro-os-plus-micro-test-plus')
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The result is a dependency object that can be added as an application
|
|
176
|
+
dependency with:
|
|
177
|
+
|
|
178
|
+
```meson
|
|
179
|
+
exe = executable(
|
|
180
|
+
your-target,
|
|
181
|
+
|
|
182
|
+
dependencies: [
|
|
183
|
+
...
|
|
184
|
+
micro_os_plus_micro_test_plus_dependency
|
|
185
|
+
]
|
|
186
|
+
)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Examples
|
|
190
|
+
|
|
191
|
+
A simple example showing how to use the µTest++ framework is
|
|
192
|
+
presented below and is also available in
|
|
193
|
+
[tests/sample-test.cpp](tests/sample-test.cpp).
|
|
194
|
+
|
|
195
|
+
```c++
|
|
196
|
+
#include <micro-os-plus/micro-test-plus.h>
|
|
197
|
+
|
|
198
|
+
using namespace micro_os_plus;
|
|
199
|
+
|
|
200
|
+
// ----------------------------------------------------------------------------
|
|
201
|
+
|
|
202
|
+
// Forward definitions of the test cases.
|
|
203
|
+
void
|
|
204
|
+
test_case_something (micro_test_plus::session& t);
|
|
205
|
+
|
|
206
|
+
void
|
|
207
|
+
test_case_args (micro_test_plus::session& t);
|
|
208
|
+
|
|
209
|
+
#if defined(__EXCEPTIONS)
|
|
210
|
+
|
|
211
|
+
void
|
|
212
|
+
test_case_exception_thrown (micro_test_plus::session& t);
|
|
213
|
+
|
|
214
|
+
void
|
|
215
|
+
test_case_exception_not_thrown (micro_test_plus::session& t);
|
|
216
|
+
|
|
217
|
+
#endif // defined(__EXCEPTIONS)
|
|
218
|
+
|
|
219
|
+
int
|
|
220
|
+
compute_one (void);
|
|
221
|
+
|
|
222
|
+
const char*
|
|
223
|
+
compute_aaa (void);
|
|
224
|
+
|
|
225
|
+
bool
|
|
226
|
+
compute_condition (void);
|
|
227
|
+
|
|
228
|
+
#if defined(__EXCEPTIONS)
|
|
229
|
+
|
|
230
|
+
void
|
|
231
|
+
exercise_throw (bool mustThrow);
|
|
232
|
+
|
|
233
|
+
#endif // defined(__EXCEPTIONS)
|
|
234
|
+
|
|
235
|
+
// ----------------------------------------------------------------------------
|
|
236
|
+
|
|
237
|
+
static int g_argc;
|
|
238
|
+
static char** g_argv;
|
|
239
|
+
|
|
240
|
+
// The test suite.
|
|
241
|
+
int
|
|
242
|
+
main (int argc, char* argv[])
|
|
243
|
+
{
|
|
244
|
+
micro_test_plus::session t (argc, argv);
|
|
245
|
+
|
|
246
|
+
g_argc = argc;
|
|
247
|
+
g_argv = argv;
|
|
248
|
+
|
|
249
|
+
t.start_suite ("Sample test");
|
|
250
|
+
|
|
251
|
+
t.run_test_case (test_case_something, "Check various conditions");
|
|
252
|
+
|
|
253
|
+
t.run_test_case (test_case_args, "Check args");
|
|
254
|
+
|
|
255
|
+
#if defined(__EXCEPTIONS)
|
|
256
|
+
|
|
257
|
+
t.run_test_case (test_case_exception_thrown,
|
|
258
|
+
"Check if exceptions are thrown");
|
|
259
|
+
|
|
260
|
+
t.run_test_case (test_case_exception_not_thrown,
|
|
261
|
+
"Check if exceptions are not thrown");
|
|
262
|
+
|
|
263
|
+
#endif // defined(__EXCEPTIONS)
|
|
264
|
+
|
|
265
|
+
return t.result ();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ----------------------------------------------------------------------------
|
|
269
|
+
|
|
270
|
+
// Simple examples of functions to be tested.
|
|
271
|
+
int
|
|
272
|
+
compute_one (void)
|
|
273
|
+
{
|
|
274
|
+
return 1;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const char*
|
|
278
|
+
compute_aaa (void)
|
|
279
|
+
{
|
|
280
|
+
return "aaa";
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
bool
|
|
284
|
+
compute_condition (void)
|
|
285
|
+
{
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
#if defined(__EXCEPTIONS)
|
|
290
|
+
|
|
291
|
+
void
|
|
292
|
+
exercise_throw (bool mustThrow)
|
|
293
|
+
{
|
|
294
|
+
if (mustThrow)
|
|
295
|
+
{
|
|
296
|
+
throw "kaboom";
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
#endif // defined(__EXCEPTIONS)
|
|
301
|
+
|
|
302
|
+
// ----------------------------------------------------------------------------
|
|
303
|
+
|
|
304
|
+
// Test equality or logical conditions.
|
|
305
|
+
void
|
|
306
|
+
test_case_something (micro_test_plus::session& t)
|
|
307
|
+
{
|
|
308
|
+
// Currently only int and long values can be compared.
|
|
309
|
+
// For everything else use casts.
|
|
310
|
+
MTP_EXPECT_EQ (t, compute_one (), 1, "compute_one() == 1");
|
|
311
|
+
|
|
312
|
+
// Strings can also be compared (via `strcmp()`).
|
|
313
|
+
MTP_EXPECT_EQ (t, compute_aaa (), "aaa", "compute_aaa() == 'aaa'");
|
|
314
|
+
|
|
315
|
+
// More complex conditions are passed as booleans.
|
|
316
|
+
MTP_EXPECT_TRUE (t, compute_condition (), "condition() is true");
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
void
|
|
320
|
+
test_case_args (micro_test_plus::session& t)
|
|
321
|
+
{
|
|
322
|
+
MTP_EXPECT_EQ (t, g_argc, 3, "argc == 3");
|
|
323
|
+
|
|
324
|
+
if (g_argc > 1)
|
|
325
|
+
{
|
|
326
|
+
MTP_EXPECT_EQ (t, g_argv[1], "one", "argv[1] == 'one'");
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (g_argc > 2)
|
|
330
|
+
{
|
|
331
|
+
MTP_EXPECT_EQ (t, g_argv[2], "two", "argv[2] == 'two'");
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// ----------------------------------------------------------------------------
|
|
336
|
+
|
|
337
|
+
#if defined(__EXCEPTIONS)
|
|
338
|
+
|
|
339
|
+
// Test is something throws exceptions.
|
|
340
|
+
void
|
|
341
|
+
test_case_exception_thrown (micro_test_plus::session& t)
|
|
342
|
+
{
|
|
343
|
+
try
|
|
344
|
+
{
|
|
345
|
+
// Do something that throws.
|
|
346
|
+
exercise_throw (true);
|
|
347
|
+
|
|
348
|
+
// If we reached here, the exception was not thrown.
|
|
349
|
+
MTP_FAIL (t, "exception not thrown");
|
|
350
|
+
}
|
|
351
|
+
catch (...)
|
|
352
|
+
{
|
|
353
|
+
// Got it.
|
|
354
|
+
MTP_PASS (t, "exception thrown");
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
void
|
|
359
|
+
test_case_exception_not_thrown (micro_test_plus::session& t)
|
|
360
|
+
{
|
|
361
|
+
try
|
|
362
|
+
{
|
|
363
|
+
// Do something that may throw, but it doesn't.
|
|
364
|
+
exercise_throw (false);
|
|
365
|
+
|
|
366
|
+
// If we reached here, everything is fine.
|
|
367
|
+
MTP_PASS (t, "exception not thrown");
|
|
368
|
+
}
|
|
369
|
+
catch (...)
|
|
370
|
+
{
|
|
371
|
+
MTP_FAIL (t, "exception thrown");
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
#endif // defined(__EXCEPTIONS)
|
|
376
|
+
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
The output of running such a test looks like:
|
|
380
|
+
|
|
381
|
+
```console
|
|
382
|
+
$ cd micro-test-plus-xpack.git
|
|
383
|
+
$ xpm install-all
|
|
384
|
+
...
|
|
385
|
+
$ xpm run test-native
|
|
386
|
+
...
|
|
387
|
+
> Executing task: xpm run test --config native-cmake-debug <
|
|
388
|
+
|
|
389
|
+
> cd build/native-cmake-debug && ctest -V
|
|
390
|
+
UpdateCTestConfiguration from :/Users/ilg/My Files/WKS Projects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/build/native-cmake-debug/DartConfiguration.tcl
|
|
391
|
+
UpdateCTestConfiguration from :/Users/ilg/My Files/WKS Projects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/build/native-cmake-debug/DartConfiguration.tcl
|
|
392
|
+
Test project /Users/ilg/My Files/WKS Projects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/build/native-cmake-debug
|
|
393
|
+
Constructing a list of tests
|
|
394
|
+
Done constructing a list of tests
|
|
395
|
+
Updating test list for fixtures
|
|
396
|
+
Added 0 tests to meet fixture requirements
|
|
397
|
+
Checking test dependency graph...
|
|
398
|
+
Checking test dependency graph end
|
|
399
|
+
test 1
|
|
400
|
+
Start 1: unit-test
|
|
401
|
+
|
|
402
|
+
1: Test command: /Users/ilg/My\ Files/WKS\ Projects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/build/native-cmake-debug/platform/unit-test
|
|
403
|
+
...
|
|
404
|
+
1/2 Test #1: unit-test ........................ Passed 0.00 sec
|
|
405
|
+
test 2
|
|
406
|
+
Start 2: sample-test
|
|
407
|
+
|
|
408
|
+
2: Test command: /Users/ilg/My\ Files/WKS\ Projects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/build/native-cmake-debug/platform/sample-test "one" "two"
|
|
409
|
+
2: Test timeout computed to be: 10000000
|
|
410
|
+
2: Built with clang Apple LLVM 13.0.0 (clang-1300.0.29.30), no FP, with exceptions, with DEBUG.
|
|
411
|
+
2: argv[] = '/Users/ilg/My Files/WKS Projects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/build/native-cmake-debug/platform/sample-test' 'one' 'two'
|
|
412
|
+
2:
|
|
413
|
+
2: Sample test started
|
|
414
|
+
2:
|
|
415
|
+
2: Check various conditions
|
|
416
|
+
2: ✓ compute_one() == 1
|
|
417
|
+
2: ✓ compute_aaa() == 'aaa'
|
|
418
|
+
2: ✓ condition() is true
|
|
419
|
+
2:
|
|
420
|
+
2: Check args
|
|
421
|
+
2: ✓ argc == 3
|
|
422
|
+
2: ✓ argv[1] == 'one'
|
|
423
|
+
2: ✓ argv[2] == 'two'
|
|
424
|
+
2:
|
|
425
|
+
2: Check if exceptions are thrown
|
|
426
|
+
2: ✓ exception thrown
|
|
427
|
+
2:
|
|
428
|
+
2: Check if exceptions are not thrown
|
|
429
|
+
2: ✓ exception not thrown
|
|
430
|
+
2:
|
|
431
|
+
2: Sample test passed (8 tests in 4 test cases)
|
|
432
|
+
2/2 Test #2: sample-test ...................... Passed 0.00 sec
|
|
433
|
+
|
|
434
|
+
100% tests passed, 0 tests failed out of 2
|
|
435
|
+
|
|
436
|
+
Total Test time (real) = 0.01 sec
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Known problems
|
|
440
|
+
|
|
441
|
+
- none
|
|
442
|
+
|
|
443
|
+
### Tests
|
|
444
|
+
|
|
445
|
+
The project is fully tested via GitHub
|
|
446
|
+
[Actions](https://github.com/micro-os-plus/micro-test-plus-xpack/actions/)
|
|
447
|
+
on each push.
|
|
448
|
+
The tests run on GNU/Linux, macOS and Windows, are compiled with GCC,
|
|
449
|
+
clang and arm-none-eabi-gcc and run natively or via QEMU.
|
|
450
|
+
|
|
451
|
+
## License
|
|
452
|
+
|
|
453
|
+
The original content is released under the
|
|
454
|
+
[MIT License](https://opensource.org/licenses/MIT/),
|
|
455
|
+
with all rights reserved to
|
|
456
|
+
[Liviu Ionescu](https://github.com/ilg-ul/).
|