From c5c392b18a21b048ceb6f728bb7dea84c6e20db5 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Fri, 6 May 2016 10:47:39 -0400 Subject: [PATCH] update UNITY_OUTPUT_CHAR to not return a value (because we never check it anyway). add UNITY_OUTPUT_FLUSH to make sure we get the output we need on aborted tests and whatnot. --- src/unity.c | 11 ++++++++++- src/unity_internals.h | 17 ++++++++++++++--- test/tests/testparameterized.c | 2 +- test/tests/testunity.c | 3 +-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/unity.c b/src/unity.c index d8fb7aa..f9750a4 100644 --- a/src/unity.c +++ b/src/unity.c @@ -7,11 +7,18 @@ #include "unity.h" #include +//If omitted from header, declare overrideable prototypes here so they're ready for use #ifdef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION -int UNITY_OUTPUT_CHAR(int); //If omitted from header, declare it here so it's ready for use +int UNITY_OUTPUT_CHAR(int); #endif +#ifdef UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION +int UNITY_OUTPUT_FLUSH(void); +#endif + +//Helpful macros for us to use here #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;} } @@ -331,6 +338,7 @@ void UnityConcludeTest(void) Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; UNITY_PRINT_EOL(); + UNITY_OUTPUT_FLUSH(); } //----------------------------------------------- @@ -1290,6 +1298,7 @@ int UnityEnd(void) #endif } UNITY_PRINT_EOL(); + UNITY_OUTPUT_FLUSH(); UNITY_OUTPUT_COMPLETE(); return (int)(Unity.TestFailures); } diff --git a/src/unity_internals.h b/src/unity_internals.h index 560d28f..d1cff52 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -290,11 +290,22 @@ typedef UNITY_DOUBLE_TYPE _UD; #ifndef UNITY_OUTPUT_CHAR //Default to using putchar, which is defined in stdio.h #include -#define UNITY_OUTPUT_CHAR(a) putchar(a) +#define UNITY_OUTPUT_CHAR(a) (void)putchar(a) #else -//If defined as something else, make sure we declare it here so it's ready for use + //If defined as something else, make sure we declare it here so it's ready for use #ifndef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION -extern int UNITY_OUTPUT_CHAR(int); +extern void UNITY_OUTPUT_CHAR(int); + #endif +#endif + +#ifndef UNITY_OUTPUT_FLUSH +//Default to using putchar, which is defined in stdio.h +#include +#define UNITY_OUTPUT_FLUSH() (void)fflush(stdout) +#else + //If defined as something else, make sure we declare it here so it's ready for use + #ifndef UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION +extern void UNITY_OUTPUT_FLUSH(void); #endif #endif diff --git a/test/tests/testparameterized.c b/test/tests/testparameterized.c index 21cf433..95216dd 100644 --- a/test/tests/testparameterized.c +++ b/test/tests/testparameterized.c @@ -8,7 +8,7 @@ #include #include "unity.h" -int putcharSpy(int c) {return putchar(c);} // include passthrough for linking tests +void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests #define TEST_CASE(...) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index e0872cc..830dc57 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -2247,7 +2247,7 @@ char* getBufferPutcharSpy(void) #endif } -int putcharSpy(int c) +void putcharSpy(int c) { #ifdef USING_OUTPUT_SPY if (putcharSpyEnabled) @@ -2257,7 +2257,6 @@ int putcharSpy(int c) } else c = putchar(c); #endif - return c; } void testFailureCountIncrementsAndIsReturnedAtEnd(void)