vendor/unity/src/unity.c in ceedling-0.19.0 vs vendor/unity/src/unity.c in ceedling-0.20.2

- old
+ new

@@ -5,10 +5,15 @@ ============================================================================ */ #include "unity.h" #include <stddef.h> +#ifndef UNITY_OUTPUT_CHAR_USE_PUTC +//If defined as something else, make sure we declare it here so it's ready for use +extern int UNITY_OUTPUT_CHAR(int); +#endif + #define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; longjmp(Unity.AbortFrame, 1); } #define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; longjmp(Unity.AbortFrame, 1); } /// return prematurely if we are already in failure or ignore state #define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} } @@ -33,10 +38,11 @@ const char UnityStrNot[] = "Not "; const char UnityStrInf[] = "Infinity"; const char UnityStrNegInf[] = "Negative Infinity"; const char UnityStrNaN[] = "NaN"; const char UnityStrDet[] = "Determinate"; +const char UnityStrInvalidFloatTrait[] = "Invalid Float Trait"; const char UnityStrErrFloat[] = "Unity Floating Point Disabled"; const char UnityStrErrDouble[] = "Unity Double Precision Disabled"; const char UnityStrErr64[] = "Unity 64-bit Support Disabled"; const char UnityStrBreaker[] = "-----------------------"; const char UnityStrResultsTests[] = " Tests "; @@ -64,13 +70,10 @@ #ifdef UNITY_SUPPORT_64 ,0xFFFFFFFFFFFFFFFF #endif }; -void UnityPrintFail(void); -void UnityPrintOk(void); - //----------------------------------------------- // Pretty Printers & Test Result Output Handlers //----------------------------------------------- void UnityPrint(const char* string) @@ -278,14 +281,23 @@ } //----------------------------------------------- #ifdef UNITY_FLOAT_VERBOSE #include <stdio.h> + +#ifndef UNITY_VERBOSE_NUMBER_MAX_LENGTH +# ifdef UNITY_DOUBLE_VERBOSE +# define UNITY_VERBOSE_NUMBER_MAX_LENGTH 317 +# else +# define UNITY_VERBOSE_NUMBER_MAX_LENGTH 47 +# endif +#endif + void UnityPrintFloat(_UF number) { - char TempBuffer[32]; - sprintf(TempBuffer, "%.6f", number); + char TempBuffer[UNITY_VERBOSE_NUMBER_MAX_LENGTH + 1]; + snprintf(TempBuffer, sizeof(TempBuffer), "%.6f", number); UnityPrint(TempBuffer); } #endif //----------------------------------------------- @@ -549,11 +561,11 @@ { if (*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US8*)ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); - UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); + UnityPrintNumberUnsigned(num_elements - elements - 1); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_exp, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_act, style); UnityAddMsgIfSpecified(msg); @@ -570,11 +582,11 @@ { if (*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US16*)ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); - UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); + UnityPrintNumberUnsigned(num_elements - elements - 1); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_exp, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_act, style); UnityAddMsgIfSpecified(msg); @@ -592,11 +604,11 @@ { if (*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US64*)ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); - UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); + UnityPrintNumberUnsigned(num_elements - elements - 1); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_exp, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_act, style); UnityAddMsgIfSpecified(msg); @@ -612,11 +624,11 @@ { if (*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US32*)ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); - UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); + UnityPrintNumberUnsigned(num_elements - elements - 1); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_exp, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_act, style); UnityAddMsgIfSpecified(msg); @@ -667,11 +679,11 @@ //This first part of this condition will catch any NaN or Infinite values if ((diff * 0.0f != 0.0f) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); - UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); + UnityPrintNumberUnsigned(num_elements - elements - 1); #ifdef UNITY_FLOAT_VERBOSE UnityPrint(UnityStrExpected); UnityPrintFloat(*ptr_expected); UnityPrint(UnityStrWas); UnityPrintFloat(*ptr_actual); @@ -731,11 +743,11 @@ const UNITY_FLOAT_TRAIT_T style) { const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet }; _U_SINT should_be_trait = ((_U_SINT)style & 1); _U_SINT is_trait = !should_be_trait; - _U_SINT trait_index = style >> 1; + _U_SINT trait_index = (_U_SINT)(style >> 1); UNITY_SKIP_EXECUTION; switch(style) { @@ -764,10 +776,12 @@ else is_trait = 1; break; default: + trait_index = 0; + trait_names[0] = UnityStrInvalidFloatTrait; break; } if (is_trait != should_be_trait) { @@ -829,11 +843,11 @@ //This first part of this condition will catch any NaN or Infinite values if ((diff * 0.0 != 0.0) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); - UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); + UnityPrintNumberUnsigned(num_elements - elements - 1); #ifdef UNITY_DOUBLE_VERBOSE UnityPrint(UnityStrExpected); UnityPrintFloat((float)(*ptr_expected)); UnityPrint(UnityStrWas); UnityPrintFloat((float)(*ptr_actual)); @@ -894,11 +908,11 @@ const UNITY_FLOAT_TRAIT_T style) { const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet }; _U_SINT should_be_trait = ((_U_SINT)style & 1); _U_SINT is_trait = !should_be_trait; - _U_SINT trait_index = style >> 1; + _U_SINT trait_index = (_U_SINT)(style >> 1); UNITY_SKIP_EXECUTION; switch(style) { @@ -927,10 +941,12 @@ else is_trait = 1; break; default: + trait_index = 0; + trait_names[0] = UnityStrInvalidFloatTrait; break; } if (is_trait != should_be_trait) { @@ -1123,11 +1139,11 @@ { UnityTestResultsFailBegin(lineNumber); if (num_elements > 1) { UnityPrint(UnityStrElement); - UnityPrintNumberByStyle((j), UNITY_DISPLAY_STYLE_UINT); + UnityPrintNumberUnsigned(j); } UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j])); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } @@ -1171,14 +1187,14 @@ UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrMemory); if (num_elements > 1) { UnityPrint(UnityStrElement); - UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); + UnityPrintNumberUnsigned(num_elements - elements - 1); } UnityPrint(UnityStrByte); - UnityPrintNumberByStyle((length - bytes - 1), UNITY_DISPLAY_STYLE_UINT); + UnityPrintNumberUnsigned(length - bytes - 1); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8); UnityAddMsgIfSpecified(msg); @@ -1245,21 +1261,16 @@ UNITY_IGNORE_AND_BAIL; } //----------------------------------------------- #if defined(UNITY_WEAK_ATTRIBUTE) - void setUp(void); - void tearDown(void); UNITY_WEAK_ATTRIBUTE void setUp(void) { } UNITY_WEAK_ATTRIBUTE void tearDown(void) { } #elif defined(UNITY_WEAK_PRAGMA) # pragma weak setUp void setUp(void) { } # pragma weak tearDown void tearDown(void) { } -#else - void setUp(void); - void tearDown(void); #endif //----------------------------------------------- void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum) { Unity.CurrentTestName = FuncName;