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.
This commit is contained in:
Mark VanderVoord
2026-03-12 14:19:12 -04:00
parent 943f4706ee
commit 849d95e119
3 changed files with 87 additions and 54 deletions
+6
View File
@@ -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$/
+24 -12
View File
@@ -196,8 +196,6 @@ 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)
{
@@ -228,10 +226,19 @@ void UnityPrintIntNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYL
}
UNITY_OUTPUT_CHAR('\'');
}
else
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
+31 -16
View File
@@ -296,30 +296,45 @@ 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