Skip to content

Commit 849d95e

Browse files
committed
improve new format checking to capture all valid outputs.
improve floating point special case reporting to always use verbose. fix bug in arrays where values were sometimes not shown.
1 parent 943f470 commit 849d95e

3 files changed

Lines changed: 87 additions & 54 deletions

File tree

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$/

src/unity.c

Lines changed: 50 additions & 38 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');
213+
}
214+
/* write escaped line feeds */
215+
else if (number == 10)
216+
{
217+
UNITY_OUTPUT_CHAR('\\');
218+
UNITY_OUTPUT_CHAR('n');
230219
}
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

test/rakefile_helper.rb

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -295,31 +295,46 @@ def run_tests(test_files)
295295

296296
# 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('|')})"
298320

299321
# Verify outputs seem to have happened
300322
failures = 0
301323
output = output.each_line.map do |line|
302-
if (line =~ /Element.*Expected.*Was/)
303-
if !(line =~ /Element \d+ Expected \S+ Was \S+/) &&
304-
!(line =~ /Element \d+ Expected "[^"]+" Was "[^"]+"/)
324+
if (line =~ /(?:Delta.*)?(?:Element.*)?Expected.*Was/)
325+
if !(line =~ /(?:Delta \d+ )?(?:Element \d+ )?Expected #{valid_vals} Was #{valid_vals}/)
305326
failures += 1
306-
"[FAIL] " + line
307-
else
308-
"[p ] " + line
309-
end
310-
elsif (line =~ /Expected.*Was/)
311-
if !(line =~ /Expected \S+ Was \S+/) &&
312-
!(line =~ /Expected "[^"]+" Was "[^"]+"/)
313-
failures += 1
314-
"[FAIL] " + line
327+
"[FAIL] " + line.sub(/:PASS$/,":FAIL:Output Format Failure")
315328
else
316329
"[p ] " + line
317330
end
318331
elsif (line =~ /:PASS$/)
319332
"[p ] " + line
320-
elsif (line =~ /:FAIL$/)
333+
elsif (line =~ /:FAIL(?:[^:])$/) || (line =~ /^FAILED$/)
334+
#failure has already been counted therefore do not add
321335
"[FAIL] " + line
322336
elsif (line =~ /:IGNORE$/)
337+
#ignore has already been counted therefore do not add
323338
"[i---] " + line
324339
else
325340
"[ ] " + line
@@ -328,13 +343,13 @@ def run_tests(test_files)
328343

329344
# Update the final test summary
330345
if failures > 0
331-
output.sub!(/^(\d+) Tests (\d+) Failures (\d+) Ignored/) do
346+
output.sub!(/^(?:\[ \] )?(\d+) Tests (\d+) Failures (\d+) Ignored/) do
332347
tests = $1
333348
failures = $2.to_i + failures
334349
ignored = $3
335-
"#{tests} Tests #{failures} Failures #{ignored} Ignored"
350+
"[ ] #{tests} Tests #{failures} Failures #{ignored} Ignored"
336351
end
337-
output.sub!(/OK$/,"FAILED")
352+
output.sub!(/\[ \] OK$/,"[FAIL] FAILED")
338353
report output
339354
raise "Command failed. (#{failures.to_s} Output Formatting Issues)"
340355
end

0 commit comments

Comments
 (0)