Skip to content

Commit 54fb72f

Browse files
authored
Merge pull request #824 from ThrowTheSwitch/refactor/uint_handling
Cleanup of Warnings and Fix UINT printing issue.
2 parents a2838c4 + b7de108 commit 54fb72f

File tree

7 files changed

+133
-50
lines changed

7 files changed

+133
-50
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unity Test ![CI][]
22

3-
__Copyright (c) 2007 - 2024 Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams__
3+
__Copyright (c) 2007 - 2026 Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams__
44

55
Welcome to the Unity Test Project, one of the main projects of ThrowTheSwitch.org.
66
Unity Test is a unit testing framework built for C, with a focus on working with embedded toolchains.

auto/colour_reporter.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ def report(message)
1919
colour = case line
2020
when /(?:total\s+)?tests:?\s+(\d+)\s+(?:total\s+)?failures:?\s+\d+\s+Ignored:?/i
2121
Regexp.last_match(1).to_i.zero? ? :green : :red
22+
when /^\[FAIL\]/
23+
:red
24+
when /^\[p \]/
25+
:green
26+
when /^\[i---\]/
27+
:green
2228
when /PASS/
2329
:green
2430
when /^OK$/

auto/generate_test_runner.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,15 @@ def count_tests(tests)
239239
if @options[:use_param_tests]
240240
idx = 0
241241
tests.each do |test|
242-
if (test[:args].nil? || test[:args].empty?)
242+
if test[:args].nil? || test[:args].empty?
243243
idx += 1
244244
else
245-
test[:args].each do |args|
246-
idx += 1
247-
end
245+
test[:args].each { idx += 1 }
248246
end
249247
end
250-
return idx
248+
idx
251249
else
252-
return tests.size
250+
tests.size
253251
end
254252
end
255253

auto/unity_test_summary.rb

100644100755
File mode changed.

src/unity.c

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -197,41 +197,48 @@ void UnityPrintLen(const char* string, const UNITY_UINT32 length)
197197
/*-----------------------------------------------*/
198198
void UnityPrintIntNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style)
199199
{
200-
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
200+
if (style == UNITY_DISPLAY_STYLE_CHAR)
201201
{
202-
if (style == UNITY_DISPLAY_STYLE_CHAR)
202+
/* printable characters plus CR & LF are printed */
203+
UNITY_OUTPUT_CHAR('\'');
204+
if ((number <= 126) && (number >= 32))
203205
{
204-
/* printable characters plus CR & LF are printed */
205-
UNITY_OUTPUT_CHAR('\'');
206-
if ((number <= 126) && (number >= 32))
207-
{
208-
UNITY_OUTPUT_CHAR((int)number);
209-
}
210-
/* write escaped carriage returns */
211-
else if (number == 13)
212-
{
213-
UNITY_OUTPUT_CHAR('\\');
214-
UNITY_OUTPUT_CHAR('r');
215-
}
216-
/* write escaped line feeds */
217-
else if (number == 10)
218-
{
219-
UNITY_OUTPUT_CHAR('\\');
220-
UNITY_OUTPUT_CHAR('n');
221-
}
222-
/* unprintable characters are shown as codes */
223-
else
224-
{
225-
UNITY_OUTPUT_CHAR('\\');
226-
UNITY_OUTPUT_CHAR('x');
227-
UnityPrintNumberHex((UNITY_UINT)number, 2);
228-
}
229-
UNITY_OUTPUT_CHAR('\'');
206+
UNITY_OUTPUT_CHAR((int)number);
207+
}
208+
/* write escaped carriage returns */
209+
else if (number == 13)
210+
{
211+
UNITY_OUTPUT_CHAR('\\');
212+
UNITY_OUTPUT_CHAR('r');
230213
}
214+
/* write escaped line feeds */
215+
else if (number == 10)
216+
{
217+
UNITY_OUTPUT_CHAR('\\');
218+
UNITY_OUTPUT_CHAR('n');
219+
}
220+
/* unprintable characters are shown as codes */
231221
else
232222
{
233-
UnityPrintNumber(number);
223+
UNITY_OUTPUT_CHAR('\\');
224+
UNITY_OUTPUT_CHAR('x');
225+
UnityPrintNumberHex((UNITY_UINT)number, 2);
234226
}
227+
UNITY_OUTPUT_CHAR('\'');
228+
}
229+
else if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
230+
{
231+
UnityPrintNumber(number);
232+
}
233+
else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
234+
{
235+
UnityPrintNumberUnsigned((UNITY_UINT)number);
236+
}
237+
else
238+
{
239+
UNITY_OUTPUT_CHAR('0');
240+
UNITY_OUTPUT_CHAR('x');
241+
UnityPrintNumberHex((UNITY_UINT)number, (char)((style & 0xF) * 2));
235242
}
236243
}
237244

@@ -359,25 +366,25 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
359366

360367
UNITY_DOUBLE number = input_number;
361368

362-
/* print minus sign (does not handle negative zero) */
363-
if (number < 0.0f)
364-
{
365-
UNITY_OUTPUT_CHAR('-');
366-
number = -number;
367-
}
368-
369369
/* handle zero, NaN, and +/- infinity */
370370
if (number == 0.0f)
371371
{
372372
UnityPrint("0");
373373
}
374374
else if (UNITY_IS_NAN(number))
375375
{
376-
UnityPrint("nan");
376+
UnityPrint(UnityStrNaN);
377377
}
378378
else if (UNITY_IS_INF(number))
379379
{
380-
UnityPrint("inf");
380+
if (number < 0.0f)
381+
{
382+
UnityPrint(UnityStrNegInf);
383+
}
384+
else
385+
{
386+
UnityPrint(UnityStrInf);
387+
}
381388
}
382389
else
383390
{
@@ -388,6 +395,11 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
388395
int digits;
389396
char buf[16] = {0};
390397

398+
if (number < 0.0f)
399+
{
400+
UNITY_OUTPUT_CHAR('-');
401+
number = -number;
402+
}
391403
/*
392404
* Scale up or down by powers of 10. To minimize rounding error,
393405
* start with a factor/divisor of 10^10, which is the largest
@@ -868,6 +880,8 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
868880
const UNITY_DISPLAY_STYLE_T style,
869881
const UNITY_FLAGS_T flags)
870882
{
883+
UNITY_INT expect_val = 0;
884+
UNITY_INT actual_val = 0;
871885
UNITY_UINT32 elements = num_elements;
872886
unsigned int length = style & 0xF;
873887
unsigned int increment = 0;
@@ -895,9 +909,6 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
895909

896910
while ((elements > 0) && (elements--))
897911
{
898-
UNITY_INT expect_val;
899-
UNITY_INT actual_val;
900-
901912
switch (length)
902913
{
903914
case 1:

src/unity_internals.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
445445
#endif
446446

447447
/*-------------------------------------------------------
448-
* Internal Structs Needed
448+
* Internal Types Needed
449449
*-------------------------------------------------------*/
450450

451451
typedef void (*UnityTestFunction)(void);
@@ -528,6 +528,10 @@ typedef enum
528528
#endif
529529
#endif
530530

531+
#if defined(__GNUC__) || defined(__clang__)
532+
#pragma GCC diagnostic push
533+
#pragma GCC diagnostic ignored "-Wpadded"
534+
#endif
531535
struct UNITY_STORAGE_T
532536
{
533537
const char* TestFile;
@@ -556,6 +560,9 @@ struct UNITY_STORAGE_T
556560
jmp_buf AbortFrame;
557561
#endif
558562
};
563+
#if defined(__GNUC__) || defined(__clang__)
564+
#pragma GCC diagnostic pop
565+
#endif
559566

560567
extern struct UNITY_STORAGE_T Unity;
561568

@@ -857,6 +864,7 @@ extern const char UnityStrErrFloat[];
857864
extern const char UnityStrErrDouble[];
858865
extern const char UnityStrErr64[];
859866
extern const char UnityStrErrShorthand[];
867+
extern const char UnityStrErrDetailStack[];
860868

861869
/*-------------------------------------------------------
862870
* Test Running Macros

test/rakefile_helper.rb

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,68 @@ def run_tests(test_files)
293293
# Link the test executable
294294
link_it(test_base, obj_list)
295295

296-
# Execute unit test and generate results file
296+
# Execute unit test
297297
output = runtest(test_base)
298+
299+
# This is a list of all non-string valid outputs
300+
# (in order) this is the following options:
301+
# valid binary representations
302+
# valid hexadecimal representation
303+
# valid integer (signed or unsigned) or float values of any precision
304+
# valid floating point special-case verbage
305+
# valid boolean verbage
306+
# valid pointer verbage
307+
# string representations
308+
# character representations
309+
valid_vals_regexes = [
310+
/[01X]+/,
311+
/0x[0-9A-Fa-f]+/,
312+
/-?\d+(?:\.\d+)?/,
313+
/(?:Not )?(?:Negative )?(?:Infinity|NaN|Determinate|Invalid Float Trait)/,
314+
/TRUE|FALSE/,
315+
/NULL/,
316+
/"[^"]*"/,
317+
/'[^']*'/
318+
]
319+
valid_vals = "(?:#{valid_vals_regexes.map(&:source).join('|')})"
320+
321+
# Verify outputs seem to have happened
322+
failures = 0
323+
output = output.each_line.map do |line|
324+
if (line =~ /(?:Delta.*)?(?:Element.*)?Expected.*Was/)
325+
if !(line =~ /(?:Delta \d+ )?(?:Element \d+ )?Expected #{valid_vals} Was #{valid_vals}/)
326+
failures += 1
327+
"[FAIL] " + line.sub(/:PASS$/,":FAIL:Output Format Failure")
328+
else
329+
"[p ] " + line
330+
end
331+
elsif (line =~ /:PASS$/)
332+
"[p ] " + line
333+
elsif (line =~ /:FAIL(?:[^:])$/) || (line =~ /^FAILED$/)
334+
#failure has already been counted therefore do not add
335+
"[FAIL] " + line
336+
elsif (line =~ /:IGNORE$/)
337+
#ignore has already been counted therefore do not add
338+
"[i---] " + line
339+
else
340+
"[ ] " + line
341+
end
342+
end.join
343+
344+
# Update the final test summary
345+
if failures > 0
346+
output.sub!(/^(?:\[ \] )?(\d+) Tests (\d+) Failures (\d+) Ignored/) do
347+
tests = $1
348+
failures = $2.to_i + failures
349+
ignored = $3
350+
"[ ] #{tests} Tests #{failures} Failures #{ignored} Ignored"
351+
end
352+
output.sub!(/\[ \] OK$/,"[FAIL] FAILED")
353+
report output
354+
raise "Command failed. (#{failures.to_s} Output Formatting Issues)"
355+
end
356+
357+
# Generate results file
298358
save_test_results(test_base, output)
299359
end
300360
end

0 commit comments

Comments
 (0)