From 849d95e119b58315094da28af18c70a54d30b144 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Thu, 12 Mar 2026 14:19:12 -0400 Subject: [PATCH] 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. --- auto/colour_reporter.rb | 6 +++ src/unity.c | 88 +++++++++++++++++++++++------------------ test/rakefile_helper.rb | 47 ++++++++++++++-------- 3 files changed, 87 insertions(+), 54 deletions(-) diff --git a/auto/colour_reporter.rb b/auto/colour_reporter.rb index 10a17d3..cb10f3f 100644 --- a/auto/colour_reporter.rb +++ b/auto/colour_reporter.rb @@ -19,6 +19,12 @@ def report(message) colour = case line when /(?:total\s+)?tests:?\s+(\d+)\s+(?:total\s+)?failures:?\s+\d+\s+Ignored:?/i Regexp.last_match(1).to_i.zero? ? :green : :red + when /^\[FAIL\]/ + :red + when /^\[p \]/ + :green + when /^\[i---\]/ + :green when /PASS/ :green when /^OK$/ diff --git a/src/unity.c b/src/unity.c index 198577c..7933edd 100644 --- a/src/unity.c +++ b/src/unity.c @@ -197,41 +197,48 @@ void UnityPrintLen(const char* string, const UNITY_UINT32 length) /*-----------------------------------------------*/ void UnityPrintIntNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style) { - if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) + if (style == UNITY_DISPLAY_STYLE_CHAR) { - if (style == UNITY_DISPLAY_STYLE_CHAR) + /* printable characters plus CR & LF are printed */ + UNITY_OUTPUT_CHAR('\''); + if ((number <= 126) && (number >= 32)) { - /* printable characters plus CR & LF are printed */ - UNITY_OUTPUT_CHAR('\''); - if ((number <= 126) && (number >= 32)) - { - UNITY_OUTPUT_CHAR((int)number); - } - /* write escaped carriage returns */ - else if (number == 13) - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('r'); - } - /* write escaped line feeds */ - else if (number == 10) - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('n'); - } - /* unprintable characters are shown as codes */ - else - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('x'); - UnityPrintNumberHex((UNITY_UINT)number, 2); - } - UNITY_OUTPUT_CHAR('\''); + UNITY_OUTPUT_CHAR((int)number); } + /* write escaped carriage returns */ + else if (number == 13) + { + UNITY_OUTPUT_CHAR('\\'); + UNITY_OUTPUT_CHAR('r'); + } + /* write escaped line feeds */ + else if (number == 10) + { + UNITY_OUTPUT_CHAR('\\'); + UNITY_OUTPUT_CHAR('n'); + } + /* unprintable characters are shown as codes */ else { - UnityPrintNumber(number); + UNITY_OUTPUT_CHAR('\\'); + UNITY_OUTPUT_CHAR('x'); + UnityPrintNumberHex((UNITY_UINT)number, 2); } + UNITY_OUTPUT_CHAR('\''); + } + else if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) + { + UnityPrintNumber(number); + } + else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT) + { + UnityPrintNumberUnsigned((UNITY_UINT)number); + } + else + { + UNITY_OUTPUT_CHAR('0'); + UNITY_OUTPUT_CHAR('x'); + UnityPrintNumberHex((UNITY_UINT)number, (char)((style & 0xF) * 2)); } } @@ -359,13 +366,6 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) UNITY_DOUBLE number = input_number; - /* print minus sign (does not handle negative zero) */ - if (number < 0.0f) - { - UNITY_OUTPUT_CHAR('-'); - number = -number; - } - /* handle zero, NaN, and +/- infinity */ if (number == 0.0f) { @@ -373,11 +373,18 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) } else if (UNITY_IS_NAN(number)) { - UnityPrint("nan"); + UnityPrint(UnityStrNaN); } else if (UNITY_IS_INF(number)) { - UnityPrint("inf"); + if (number < 0.0f) + { + UnityPrint(UnityStrNegInf); + } + else + { + UnityPrint(UnityStrInf); + } } else { @@ -388,6 +395,11 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) int digits; char buf[16] = {0}; + if (number < 0.0f) + { + UNITY_OUTPUT_CHAR('-'); + number = -number; + } /* * Scale up or down by powers of 10. To minimize rounding error, * start with a factor/divisor of 10^10, which is the largest diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index 0938505..6149b8d 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -295,31 +295,46 @@ module RakefileHelpers # Execute unit test output = runtest(test_base) + + # This is a list of all non-string valid outputs + # (in order) this is the following options: + # valid binary representations + # valid hexadecimal representation + # valid integer (signed or unsigned) or float values of any precision + # valid floating point special-case verbage + # valid boolean verbage + # valid pointer verbage + # string representations + # character representations + valid_vals_regexes = [ + /[01X]+/, + /0x[0-9A-Fa-f]+/, + /-?\d+(?:\.\d+)?/, + /(?:Not )?(?:Negative )?(?:Infinity|NaN|Determinate|Invalid Float Trait)/, + /TRUE|FALSE/, + /NULL/, + /"[^"]*"/, + /'[^']*'/ + ] + valid_vals = "(?:#{valid_vals_regexes.map(&:source).join('|')})" # Verify outputs seem to have happened failures = 0 output = output.each_line.map do |line| - if (line =~ /Element.*Expected.*Was/) - if !(line =~ /Element \d+ Expected \S+ Was \S+/) && - !(line =~ /Element \d+ Expected "[^"]+" Was "[^"]+"/) + if (line =~ /(?:Delta.*)?(?:Element.*)?Expected.*Was/) + if !(line =~ /(?:Delta \d+ )?(?:Element \d+ )?Expected #{valid_vals} Was #{valid_vals}/) failures += 1 - "[FAIL] " + line - else - "[p ] " + line - end - elsif (line =~ /Expected.*Was/) - if !(line =~ /Expected \S+ Was \S+/) && - !(line =~ /Expected "[^"]+" Was "[^"]+"/) - failures += 1 - "[FAIL] " + line + "[FAIL] " + line.sub(/:PASS$/,":FAIL:Output Format Failure") else "[p ] " + line end elsif (line =~ /:PASS$/) "[p ] " + line - elsif (line =~ /:FAIL$/) + elsif (line =~ /:FAIL(?:[^:])$/) || (line =~ /^FAILED$/) + #failure has already been counted therefore do not add "[FAIL] " + line elsif (line =~ /:IGNORE$/) + #ignore has already been counted therefore do not add "[i---] " + line else "[ ] " + line @@ -328,13 +343,13 @@ module RakefileHelpers # Update the final test summary if failures > 0 - output.sub!(/^(\d+) Tests (\d+) Failures (\d+) Ignored/) do + output.sub!(/^(?:\[ \] )?(\d+) Tests (\d+) Failures (\d+) Ignored/) do tests = $1 failures = $2.to_i + failures ignored = $3 - "#{tests} Tests #{failures} Failures #{ignored} Ignored" + "[ ] #{tests} Tests #{failures} Failures #{ignored} Ignored" end - output.sub!(/OK$/,"FAILED") + output.sub!(/\[ \] OK$/,"[FAIL] FAILED") report output raise "Command failed. (#{failures.to_s} Output Formatting Issues)" end