ceedling 0.31.0 → 0.31.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/example_file_call.c +6 -0
- data/assets/example_file_call.h +6 -0
- data/assets/test_example_file_with_mock.c +13 -0
- data/bin/ceedling +2 -2
- data/ceedling.gemspec +1 -1
- data/lib/ceedling/configurator.rb +7 -2
- data/lib/ceedling/configurator_plugins.rb +21 -1
- data/lib/ceedling/defaults.rb +1 -0
- data/lib/ceedling/preprocessinator_extractor.rb +2 -0
- data/lib/ceedling/preprocessinator_includes_handler.rb +24 -24
- data/lib/ceedling/version.rb +11 -7
- data/plugins/gcov/config/defaults_gcov.rb +118 -0
- data/plugins/gcov/lib/gcovr_reportinator.rb +1 -1
- data/plugins/gcov/lib/reportgenerator_reportinator.rb +1 -1
- data/plugins/junit_tests_report/lib/junit_tests_report.rb +6 -6
- data/plugins/module_generator/README.md +16 -2
- data/plugins/module_generator/lib/module_generator.rb +1 -0
- data/spec/gcov/gcov_deployment_spec.rb +1 -1
- data/spec/preprocessinator_includes_handler_spec.rb +38 -8
- data/spec/spec_system_helper.rb +19 -0
- data/spec/system/deployment_spec.rb +1 -0
- data/vendor/cmock/lib/cmock_file_writer.rb +2 -3
- data/vendor/cmock/lib/cmock_generator.rb +87 -70
- data/vendor/cmock/lib/cmock_header_parser.rb +29 -27
- data/vendor/cmock/src/cmock.h +1 -1
- data/vendor/cmock/test/unit/cmock_generator_main_test.rb +46 -41
- data/vendor/cmock/test/unit/cmock_header_parser_test.rb +46 -40
- data/vendor/cmock/vendor/c_exception/README.md +6 -4
- data/vendor/cmock/vendor/c_exception/docs/CException.md +2 -2
- data/vendor/cmock/vendor/c_exception/lib/CException.h +1 -1
- data/vendor/cmock/vendor/c_exception/lib/meson.build +2 -2
- data/vendor/cmock/vendor/c_exception/meson.build +36 -2
- data/vendor/cmock/vendor/unity/README.md +77 -71
- data/vendor/cmock/vendor/unity/auto/generate_test_runner.rb +1 -1
- data/vendor/cmock/vendor/unity/docs/ThrowTheSwitchCodingStandard.md +107 -126
- data/vendor/cmock/vendor/unity/docs/UnityAssertionsReference.md +149 -193
- data/vendor/cmock/vendor/unity/docs/UnityConfigurationGuide.md +236 -294
- data/vendor/cmock/vendor/unity/docs/UnityGettingStartedGuide.md +112 -121
- data/vendor/cmock/vendor/unity/docs/UnityHelperScriptsGuide.md +82 -115
- data/vendor/cmock/vendor/unity/extras/fixture/readme.md +16 -19
- data/vendor/cmock/vendor/unity/extras/memory/readme.md +27 -34
- data/vendor/cmock/vendor/unity/src/unity.c +1 -1
- data/vendor/cmock/vendor/unity/src/unity.h +1 -1
- data/vendor/cmock/vendor/unity/src/unity_internals.h +21 -7
- data/vendor/unity/README.md +77 -71
- data/vendor/unity/auto/generate_test_runner.rb +1 -1
- data/vendor/unity/docs/ThrowTheSwitchCodingStandard.md +107 -126
- data/vendor/unity/docs/UnityAssertionsReference.md +149 -193
- data/vendor/unity/docs/UnityConfigurationGuide.md +236 -294
- data/vendor/unity/docs/UnityGettingStartedGuide.md +112 -121
- data/vendor/unity/docs/UnityHelperScriptsGuide.md +82 -115
- data/vendor/unity/extras/fixture/readme.md +16 -19
- data/vendor/unity/extras/memory/readme.md +27 -34
- data/vendor/unity/src/unity.c +1 -1
- data/vendor/unity/src/unity.h +1 -1
- data/vendor/unity/src/unity_internals.h +21 -7
- metadata +14 -5
- data/plugins/gcov/config/defaults.yml +0 -55
@@ -2,133 +2,118 @@
|
|
2
2
|
|
3
3
|
## C Standards, Compilers and Microcontrollers
|
4
4
|
|
5
|
-
The embedded software world contains its challenges.
|
6
|
-
revisions of the C Standard.
|
7
|
-
make the language more usable in some special regard.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
described in this document.
|
16
|
-
|
17
|
-
All of Unity's configuration options are `#defines`.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
provide a more consistent and simple experience elsewhere.
|
24
|
-
|
5
|
+
The embedded software world contains its challenges.
|
6
|
+
Compilers support different revisions of the C Standard.
|
7
|
+
They ignore requirements in places, sometimes to make the language more usable in some special regard.
|
8
|
+
Sometimes it's to simplify their support.
|
9
|
+
Sometimes it's due to specific quirks of the microcontroller they are targeting.
|
10
|
+
Simulators add another dimension to this menagerie.
|
11
|
+
|
12
|
+
Unity is designed to run on almost anything that is targeted by a C compiler.
|
13
|
+
It would be awesome if this could be done with zero configuration.
|
14
|
+
While there are some targets that come close to this dream, it is sadly not universal.
|
15
|
+
It is likely that you are going to need at least a couple of the configuration options described in this document.
|
16
|
+
|
17
|
+
All of Unity's configuration options are `#defines`.
|
18
|
+
Most of these are simple definitions.
|
19
|
+
A couple are macros with arguments.
|
20
|
+
They live inside the unity_internals.h header file.
|
21
|
+
We don't necessarily recommend opening that file unless you really need to.
|
22
|
+
That file is proof that a cross-platform library is challenging to build.
|
23
|
+
From a more positive perspective, it is also proof that a great deal of complexity can be centralized primarily to one place to provide a more consistent and simple experience elsewhere.
|
25
24
|
|
26
25
|
### Using These Options
|
27
26
|
|
28
|
-
It doesn't matter if you're using a target-specific compiler and a simulator or
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
defines
|
37
|
-
|
38
|
-
toolchain's search paths). In this file, you will list definitions and macros
|
39
|
-
specific to your target. All you must do is define `UNITY_INCLUDE_CONFIG_H` and
|
40
|
-
Unity will rely on `unity_config.h` for any further definitions it may need.
|
41
|
-
|
42
|
-
Unfortunately, it doesn't usually work well to just #define these things in the
|
43
|
-
test itself. These defines need to take effect where ever unity.h is included.
|
44
|
-
This would be test test, the test runner (if you're generating one), and from
|
45
|
-
unity.c when it's compiled.
|
27
|
+
It doesn't matter if you're using a target-specific compiler and a simulator or a native compiler.
|
28
|
+
In either case, you've got a couple choices for configuring these options:
|
29
|
+
|
30
|
+
1. Because these options are specified via C defines, you can pass most of these options to your compiler through command line compiler flags. Even if you're using an embedded target that forces you to use their overbearing IDE for all configuration, there will be a place somewhere in your project to configure defines for your compiler.
|
31
|
+
2. You can create a custom `unity_config.h` configuration file (present in your toolchain's search paths).
|
32
|
+
In this file, you will list definitions and macros specific to your target. All you must do is define `UNITY_INCLUDE_CONFIG_H` and Unity will rely on `unity_config.h` for any further definitions it may need.
|
33
|
+
|
34
|
+
Unfortunately, it doesn't usually work well to just #define these things in the test itself.
|
35
|
+
These defines need to take effect where ever unity.h is included.
|
36
|
+
This would be test test, the test runner (if you're generating one), and from unity.c when it's compiled.
|
46
37
|
|
47
38
|
## The Options
|
48
39
|
|
49
40
|
### Integer Types
|
50
41
|
|
51
|
-
If you've been a C developer for long, you probably already know that C's
|
52
|
-
|
53
|
-
about the `int`
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
number of features for helping to adjust itself to match your required integer
|
59
|
-
sizes. It starts off by trying to do it automatically.
|
60
|
-
|
42
|
+
If you've been a C developer for long, you probably already know that C's concept of an integer varies from target to target.
|
43
|
+
The C Standard has rules about the `int` matching the register size of the target microprocessor.
|
44
|
+
It has rules about the `int` and how its size relates to other integer types.
|
45
|
+
An `int` on one target might be 16 bits while on another target it might be 64.
|
46
|
+
There are more specific types in compilers compliant with C99 or later, but that's certainly not every compiler you are likely to encounter.
|
47
|
+
Therefore, Unity has a number of features for helping to adjust itself to match your required integer sizes.
|
48
|
+
It starts off by trying to do it automatically.
|
61
49
|
|
62
|
-
|
50
|
+
#### `UNITY_EXCLUDE_STDINT_H`
|
63
51
|
|
64
52
|
The first thing that Unity does to guess your types is check `stdint.h`.
|
65
|
-
This file includes defines like `UINT_MAX` that Unity can use to
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
That way, Unity will know to skip the inclusion of this file and you won't
|
70
|
-
be left with a compiler error.
|
53
|
+
This file includes defines like `UINT_MAX` that Unity can use to learn a lot about your system.
|
54
|
+
It's possible you don't want it to do this (um. why not?) or (more likely) it's possible that your system doesn't support `stdint.h`.
|
55
|
+
If that's the case, you're going to want to define this.
|
56
|
+
That way, Unity will know to skip the inclusion of this file and you won't be left with a compiler error.
|
71
57
|
|
72
58
|
_Example:_
|
59
|
+
|
73
60
|
```C
|
74
61
|
#define UNITY_EXCLUDE_STDINT_H
|
75
62
|
```
|
76
63
|
|
64
|
+
#### `UNITY_EXCLUDE_LIMITS_H`
|
77
65
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
that don't support `stdint.h` could include `limits.h` instead. If you don't
|
82
|
-
want Unity to check this file either, define this to make it skip the inclusion.
|
66
|
+
The second attempt to guess your types is to check `limits.h`.
|
67
|
+
Some compilers that don't support `stdint.h` could include `limits.h` instead.
|
68
|
+
If you don't want Unity to check this file either, define this to make it skip the inclusion.
|
83
69
|
|
84
70
|
_Example:_
|
71
|
+
|
85
72
|
```C
|
86
73
|
#define UNITY_EXCLUDE_LIMITS_H
|
87
74
|
```
|
88
75
|
|
89
|
-
If you've disabled both of the automatic options above, you're going to have to
|
90
|
-
|
91
|
-
just a handful of defines that you are going to specify if you don't like the
|
92
|
-
defaults.
|
76
|
+
If you've disabled both of the automatic options above, you're going to have to do the configuration yourself.
|
77
|
+
Don't worry.
|
78
|
+
Even this isn't too bad... there are just a handful of defines that you are going to specify if you don't like the defaults.
|
93
79
|
|
80
|
+
#### `UNITY_INT_WIDTH`
|
94
81
|
|
95
|
-
|
96
|
-
|
97
|
-
Define this to be the number of bits an `int` takes up on your system. The
|
98
|
-
default, if not autodetected, is 32 bits.
|
82
|
+
Define this to be the number of bits an `int` takes up on your system.
|
83
|
+
The default, if not autodetected, is 32 bits.
|
99
84
|
|
100
85
|
_Example:_
|
86
|
+
|
101
87
|
```C
|
102
88
|
#define UNITY_INT_WIDTH 16
|
103
89
|
```
|
104
90
|
|
91
|
+
#### `UNITY_LONG_WIDTH`
|
105
92
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
`long long` to get a 64-bit value. On 16-bit systems, this option is going to be
|
112
|
-
ignored.
|
93
|
+
Define this to be the number of bits a `long` takes up on your system.
|
94
|
+
The default, if not autodetected, is 32 bits.
|
95
|
+
This is used to figure out what kind of 64-bit support your system can handle.
|
96
|
+
Does it need to specify a `long` or a `long long` to get a 64-bit value.
|
97
|
+
On 16-bit systems, this option is going to be ignored.
|
113
98
|
|
114
99
|
_Example:_
|
100
|
+
|
115
101
|
```C
|
116
102
|
#define UNITY_LONG_WIDTH 16
|
117
103
|
```
|
118
104
|
|
105
|
+
#### `UNITY_POINTER_WIDTH`
|
119
106
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
default, if not autodetected, is 32-bits. If you're getting ugly compiler
|
124
|
-
warnings about casting from pointers, this is the one to look at.
|
107
|
+
Define this to be the number of bits a pointer takes up on your system.
|
108
|
+
The default, if not autodetected, is 32-bits.
|
109
|
+
If you're getting ugly compiler warnings about casting from pointers, this is the one to look at.
|
125
110
|
|
126
|
-
_Hint:_ In order to support exotic processors (for example TI C55x with a pointer
|
127
|
-
width of 23-bit), choose the next power of two (in this case 32-bit).
|
111
|
+
_Hint:_ In order to support exotic processors (for example TI C55x with a pointer width of 23-bit), choose the next power of two (in this case 32-bit).
|
128
112
|
|
129
113
|
_Supported values:_ 16, 32 and 64
|
130
114
|
|
131
115
|
_Example:_
|
116
|
+
|
132
117
|
```C
|
133
118
|
// Choose on of these #defines to set your pointer width (if not autodetected)
|
134
119
|
//#define UNITY_POINTER_WIDTH 16
|
@@ -136,137 +121,117 @@ _Example:_
|
|
136
121
|
#define UNITY_POINTER_WIDTH 64 // Set UNITY_POINTER_WIDTH to 64-bit
|
137
122
|
```
|
138
123
|
|
124
|
+
#### `UNITY_SUPPORT_64`
|
139
125
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
your `int`, `long`, or pointer widths are greater than 32-bits. Define this to
|
144
|
-
enable 64-bit support if none of the other options already did it for you. There
|
145
|
-
can be a significant size and speed impact to enabling 64-bit support on small
|
146
|
-
targets, so don't define it if you don't need it.
|
126
|
+
Unity will automatically include 64-bit support if it auto-detects it, or if your `int`, `long`, or pointer widths are greater than 32-bits.
|
127
|
+
Define this to enable 64-bit support if none of the other options already did it for you.
|
128
|
+
There can be a significant size and speed impact to enabling 64-bit support on small targets, so don't define it if you don't need it.
|
147
129
|
|
148
130
|
_Example:_
|
131
|
+
|
149
132
|
```C
|
150
133
|
#define UNITY_SUPPORT_64
|
151
134
|
```
|
152
135
|
|
153
|
-
|
154
136
|
### Floating Point Types
|
155
137
|
|
156
|
-
In the embedded world, it's not uncommon for targets to have no support for
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
sometimes not available at all. Trying to include `float.h` on these platforms
|
161
|
-
would result in an error. This leaves manual configuration as the only option.
|
138
|
+
In the embedded world, it's not uncommon for targets to have no support for floating point operations at all or to have support that is limited to only single precision.
|
139
|
+
We are able to guess integer sizes on the fly because integers are always available in at least one size.
|
140
|
+
Floating point, on the other hand, is sometimes not available at all.
|
141
|
+
Trying to include `float.h` on these platforms would result in an error. This leaves manual configuration as the only option.
|
162
142
|
|
143
|
+
#### `UNITY_INCLUDE_FLOAT`
|
163
144
|
|
164
|
-
|
145
|
+
#### `UNITY_EXCLUDE_FLOAT`
|
165
146
|
|
166
|
-
|
147
|
+
#### `UNITY_INCLUDE_DOUBLE`
|
167
148
|
|
168
|
-
|
149
|
+
#### `UNITY_EXCLUDE_DOUBLE`
|
169
150
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
include and exclude options here. You may include neither, either, or both, as
|
175
|
-
suits your needs. For features that are enabled, the following floating point
|
176
|
-
options also become available.
|
151
|
+
By default, Unity guesses that you will want single precision floating point support, but not double precision.
|
152
|
+
It's easy to change either of these using the include and exclude options here.
|
153
|
+
You may include neither, either, or both, as suits your needs.
|
154
|
+
For features that are enabled, the following floating point options also become available.
|
177
155
|
|
178
156
|
_Example:_
|
157
|
+
|
179
158
|
```C
|
180
159
|
//what manner of strange processor is this?
|
181
160
|
#define UNITY_EXCLUDE_FLOAT
|
182
161
|
#define UNITY_INCLUDE_DOUBLE
|
183
162
|
```
|
184
163
|
|
164
|
+
#### `UNITY_EXCLUDE_FLOAT_PRINT`
|
185
165
|
|
186
|
-
|
187
|
-
|
188
|
-
Unity aims for as small of a footprint as possible and avoids most standard
|
189
|
-
library calls (some embedded platforms don’t have a standard library!). Because
|
190
|
-
of this, its routines for printing integer values are minimalist and hand-coded.
|
166
|
+
Unity aims for as small of a footprint as possible and avoids most standard library calls (some embedded platforms don’t have a standard library!).
|
167
|
+
Because of this, its routines for printing integer values are minimalist and hand-coded.
|
191
168
|
Therefore, the display of floating point values during a failure are optional.
|
192
|
-
By default, Unity will print the actual results of floating point assertion
|
193
|
-
|
194
|
-
|
195
|
-
”Values Not Within Delta”. If you would like verbose failure messages for floating
|
196
|
-
point assertions, use these options to give more explicit failure messages.
|
169
|
+
By default, Unity will print the actual results of floating point assertion failure (e.g. ”Expected 4.56 Was 4.68”).
|
170
|
+
To not include this extra support, you can use this define to instead respond to a failed assertion with a message like ”Values Not Within Delta”.
|
171
|
+
If you would like verbose failure messages for floating point assertions, use these options to give more explicit failure messages.
|
197
172
|
|
198
173
|
_Example:_
|
174
|
+
|
199
175
|
```C
|
200
176
|
#define UNITY_EXCLUDE_FLOAT_PRINT
|
201
177
|
```
|
202
178
|
|
179
|
+
#### `UNITY_FLOAT_TYPE`
|
203
180
|
|
204
|
-
|
205
|
-
|
206
|
-
If enabled, Unity assumes you want your `FLOAT` asserts to compare standard C
|
207
|
-
floats. If your compiler supports a specialty floating point type, you can
|
208
|
-
always override this behavior by using this definition.
|
181
|
+
If enabled, Unity assumes you want your `FLOAT` asserts to compare standard C floats.
|
182
|
+
If your compiler supports a specialty floating point type, you can always override this behavior by using this definition.
|
209
183
|
|
210
184
|
_Example:_
|
185
|
+
|
211
186
|
```C
|
212
187
|
#define UNITY_FLOAT_TYPE float16_t
|
213
188
|
```
|
214
189
|
|
190
|
+
#### `UNITY_DOUBLE_TYPE`
|
215
191
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
doubles. If you would like to change this, you can specify something else by
|
220
|
-
using this option. For example, defining `UNITY_DOUBLE_TYPE` to `long double`
|
221
|
-
could enable gargantuan floating point types on your 64-bit processor instead of
|
222
|
-
the standard `double`.
|
192
|
+
If enabled, Unity assumes you want your `DOUBLE` asserts to compare standard C doubles.
|
193
|
+
If you would like to change this, you can specify something else by using this option.
|
194
|
+
For example, defining `UNITY_DOUBLE_TYPE` to `long double` could enable gargantuan floating point types on your 64-bit processor instead of the standard `double`.
|
223
195
|
|
224
196
|
_Example:_
|
197
|
+
|
225
198
|
```C
|
226
199
|
#define UNITY_DOUBLE_TYPE long double
|
227
200
|
```
|
228
201
|
|
202
|
+
#### `UNITY_FLOAT_PRECISION`
|
229
203
|
|
230
|
-
|
231
|
-
|
232
|
-
##### `UNITY_DOUBLE_PRECISION`
|
204
|
+
#### `UNITY_DOUBLE_PRECISION`
|
233
205
|
|
234
|
-
If you look up `UNITY_ASSERT_EQUAL_FLOAT` and `UNITY_ASSERT_EQUAL_DOUBLE` as
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
options. They are both set to give you approximately 1 significant bit in either
|
241
|
-
direction. The float precision is 0.00001 while the double is 10-12.
|
242
|
-
For further details on how this works, see the appendix of the Unity Assertion
|
243
|
-
Guide.
|
206
|
+
If you look up `UNITY_ASSERT_EQUAL_FLOAT` and `UNITY_ASSERT_EQUAL_DOUBLE` as documented in the big daddy Unity Assertion Guide, you will learn that they are not really asserting that two values are equal but rather that two values are "close enough" to equal.
|
207
|
+
"Close enough" is controlled by these precision configuration options.
|
208
|
+
If you are working with 32-bit floats and/or 64-bit doubles (the normal on most processors), you should have no need to change these options.
|
209
|
+
They are both set to give you approximately 1 significant bit in either direction.
|
210
|
+
The float precision is 0.00001 while the double is 10-12.
|
211
|
+
For further details on how this works, see the appendix of the Unity Assertion Guide.
|
244
212
|
|
245
213
|
_Example:_
|
214
|
+
|
246
215
|
```C
|
247
216
|
#define UNITY_FLOAT_PRECISION 0.001f
|
248
217
|
```
|
249
218
|
|
250
|
-
|
251
219
|
### Miscellaneous
|
252
220
|
|
253
|
-
|
221
|
+
#### `UNITY_EXCLUDE_STDDEF_H`
|
254
222
|
|
255
|
-
Unity uses the `NULL` macro, which defines the value of a null pointer constant,
|
256
|
-
|
257
|
-
your own macro for this, you should exclude the `stddef.h` header file by adding this
|
258
|
-
define to your configuration.
|
223
|
+
Unity uses the `NULL` macro, which defines the value of a null pointer constant, defined in `stddef.h` by default.
|
224
|
+
If you want to provide your own macro for this, you should exclude the `stddef.h` header file by adding this define to your configuration.
|
259
225
|
|
260
226
|
_Example:_
|
227
|
+
|
261
228
|
```C
|
262
229
|
#define UNITY_EXCLUDE_STDDEF_H
|
263
230
|
```
|
264
231
|
|
265
|
-
|
266
232
|
#### `UNITY_INCLUDE_PRINT_FORMATTED`
|
267
233
|
|
268
|
-
Unity provides a simple (and very basic) printf-like string output implementation,
|
269
|
-
which is able to print a string modified by the following format string modifiers:
|
234
|
+
Unity provides a simple (and very basic) printf-like string output implementation, which is able to print a string modified by the following format string modifiers:
|
270
235
|
|
271
236
|
- __%d__ - signed value (decimal)
|
272
237
|
- __%i__ - same as __%i__
|
@@ -282,6 +247,7 @@ which is able to print a string modified by the following format string modifier
|
|
282
247
|
- __%%__ - The "%" symbol (escaped)
|
283
248
|
|
284
249
|
_Example:_
|
250
|
+
|
285
251
|
```C
|
286
252
|
#define UNITY_INCLUDE_PRINT_FORMATTED
|
287
253
|
|
@@ -300,39 +266,32 @@ TEST_PRINTF("\n");
|
|
300
266
|
TEST_PRINTF("Multiple (%d) (%i) (%u) (%x)\n", -100, 0, 200, 0x12345);
|
301
267
|
```
|
302
268
|
|
303
|
-
|
304
269
|
### Toolset Customization
|
305
270
|
|
306
|
-
In addition to the options listed above, there are a number of other options
|
307
|
-
|
308
|
-
|
309
|
-
certain platforms, particularly those running in simulators, may need to jump
|
310
|
-
through extra hoops to run properly. These macros will help in those
|
311
|
-
situations.
|
312
|
-
|
271
|
+
In addition to the options listed above, there are a number of other options which will come in handy to customize Unity's behavior for your specific toolchain.
|
272
|
+
It is possible that you may not need to touch any of these... but certain platforms, particularly those running in simulators, may need to jump through extra hoops to run properly.
|
273
|
+
These macros will help in those situations.
|
313
274
|
|
314
|
-
|
275
|
+
#### `UNITY_OUTPUT_CHAR(a)`
|
315
276
|
|
316
|
-
|
277
|
+
#### `UNITY_OUTPUT_FLUSH()`
|
317
278
|
|
318
|
-
|
279
|
+
#### `UNITY_OUTPUT_START()`
|
319
280
|
|
320
|
-
|
281
|
+
#### `UNITY_OUTPUT_COMPLETE()`
|
321
282
|
|
322
|
-
By default, Unity prints its results to `stdout` as it runs.
|
323
|
-
perfectly fine in most situations where you are using a native compiler for
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
an `int`, since this is the parameter type of the standard C `putchar` function
|
330
|
-
most commonly used). You may replace this with whatever function call you like.
|
283
|
+
By default, Unity prints its results to `stdout` as it runs.
|
284
|
+
This works perfectly fine in most situations where you are using a native compiler for testing.
|
285
|
+
It works on some simulators as well so long as they have `stdout` routed back to the command line.
|
286
|
+
There are times, however, where the simulator will lack support for dumping results or you will want to route results elsewhere for other reasons.
|
287
|
+
In these cases, you should define the `UNITY_OUTPUT_CHAR` macro.
|
288
|
+
This macro accepts a single character at a time (as an `int`, since this is the parameter type of the standard C `putchar` function most commonly used).
|
289
|
+
You may replace this with whatever function call you like.
|
331
290
|
|
332
291
|
_Example:_
|
333
|
-
Say you are forced to run your test suite on an embedded processor with no
|
334
|
-
|
335
|
-
|
292
|
+
Say you are forced to run your test suite on an embedded processor with no `stdout` option.
|
293
|
+
You decide to route your test result output to a custom serial `RS232_putc()` function you wrote like thus:
|
294
|
+
|
336
295
|
```C
|
337
296
|
#include "RS232_header.h"
|
338
297
|
...
|
@@ -343,67 +302,63 @@ Say you are forced to run your test suite on an embedded processor with no
|
|
343
302
|
```
|
344
303
|
|
345
304
|
_Note:_
|
346
|
-
`UNITY_OUTPUT_FLUSH()` can be set to the standard out flush function simply by
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
##### `UNITY_OUTPUT_FOR_ECLIPSE`
|
305
|
+
`UNITY_OUTPUT_FLUSH()` can be set to the standard out flush function simply by specifying `UNITY_USE_FLUSH_STDOUT`.
|
306
|
+
No other defines are required.
|
351
307
|
|
352
|
-
|
308
|
+
#### `UNITY_OUTPUT_FOR_ECLIPSE`
|
353
309
|
|
354
|
-
|
310
|
+
#### `UNITY_OUTPUT_FOR_IAR_WORKBENCH`
|
355
311
|
|
356
|
-
|
357
|
-
recognized by your IDE. These are some standard formats which can be supported. If you're using
|
358
|
-
Ceedling to manage your builds, it is better to stick with the standard format (leaving these
|
359
|
-
all undefined) and allow Ceedling to use its own decorators.
|
312
|
+
#### `UNITY_OUTPUT_FOR_QT_CREATOR`
|
360
313
|
|
314
|
+
When managing your own builds, it is often handy to have messages output in a format which is recognized by your IDE.
|
315
|
+
These are some standard formats which can be supported.
|
316
|
+
If you're using Ceedling to manage your builds, it is better to stick with the standard format (leaving these all undefined) and allow Ceedling to use its own decorators.
|
361
317
|
|
362
|
-
|
318
|
+
#### `UNITY_PTR_ATTRIBUTE`
|
363
319
|
|
364
|
-
Some compilers require a custom attribute to be assigned to pointers, like
|
365
|
-
|
366
|
-
defining this option with the attribute you would like.
|
320
|
+
Some compilers require a custom attribute to be assigned to pointers, like `near` or `far`.
|
321
|
+
In these cases, you can give Unity a safe default for these by defining this option with the attribute you would like.
|
367
322
|
|
368
323
|
_Example:_
|
324
|
+
|
369
325
|
```C
|
370
326
|
#define UNITY_PTR_ATTRIBUTE __attribute__((far))
|
371
327
|
#define UNITY_PTR_ATTRIBUTE near
|
372
328
|
```
|
373
329
|
|
374
|
-
|
330
|
+
#### `UNITY_PRINT_EOL`
|
375
331
|
|
376
|
-
By default, Unity outputs \n at the end of each line of output.
|
377
|
-
to parse by the scripts, by Ceedling, etc, but it might not be ideal for YOUR
|
378
|
-
|
332
|
+
By default, Unity outputs \n at the end of each line of output.
|
333
|
+
This is easy to parse by the scripts, by Ceedling, etc, but it might not be ideal for YOUR system.
|
334
|
+
Feel free to override this and to make it whatever you wish.
|
379
335
|
|
380
336
|
_Example:_
|
337
|
+
|
381
338
|
```C
|
382
|
-
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\r'); UNITY_OUTPUT_CHAR('\n') }
|
339
|
+
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\r'); UNITY_OUTPUT_CHAR('\n'); }
|
383
340
|
```
|
384
341
|
|
342
|
+
#### `UNITY_EXCLUDE_DETAILS`
|
385
343
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
extra detail information around. It's used by systems like CMock in order to
|
391
|
-
report which function or argument flagged an error. If you're not using CMock and
|
392
|
-
you're not using these details for other things, then you can exclude them.
|
344
|
+
This is an option for if you absolutely must squeeze every byte of memory out of your system.
|
345
|
+
Unity stores a set of internal scratchpads which are used to pass extra detail information around.
|
346
|
+
It's used by systems like CMock in order to report which function or argument flagged an error.
|
347
|
+
If you're not using CMock and you're not using these details for other things, then you can exclude them.
|
393
348
|
|
394
349
|
_Example:_
|
350
|
+
|
395
351
|
```C
|
396
352
|
#define UNITY_EXCLUDE_DETAILS
|
397
353
|
```
|
398
354
|
|
399
|
-
|
355
|
+
#### `UNITY_PRINT_TEST_CONTEXT`
|
400
356
|
|
401
|
-
This option allows you to specify your own function to print additional context
|
402
|
-
|
403
|
-
want to output some specific information about the state of the test at the point
|
404
|
-
of failure, and `UNITY_SET_DETAILS` isn't flexible enough for your needs.
|
357
|
+
This option allows you to specify your own function to print additional context as part of the error message when a test has failed.
|
358
|
+
It can be useful if you want to output some specific information about the state of the test at the point of failure, and `UNITY_SET_DETAILS` isn't flexible enough for your needs.
|
405
359
|
|
406
360
|
_Example:_
|
361
|
+
|
407
362
|
```C
|
408
363
|
#define UNITY_PRINT_TEST_CONTEXT PrintIterationCount
|
409
364
|
|
@@ -415,82 +370,74 @@ void PrintIterationCount(void)
|
|
415
370
|
}
|
416
371
|
```
|
417
372
|
|
418
|
-
|
373
|
+
#### `UNITY_EXCLUDE_SETJMP`
|
419
374
|
|
420
|
-
If your embedded system doesn't support the standard library setjmp, you can
|
421
|
-
|
422
|
-
|
423
|
-
your
|
424
|
-
compiler doesn't support setjmp, you wouldn't have had the memory space for those
|
425
|
-
things anyway, though... so this option exists for those situations.
|
375
|
+
If your embedded system doesn't support the standard library setjmp, you can exclude Unity's reliance on this by using this define.
|
376
|
+
This dropped dependence comes at a price, though.
|
377
|
+
You will be unable to use custom helper functions for your tests, and you will be unable to use tools like CMock.
|
378
|
+
Very likely, if your compiler doesn't support setjmp, you wouldn't have had the memory space for those things anyway, though... so this option exists for those situations.
|
426
379
|
|
427
380
|
_Example:_
|
381
|
+
|
428
382
|
```C
|
429
383
|
#define UNITY_EXCLUDE_SETJMP
|
430
384
|
```
|
431
385
|
|
432
|
-
|
386
|
+
#### `UNITY_OUTPUT_COLOR`
|
433
387
|
|
434
388
|
If you want to add color using ANSI escape codes you can use this define.
|
435
389
|
|
436
390
|
_Example:_
|
391
|
+
|
437
392
|
```C
|
438
393
|
#define UNITY_OUTPUT_COLOR
|
439
394
|
```
|
440
395
|
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
`
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
insisting that developers choose a more descriptive option.
|
396
|
+
#### `UNITY_SHORTHAND_AS_INT`
|
397
|
+
|
398
|
+
#### `UNITY_SHORTHAND_AS_MEM`
|
399
|
+
|
400
|
+
#### `UNITY_SHORTHAND_AS_RAW`
|
401
|
+
|
402
|
+
#### `UNITY_SHORTHAND_AS_NONE`
|
403
|
+
|
404
|
+
These options give you control of the `TEST_ASSERT_EQUAL` and the `TEST_ASSERT_NOT_EQUAL` shorthand assertions.
|
405
|
+
Historically, Unity treated the former as an alias for an integer comparison.
|
406
|
+
It treated the latter as a direct comparison using `!=`.
|
407
|
+
This asymmetry was confusing, but there was much disagreement as to how best to treat this pair of assertions.
|
408
|
+
These four options will allow you to specify how Unity will treat these assertions.
|
409
|
+
|
410
|
+
- AS INT - the values will be cast to integers and directly compared.
|
411
|
+
Arguments that don't cast easily to integers will cause compiler errors.
|
412
|
+
- AS MEM - the address of both values will be taken and the entire object's memory footprint will be compared byte by byte.
|
413
|
+
Directly placing constant numbers like `456` as expected values will cause errors.
|
414
|
+
- AS_RAW - Unity assumes that you can compare the two values using `==` and `!=` and will do so.
|
415
|
+
No details are given about mismatches, because it doesn't really know what type it's dealing with.
|
416
|
+
- AS_NONE - Unity will disallow the use of these shorthand macros altogether, insisting that developers choose a more descriptive option.
|
463
417
|
|
464
418
|
#### `UNITY_SUPPORT_VARIADIC_MACROS`
|
465
419
|
|
466
|
-
This will force Unity to support variadic macros when using its own built-in
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
C89 (ANSI), defining this option will allow you to use them. This option is also not
|
471
|
-
necessary when using Ceedling or the test runner generator script.
|
420
|
+
This will force Unity to support variadic macros when using its own built-in RUN_TEST macro.
|
421
|
+
This will rarely be necessary. Most often, Unity will automatically detect if the compiler supports variadic macros by checking to see if it's C99+ compatible.
|
422
|
+
In the event that the compiler supports variadic macros, but is primarily C89 (ANSI), defining this option will allow you to use them.
|
423
|
+
This option is also not necessary when using Ceedling or the test runner generator script.
|
472
424
|
|
473
425
|
## Getting Into The Guts
|
474
426
|
|
475
|
-
There will be cases where the options above aren't quite going to get everything
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
places: the `main()` function or the `RUN_TEST` macro. Let's look at how these
|
483
|
-
work.
|
427
|
+
There will be cases where the options above aren't quite going to get everything perfect.
|
428
|
+
They are likely sufficient for any situation where you are compiling and executing your tests with a native toolchain (e.g. clang on Mac).
|
429
|
+
These options may even get you through the majority of cases encountered in working with a target simulator run from your local command line.
|
430
|
+
But especially if you must run your test suite on your target hardware, your Unity configuration will
|
431
|
+
require special help.
|
432
|
+
This special help will usually reside in one of two places: the `main()` function or the `RUN_TEST` macro.
|
433
|
+
Let's look at how these work.
|
484
434
|
|
435
|
+
### `main()`
|
485
436
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
`main` function will need to contain whatever code is necessary to initialize
|
491
|
-
your system to a workable state. This is particularly true for situations where
|
492
|
-
you must set up a memory map or initialize a communication channel for the
|
493
|
-
output of your test results.
|
437
|
+
Each test module is compiled and run on its own, separate from the other test files in your project.
|
438
|
+
Each test file, therefore, has a `main` function.
|
439
|
+
This `main` function will need to contain whatever code is necessary to initialize your system to a workable state.
|
440
|
+
This is particularly true for situations where you must set up a memory map or initialize a communication channel for the output of your test results.
|
494
441
|
|
495
442
|
A simple main function looks something like this:
|
496
443
|
|
@@ -504,26 +451,22 @@ int main(void) {
|
|
504
451
|
}
|
505
452
|
```
|
506
453
|
|
507
|
-
You can see that our main function doesn't bother taking any arguments.
|
508
|
-
most barebones case, we'll never have arguments because we just run all the
|
509
|
-
|
510
|
-
(in whatever order we wish).
|
511
|
-
value (which is the total number of failures).
|
512
|
-
|
513
|
-
It should be easy to see that you can add code before any test cases are run or
|
514
|
-
after all the test cases have completed. This allows you to do any needed
|
515
|
-
system-wide setup or teardown that might be required for your special
|
516
|
-
circumstances.
|
454
|
+
You can see that our main function doesn't bother taking any arguments.
|
455
|
+
For our most barebones case, we'll never have arguments because we just run all the tests each time.
|
456
|
+
Instead, we start by calling `UNITY_BEGIN`.
|
457
|
+
We run each test (in whatever order we wish).
|
458
|
+
Finally, we call `UNITY_END`, returning its return value (which is the total number of failures).
|
517
459
|
|
460
|
+
It should be easy to see that you can add code before any test cases are run or after all the test cases have completed.
|
461
|
+
This allows you to do any needed system-wide setup or teardown that might be required for your special circumstances.
|
518
462
|
|
519
|
-
|
463
|
+
#### `RUN_TEST`
|
520
464
|
|
521
|
-
The `RUN_TEST` macro is called with each test case function.
|
522
|
-
perform whatever setup and teardown is necessary for executing a single test
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
simple minimalist RUN_TEST macro looks something like this:
|
465
|
+
The `RUN_TEST` macro is called with each test case function.
|
466
|
+
Its job is to perform whatever setup and teardown is necessary for executing a single test case function.
|
467
|
+
This includes catching failures, calling the test module's `setUp()` and `tearDown()` functions, and calling `UnityConcludeTest()`.
|
468
|
+
If using CMock or test coverage, there will be additional stubs in use here.
|
469
|
+
A simple minimalist RUN_TEST macro looks something like this:
|
527
470
|
|
528
471
|
```C
|
529
472
|
#define RUN_TEST(testfunc) \
|
@@ -537,27 +480,26 @@ simple minimalist RUN_TEST macro looks something like this:
|
|
537
480
|
UnityConcludeTest();
|
538
481
|
```
|
539
482
|
|
540
|
-
So that's quite a macro, huh?
|
541
|
-
has to deal with for every single test case.
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
test before moving on to the next.
|
547
|
-
|
548
|
-
Let's say you need to add a call to `fsync` to force all of your output data to
|
549
|
-
flush to a file after each test. You could easily insert this after your
|
550
|
-
`UnityConcludeTest` call. Maybe you want to write an xml tag before and after
|
551
|
-
each result set. Again, you could do this by adding lines to this macro. Updates
|
552
|
-
to this macro are for the occasions when you need an action before or after
|
553
|
-
every single test case throughout your entire suite of tests.
|
483
|
+
So that's quite a macro, huh?
|
484
|
+
It gives you a glimpse of what kind of stuff Unity has to deal with for every single test case.
|
485
|
+
For each test case, we declare that it is a new test.
|
486
|
+
Then we run `setUp` and our test function.
|
487
|
+
These are run within a `TEST_PROTECT` block, the function of which is to handle failures that occur during the test.
|
488
|
+
Then, assuming our test is still running and hasn't been ignored, we run `tearDown`.
|
489
|
+
No matter what, our last step is to conclude this test before moving on to the next.
|
554
490
|
|
491
|
+
Let's say you need to add a call to `fsync` to force all of your output data to flush to a file after each test.
|
492
|
+
You could easily insert this after your `UnityConcludeTest` call.
|
493
|
+
Maybe you want to write an xml tag before and after each result set.
|
494
|
+
Again, you could do this by adding lines to this macro.
|
495
|
+
Updates to this macro are for the occasions when you need an action before or after every single test case throughout your entire suite of tests.
|
555
496
|
|
556
497
|
## Happy Porting
|
557
498
|
|
558
|
-
The defines and macros in this guide should help you port Unity to just about
|
559
|
-
|
560
|
-
|
499
|
+
The defines and macros in this guide should help you port Unity to just about any C target we can imagine.
|
500
|
+
If you run into a snag or two, don't be afraid of asking for help on the forums.
|
501
|
+
We love a good challenge!
|
561
502
|
|
503
|
+
*Find The Latest of This And More at [ThrowTheSwitch.org][]*
|
562
504
|
|
563
|
-
|
505
|
+
[ThrowTheSwitch.org]: https://throwtheswitch.org
|