Skip to content

Commit 16b26fe

Browse files
committed
Merge tag 'v2.4.3'
2 parents d5ce931 + 287e076 commit 16b26fe

16 files changed

Lines changed: 936 additions & 88 deletions

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ install:
1818
script:
1919
- cd test && rake ci
2020
- make -s
21-
- make -s DEBUG=-m32
21+
- make -s DEBUG=-m32 #32-bit architecture with 64-bit support
22+
- make -s DEBUG=-m32 UNITY_SUPPORT_64= #32-bit build without 64-bit types
23+
- make -s UNITY_INCLUDE_DOUBLE= # without double
2224
- cd ../extras/fixture/test && rake ci
2325
- make -s default noStdlibMalloc
2426
- make -s C89

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ Another way of calling TEST_ASSERT_EQUAL_INT
118118
Asserts that the actual value is within plus or minus delta of the expected value. This also comes in
119119
size specific variants.
120120

121+
122+
TEST_ASSERT_GREATER_THAN(threshold, actual)
123+
124+
Asserts that the actual value is greater than the threshold. This also comes in size specific variants.
125+
126+
127+
TEST_ASSERT_LESS_THAN(threshold, actual)
128+
129+
Asserts that the actual value is less than the threshold. This also comes in size specific variants.
130+
131+
121132
Arrays
122133
------
123134

auto/colour_prompt.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def initialize
2424
return unless RUBY_PLATFORM =~ /(win|w)32$/
2525
get_std_handle = Win32API.new('kernel32', 'GetStdHandle', ['L'], 'L')
2626
@set_console_txt_attrb =
27-
Win32API.new('kernel32', 'SetConsoleTextAttribute', %w[L N], 'I')
27+
Win32API.new('kernel32', 'SetConsoleTextAttribute', %w(L N), 'I')
2828
@hout = get_std_handle.call(-11)
2929
end
3030

auto/generate_test_runner.rb

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def find_tests(source)
119119
source_index = 0
120120
tests_and_line_numbers.size.times do |i|
121121
source_lines[source_index..-1].each_with_index do |line, index|
122-
next unless line =~ /#{tests_and_line_numbers[i][:test]}/
122+
next unless line =~ /\s+#{tests_and_line_numbers[i][:test]}(?:\s|\()/
123123
source_index += index
124124
tests_and_line_numbers[i][:line_number] = source_index + 1
125125
break
@@ -157,6 +157,9 @@ def create_header(output, mocks, testfile_includes = [])
157157
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
158158
create_runtest(output, mocks)
159159
output.puts("\n/*=======Automagically Detected Files To Include=====*/")
160+
output.puts('#ifdef __WIN32__')
161+
output.puts('#define UNITY_INCLUDE_SETUP_STUBS')
162+
output.puts('#endif')
160163
output.puts("#include \"#{@options[:framework]}.h\"")
161164
output.puts('#include "cmock.h"') unless mocks.empty?
162165
output.puts('#include <setjmp.h>')
@@ -235,22 +238,36 @@ def create_mock_management(output, mock_headers)
235238
end
236239

237240
def create_suite_setup(output)
238-
return if @options[:suite_setup].nil?
239-
240241
output.puts("\n/*=======Suite Setup=====*/")
241242
output.puts('static void suite_setup(void)')
242243
output.puts('{')
243-
output.puts(@options[:suite_setup])
244+
if @options[:suite_setup].nil?
245+
# New style, call suiteSetUp() if we can use weak symbols
246+
output.puts('#if defined(UNITY_WEAK_ATTRIBUTE) || defined(UNITY_WEAK_PRAGMA)')
247+
output.puts(' suiteSetUp();')
248+
output.puts('#endif')
249+
else
250+
# Old style, C code embedded in the :suite_setup option
251+
output.puts(@options[:suite_setup])
252+
end
244253
output.puts('}')
245254
end
246255

247256
def create_suite_teardown(output)
248-
return if @options[:suite_teardown].nil?
249-
250257
output.puts("\n/*=======Suite Teardown=====*/")
251258
output.puts('static int suite_teardown(int num_failures)')
252259
output.puts('{')
253-
output.puts(@options[:suite_teardown])
260+
if @options[:suite_teardown].nil?
261+
# New style, call suiteTearDown() if we can use weak symbols
262+
output.puts('#if defined(UNITY_WEAK_ATTRIBUTE) || defined(UNITY_WEAK_PRAGMA)')
263+
output.puts(' return suiteTearDown(num_failures);')
264+
output.puts('#else')
265+
output.puts(' return num_failures;')
266+
output.puts('#endif')
267+
else
268+
# Old style, C code embedded in the :suite_teardown option
269+
output.puts(@options[:suite_teardown])
270+
end
254271
output.puts('}')
255272
end
256273

@@ -342,7 +359,7 @@ def create_main(output, filename, tests, used_mocks)
342359
output.puts("int #{main_name}(void)")
343360
output.puts('{')
344361
end
345-
output.puts(' suite_setup();') unless @options[:suite_setup].nil?
362+
output.puts(' suite_setup();')
346363
output.puts(" UnityBegin(\"#{filename.gsub(/\\/, '\\\\\\')}\");")
347364
if @options[:use_param_tests]
348365
tests.each do |test|
@@ -357,7 +374,7 @@ def create_main(output, filename, tests, used_mocks)
357374
end
358375
output.puts
359376
output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty?
360-
output.puts(" return #{@options[:suite_teardown].nil? ? '' : 'suite_teardown'}(UnityEnd());")
377+
output.puts(" return suite_teardown(UnityEnd());")
361378
output.puts('}')
362379
end
363380

docs/UnityAssertionsReference.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,60 @@ Asserts the specified bit of the `actual` parameter is high.
290290

291291
Asserts the specified bit of the `actual` parameter is low.
292292

293+
### Integer Less Than / Greater Than
294+
295+
These assertions verify that the `actual` parameter is less than or greater
296+
than `threshold` (exclusive). For example, if the threshold value is 0 for the
297+
greater than assertion will fail if it is 0 or less.
298+
299+
##### `TEST_ASSERT_GREATER_THAN (threshold, actual)`
300+
301+
##### `TEST_ASSERT_GREATER_THAN_INT (threshold, actual)`
302+
303+
##### `TEST_ASSERT_GREATER_THAN_INT8 (threshold, actual)`
304+
305+
##### `TEST_ASSERT_GREATER_THAN_INT16 (threshold, actual)`
306+
307+
##### `TEST_ASSERT_GREATER_THAN_INT32 (threshold, actual)`
308+
309+
##### `TEST_ASSERT_GREATER_THAN_UINT (threshold, actual)`
310+
311+
##### `TEST_ASSERT_GREATER_THAN_UINT8 (threshold, actual)`
312+
313+
##### `TEST_ASSERT_GREATER_THAN_UINT16 (threshold, actual)`
314+
315+
##### `TEST_ASSERT_GREATER_THAN_UINT32 (threshold, actual)`
316+
317+
##### `TEST_ASSERT_GREATER_THAN_HEX8 (threshold, actual)`
318+
319+
##### `TEST_ASSERT_GREATER_THAN_HEX16 (threshold, actual)`
320+
321+
##### `TEST_ASSERT_GREATER_THAN_HEX32 (threshold, actual)`
322+
323+
##### `TEST_ASSERT_LESS_THAN (threshold, actual)`
324+
325+
##### `TEST_ASSERT_LESS_THAN_INT (threshold, actual)`
326+
327+
##### `TEST_ASSERT_LESS_THAN_INT8 (threshold, actual)`
328+
329+
##### `TEST_ASSERT_LESS_THAN_INT16 (threshold, actual)`
330+
331+
##### `TEST_ASSERT_LESS_THAN_INT32 (threshold, actual)`
332+
333+
##### `TEST_ASSERT_LESS_THAN_UINT (threshold, actual)`
334+
335+
##### `TEST_ASSERT_LESS_THAN_UINT8 (threshold, actual)`
336+
337+
##### `TEST_ASSERT_LESS_THAN_UINT16 (threshold, actual)`
338+
339+
##### `TEST_ASSERT_LESS_THAN_UINT32 (threshold, actual)`
340+
341+
##### `TEST_ASSERT_LESS_THAN_HEX8 (threshold, actual)`
342+
343+
##### `TEST_ASSERT_LESS_THAN_HEX16 (threshold, actual)`
344+
345+
##### `TEST_ASSERT_LESS_THAN_HEX32 (threshold, actual)`
346+
293347

294348
### Integer Ranges (of all sizes)
295349

docs/UnityConfigurationGuide.md

Lines changed: 80 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,7 @@ _Example:_
7979
#define UNITY_EXCLUDE_LIMITS_H
8080

8181

82-
##### `UNITY_EXCLUDE_SIZEOF`
83-
84-
The third and final attempt to guess your types is to use the `sizeof()`
85-
operator. Even if the first two options don't work, this one covers most cases.
86-
There _is_ a rare compiler or two out there that doesn't support sizeof() in the
87-
preprocessing stage, though. For these, you have the ability to disable this
88-
feature as well.
89-
90-
_Example:_
91-
#define UNITY_EXCLUDE_SIZEOF
92-
93-
If you've disabled all of the automatic options above, you're going to have to
82+
If you've disabled both of the automatic options above, you're going to have to
9483
do the configuration yourself. Don't worry. Even this isn't too bad... there are
9584
just a handful of defines that you are going to specify if you don't like the
9685
defaults.
@@ -127,7 +116,7 @@ _Example:_
127116
#define UNITY_POINTER_WIDTH 64
128117

129118

130-
##### `UNITY_INCLUDE_64`
119+
##### `UNITY_SUPPORT_64`
131120

132121
Unity will automatically include 64-bit support if it auto-detects it, or if
133122
your `int`, `long`, or pointer widths are greater than 32-bits. Define this to
@@ -136,7 +125,7 @@ can be a significant size and speed impact to enabling 64-bit support on small
136125
targets, so don't define it if you don't need it.
137126

138127
_Example:_
139-
#define UNITY_INCLUDE_64
128+
#define UNITY_SUPPORT_64
140129

141130

142131
### Floating Point Types
@@ -170,24 +159,20 @@ _Example:_
170159
#define UNITY_INCLUDE_DOUBLE
171160

172161

173-
##### `UNITY_FLOAT_VERBOSE`
174-
175-
##### `UNITY_DOUBLE_VERBOSE`
162+
##### `UNITY_EXCLUDE_FLOAT_PRINT`
176163

177164
Unity aims for as small of a footprint as possible and avoids most standard
178-
library calls (some embedded platforms don't have a standard library!). Because
165+
library calls (some embedded platforms dont have a standard library!). Because
179166
of this, its routines for printing integer values are minimalist and hand-coded.
180-
To keep Unity universal, though, we chose to _not_ develop our own floating
181-
point print routines. Instead, the display of floating point values during a
182-
failure are optional. By default, Unity will not print the actual results of
183-
floating point assertion failure. So a failed assertion will produce a message
184-
like `"Values Not Within Delta"`. If you would like verbose failure messages for
185-
floating point assertions, use these options to give more explicit failure
186-
messages (e.g. `"Expected 4.56 Was 4.68"`). Note that this feature requires the
187-
use of `sprintf` so might not be desirable in all cases.
167+
Therefore, the display of floating point values during a failure are optional.
168+
By default, Unity will print the actual results of floating point assertion
169+
failure (e.g. ”Expected 4.56 Was 4.68”). To not include this extra support, you
170+
can use this define to instead respond to a failed assertion with a message like
171+
”Values Not Within Delta”. If you would like verbose failure messages for floating
172+
point assertions, use these options to give more explicit failure messages.
188173

189174
_Example:_
190-
#define UNITY_DOUBLE_VERBOSE
175+
#define UNITY_EXCLUDE_FLOAT_PRINT
191176

192177

193178
##### `UNITY_FLOAT_TYPE`
@@ -277,25 +262,32 @@ will declare an instance of your function by default. If you want to disable
277262
this behavior, add `UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION`.
278263

279264

280-
##### `UNITY_SUPPORT_WEAK`
265+
##### `UNITY_WEAK_ATTRIBUTE`
266+
267+
##### `UNITY_WEAK_PRAGMA`
268+
269+
##### `UNITY_NO_WEAK`
281270

282-
For some targets, Unity can make the otherwise required `setUp()` and
283-
`tearDown()` functions optional. This is a nice convenience for test writers
284-
since `setUp` and `tearDown` don't often actually _do_ anything. If you're using
285-
gcc or clang, this option is automatically defined for you. Other compilers can
286-
also support this behavior, if they support a C feature called weak functions. A
287-
weak function is a function that is compiled into your executable _unless_ a
288-
non-weak version of the same function is defined elsewhere. If a non-weak
289-
version is found, the weak version is ignored as if it never existed. If your
290-
compiler supports this feature, you can let Unity know by defining
291-
`UNITY_SUPPORT_WEAK` as the function attributes that would need to be applied to
292-
identify a function as weak. If your compiler lacks support for weak functions,
293-
you will always need to define `setUp` and `tearDown` functions (though they can
294-
be and often will be just empty). The most common options for this feature are:
271+
For some targets, Unity can make the otherwise required setUp() and tearDown()
272+
functions optional. This is a nice convenience for test writers since setUp and
273+
tearDown don’t often actually do anything. If you’re using gcc or clang, this
274+
option is automatically defined for you. Other compilers can also support this
275+
behavior, if they support a C feature called weak functions. A weak function is
276+
a function that is compiled into your executable unless a non-weak version of
277+
the same function is defined elsewhere. If a non-weak version is found, the weak
278+
version is ignored as if it never existed. If your compiler supports this feature,
279+
you can let Unity know by defining UNITY_WEAK_ATTRIBUTE or UNITY_WEAK_PRAGMA as
280+
the function attributes that would need to be applied to identify a function as
281+
weak. If your compiler lacks support for weak functions, you will always need to
282+
define setUp and tearDown functions (though they can be and often will be just
283+
empty). You can also force Unity to NOT use weak functions by defining
284+
UNITY_NO_WEAK. The most common options for this feature are:
295285

296286
_Example:_
297-
#define UNITY_SUPPORT_WEAK weak
298-
#define UNITY_SUPPORT_WEAK __attribute__((weak))
287+
#define UNITY_WEAK_ATTRIBUTE weak
288+
#define UNITY_WEAK_ATTRIBUTE __attribute__((weak))
289+
#define UNITY_WEAK_PRAGMA
290+
#define UNITY_NO_WEAK
299291

300292

301293
##### `UNITY_PTR_ATTRIBUTE`
@@ -309,6 +301,51 @@ _Example:_
309301
#define UNITY_PTR_ATTRIBUTE near
310302

311303

304+
##### `UNITY_PRINT_EOL`
305+
306+
By default, Unity outputs \n at the end of each line of output. This is easy
307+
to parse by the scripts, by Ceedling, etc, but it might not be ideal for YOUR
308+
system. Feel free to override this and to make it whatever you wish.
309+
310+
_Example:_
311+
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\r'); UNITY_OUTPUT_CHAR('\n') }
312+
313+
314+
315+
##### `UNITY_EXCLUDE_DETAILS`
316+
317+
This is an option for if you absolutely must squeeze every byte of memory out of
318+
your system. Unity stores a set of internal scratchpads which are used to pass
319+
extra detail information around. It's used by systems like CMock in order to
320+
report which function or argument flagged an error. If you're not using CMock and
321+
you're not using these details for other things, then you can exclude them.
322+
323+
_Example:_
324+
#define UNITY_EXCLUDE_DETAILS
325+
326+
327+
328+
##### `UNITY_EXCLUDE_SETJMP`
329+
330+
If your embedded system doesn't support the standard library setjmp, you can
331+
exclude Unity's reliance on this by using this define. This dropped dependence
332+
comes at a price, though. You will be unable to use custom helper functions for
333+
your tests, and you will be unable to use tools like CMock. Very likely, if your
334+
compiler doesn't support setjmp, you wouldn't have had the memory space for those
335+
things anyway, though... so this option exists for those situations.
336+
337+
_Example:_
338+
#define UNITY_EXCLUDE_SETJMP
339+
340+
##### `UNITY_OUTPUT_COLOR`
341+
342+
If you want to add color using ANSI escape codes you can use this define.
343+
t
344+
_Example:_
345+
#define UNITY_OUTPUT_COLOR
346+
347+
348+
312349
## Getting Into The Guts
313350

314351
There will be cases where the options above aren't quite going to get everything

docs/UnityHelperScriptsGuide.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ demonstrates using a Ruby hash.
124124

125125
##### `:includes`
126126

127-
This option specifies an array of file names to be ?#include?'d at the top of
127+
This option specifies an array of file names to be `#include`'d at the top of
128128
your runner C file. You might use it to reference custom types or anything else
129129
universally needed in your generated runners.
130130

@@ -133,11 +133,23 @@ universally needed in your generated runners.
133133

134134
Define this option with C code to be executed _before any_ test cases are run.
135135

136+
Alternatively, if your C compiler supports weak symbols, you can leave this
137+
option unset and instead provide a `void suiteSetUp(void)` function in your test
138+
suite. The linker will look for this symbol and fall back to a Unity-provided
139+
stub if it is not found.
140+
136141

137142
##### `:suite_teardown`
138143

139-
Define this option with C code to be executed ?after all?test cases have
140-
finished.
144+
Define this option with C code to be executed _after all_ test cases have
145+
finished. An integer variable `num_failures` is available for diagnostics.
146+
The code should end with a `return` statement; the value returned will become
147+
the exit code of `main`. You can normally just return `num_failures`.
148+
149+
Alternatively, if your C compiler supports weak symbols, you can leave this
150+
option unset and instead provide a `int suiteTearDown(int num_failures)`
151+
function in your test suite. The linker will look for this symbol and fall
152+
back to a Unity-provided stub if it is not found.
141153

142154

143155
##### `:enforce_strict_ordering`

examples/example_3/rakefile.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
end
3333

3434
desc 'Build and test Unity'
35-
task all: %i[clean unit summary]
36-
task default: %i[clobber all]
35+
task all: %i(clean unit summary)
36+
task default: %i(clobber all)
3737
task ci: [:default]
3838
task cruise: [:default]
3939

0 commit comments

Comments
 (0)