mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-06-25 01:59:21 +08:00
(1.) removed errant '.' from memory mismatch string (2.) made string asserts more verbose for NULL string pointers (3.) modified UnityPrint to display unprintable characters as codes
git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@77 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
63
src/unity.c
63
src/unity.c
@ -13,17 +13,16 @@
|
|||||||
|
|
||||||
struct _Unity Unity = { 0 };
|
struct _Unity Unity = { 0 };
|
||||||
|
|
||||||
|
const char* UnityStrNull = "NULL";
|
||||||
const char* UnityStrExpected = " Expected ";
|
const char* UnityStrExpected = " Expected ";
|
||||||
const char* UnityStrWas = " Was ";
|
const char* UnityStrWas = " Was ";
|
||||||
const char* UnityStrTo = " To ";
|
const char* UnityStrTo = " To ";
|
||||||
const char* UnityStrElement = " Element ";
|
const char* UnityStrElement = " Element ";
|
||||||
const char* UnityStrMemory = " Memory Mismatch.";
|
const char* UnityStrMemory = " Memory Mismatch";
|
||||||
const char* UnityStrDelta = " Values Not Within Delta ";
|
const char* UnityStrDelta = " Values Not Within Delta ";
|
||||||
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
|
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
|
||||||
const char* UnityStrSpacer = ". ";
|
const char* UnityStrSpacer = ". ";
|
||||||
|
|
||||||
void UnityAddMsgIfSpecified(const char* msg);
|
|
||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
// Pretty Printers
|
// Pretty Printers
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
@ -36,7 +35,19 @@ void UnityPrint(const char* string)
|
|||||||
{
|
{
|
||||||
while (*pch)
|
while (*pch)
|
||||||
{
|
{
|
||||||
|
// printable characters plus CR & LF are printed
|
||||||
|
if ( (*pch <= 126) && (*pch >= 32) || (*pch == 13) || (*pch == 10) )
|
||||||
|
{
|
||||||
UNITY_OUTPUT_CHAR(*pch);
|
UNITY_OUTPUT_CHAR(*pch);
|
||||||
|
}
|
||||||
|
// unprintable characters are shown as codes
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UNITY_OUTPUT_CHAR('{');
|
||||||
|
UNITY_OUTPUT_CHAR('\\');
|
||||||
|
UnityPrintNumber((const _US32)*pch);
|
||||||
|
UNITY_OUTPUT_CHAR('}');
|
||||||
|
}
|
||||||
pch++;
|
pch++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,6 +232,34 @@ void UnityAddMsgIfSpecified(const char* msg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------
|
||||||
|
void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
|
||||||
|
{
|
||||||
|
UnityPrint(UnityStrExpected);
|
||||||
|
if (expected != NULL)
|
||||||
|
{
|
||||||
|
UNITY_OUTPUT_CHAR('\'');
|
||||||
|
UnityPrint(expected);
|
||||||
|
UNITY_OUTPUT_CHAR('\'');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UnityPrint(UnityStrNull);
|
||||||
|
}
|
||||||
|
UnityPrint(UnityStrWas);
|
||||||
|
if (actual != NULL)
|
||||||
|
{
|
||||||
|
UNITY_OUTPUT_CHAR('\'');
|
||||||
|
UnityPrint(actual);
|
||||||
|
UNITY_OUTPUT_CHAR('\'');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UnityPrint(UnityStrNull);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
// Assertion Functions
|
// Assertion Functions
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
@ -500,14 +539,7 @@ void UnityAssertEqualString(const char* expected,
|
|||||||
if (Unity.CurrentTestFailed)
|
if (Unity.CurrentTestFailed)
|
||||||
{
|
{
|
||||||
UnityTestResultsFailBegin(lineNumber);
|
UnityTestResultsFailBegin(lineNumber);
|
||||||
UnityPrint(UnityStrExpected);
|
UnityPrintExpectedAndActualStrings(expected, actual);
|
||||||
UNITY_OUTPUT_CHAR('\'');
|
|
||||||
UnityPrint(expected);
|
|
||||||
UNITY_OUTPUT_CHAR('\'');
|
|
||||||
UnityPrint(UnityStrWas);
|
|
||||||
UNITY_OUTPUT_CHAR('\'');
|
|
||||||
UnityPrint(actual);
|
|
||||||
UNITY_OUTPUT_CHAR('\'');
|
|
||||||
UnityAddMsgIfSpecified(msg);
|
UnityAddMsgIfSpecified(msg);
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
}
|
}
|
||||||
@ -575,14 +607,7 @@ void UnityAssertEqualStringArray( const char** expected,
|
|||||||
UnityPrint(UnityStrElement);
|
UnityPrint(UnityStrElement);
|
||||||
UnityPrintNumberByStyle((num_elements - j - 1), UNITY_DISPLAY_STYLE_UINT);
|
UnityPrintNumberByStyle((num_elements - j - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||||
}
|
}
|
||||||
UnityPrint(UnityStrExpected);
|
UnityPrintExpectedAndActualStrings(expected[j], actual[j]);
|
||||||
UNITY_OUTPUT_CHAR('\'');
|
|
||||||
UnityPrint(expected[j]);
|
|
||||||
UNITY_OUTPUT_CHAR('\'');
|
|
||||||
UnityPrint(UnityStrWas);
|
|
||||||
UNITY_OUTPUT_CHAR('\'');
|
|
||||||
UnityPrint(actual[j]);
|
|
||||||
UNITY_OUTPUT_CHAR('\'');
|
|
||||||
UnityAddMsgIfSpecified(msg);
|
UnityAddMsgIfSpecified(msg);
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user