diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index 96e5358d41ac93c4e07fbe5e8658d612aeeb3de1..1b698287b71b9ac0576852f9730fcb196411d1ba 100644 --- a/docs/UnityConfigurationGuide.md +++ b/docs/UnityConfigurationGuide.md @@ -248,7 +248,8 @@ _Example:_ Say you are forced to run your test suite on an embedded processor with no `stdout` option. You decide to route your test result output to a custom serial `RS232_putc()` function you wrote like thus: - + #include "RS232_header.h" + ... #define UNITY_OUTPUT_CHAR(a) RS232_putc(a) #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) #define UNITY_OUTPUT_FLUSH() RS232_flush() @@ -256,10 +257,7 @@ Say you are forced to run your test suite on an embedded processor with no _Note:_ `UNITY_OUTPUT_FLUSH()` can be set to the standard out flush function simply by -specifying `UNITY_USE_FLUSH_STDOUT`. No other defines are required. If you -specify a custom flush function instead with `UNITY_OUTPUT_FLUSH` directly, it -will declare an instance of your function by default. If you want to disable -this behavior, add `UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION`. +specifying `UNITY_USE_FLUSH_STDOUT`. No other defines are required. ##### `UNITY_WEAK_ATTRIBUTE` diff --git a/src/unity_internals.h b/src/unity_internals.h index 3ba6fae762b456f81b629f83db2570afd68f54c2..415a29b0cc7fbc143760770bbe00cb03b0e9b19e 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -241,30 +241,30 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT; * Output Method: stdout (DEFAULT) *-------------------------------------------------------*/ #ifndef UNITY_OUTPUT_CHAR -/* Default to using putchar, which is defined in stdio.h */ -#include -#define UNITY_OUTPUT_CHAR(a) (void)putchar(a) + /* Default to using putchar, which is defined in stdio.h */ + #include + #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 */ #ifdef UNITY_OUTPUT_CHAR_HEADER_DECLARATION -extern void UNITY_OUTPUT_CHAR_HEADER_DECLARATION; + extern void UNITY_OUTPUT_CHAR_HEADER_DECLARATION; #endif #endif #ifndef UNITY_OUTPUT_FLUSH -#ifdef UNITY_USE_FLUSH_STDOUT -/* We want to use the stdout flush utility */ -#include -#define UNITY_OUTPUT_FLUSH() (void)fflush(stdout) -#else -/* We've specified nothing, therefore flush should just be ignored */ -#define UNITY_OUTPUT_FLUSH() -#endif + #ifdef UNITY_USE_FLUSH_STDOUT + /* We want to use the stdout flush utility */ + #include + #define UNITY_OUTPUT_FLUSH() (void)fflush(stdout) + #else + /* We've specified nothing, therefore flush should just be ignored */ + #define UNITY_OUTPUT_FLUSH() + #endif #else -/* We've defined flush as something else, so make sure we declare it here so it's ready for use */ -#ifdef UNITY_OUTPUT_FLUSH_HEADER_DECLARATION -extern void UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION; -#endif + /* If defined as something else, make sure we declare it here so it's ready for use */ + #ifdef UNITY_OUTPUT_FLUSH_HEADER_DECLARATION + extern void UNITY_OUTPUT_FLUSH_HEADER_DECLARATION; + #endif #endif #ifndef UNITY_OUTPUT_FLUSH diff --git a/test/Makefile b/test/Makefile index c2710f1f184b692d983dd3896e94f915134d6ff5..89ece81dd0d1e24202edfdd7a16a23e8170a83ae 100644 --- a/test/Makefile +++ b/test/Makefile @@ -15,6 +15,8 @@ CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstri CFLAGS += $(DEBUG) DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\) +DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy +DEFINES += -D UNITY_OUTPUT_FLUSH_HEADER_DECLARATION=flushSpy\(void\) DEFINES += $(UNITY_SUPPORT_64) $(UNITY_INCLUDE_DOUBLE) UNITY_SUPPORT_64 = -D UNITY_SUPPORT_64 UNITY_INCLUDE_DOUBLE = -D UNITY_INCLUDE_DOUBLE diff --git a/test/testdata/testRunnerGenerator.c b/test/testdata/testRunnerGenerator.c index e036dd96749d8ff57b52354633fe506271521fa0..62989a0d331724534d2b082c25c9d9f99f2c385e 100644 --- a/test/testdata/testRunnerGenerator.c +++ b/test/testdata/testRunnerGenerator.c @@ -21,7 +21,10 @@ /* Support for Meta Test Rig */ #define TEST_CASE(a) -void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests + +/* Include Passthroughs for Linking Tests */ +void putcharSpy(int c) { (void)putchar(c);} +void flushSpy(void) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/testdata/testRunnerGeneratorSmall.c b/test/testdata/testRunnerGeneratorSmall.c index c683749480fc8b7794f1dc1a793322b2c70e1092..c8aaf747ebf993b978375eecc0982c1090daa35d 100644 --- a/test/testdata/testRunnerGeneratorSmall.c +++ b/test/testdata/testRunnerGeneratorSmall.c @@ -13,7 +13,10 @@ TEST_FILE("some_file.c") /* Support for Meta Test Rig */ #define TEST_CASE(a) -void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests + +/* Include Passthroughs for Linking Tests */ +void putcharSpy(int c) { (void)putchar(c);} +void flushSpy(void) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/testdata/testRunnerGeneratorWithMocks.c b/test/testdata/testRunnerGeneratorWithMocks.c index 7eb0b671f6b90c502b9c53ce305425000f2e7789..4aacbf9ac3712bfbfb8de8553095ca9a1f0a0f25 100644 --- a/test/testdata/testRunnerGeneratorWithMocks.c +++ b/test/testdata/testRunnerGeneratorWithMocks.c @@ -22,7 +22,10 @@ /* Support for Meta Test Rig */ #define TEST_CASE(a) -void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests + +/* Include Passthroughs for Linking Tests */ +void putcharSpy(int c) { (void)putchar(c);} +void flushSpy(void) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/tests/testparameterized.c b/test/tests/testparameterized.c index aa6d1732c2de1a30b68b2b49ebe241c1536e930b..136cd2f4b36540c3b628413a96236a7f46a49ba1 100644 --- a/test/tests/testparameterized.c +++ b/test/tests/testparameterized.c @@ -8,10 +8,13 @@ #include #include "unity.h" -void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests - +/* Support for Meta Test Rig */ #define TEST_CASE(...) +/* Include Passthroughs for Linking Tests */ +void putcharSpy(int c) { (void)putchar(c);} +void flushSpy(void) {} + #define EXPECT_ABORT_BEGIN \ if (TEST_PROTECT()) \ { diff --git a/test/tests/testunity.c b/test/tests/testunity.c index af06647f81c0565dd20b0593b6b2d0586fe5d6db..95c8280460a0293f695e30cc696cd89e4ccafba4 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -54,6 +54,10 @@ void startPutcharSpy(void); void endPutcharSpy(void); char* getBufferPutcharSpy(void); +void startFlushSpy(void); +void endFlushSpy(void); +int getFlushSpyCalls(void); + static int SetToOneToFailInTearDown; static int SetToOneMeanWeAlreadyCheckedThisGuy; @@ -3335,14 +3339,35 @@ void putcharSpy(int c) #endif } +/* This is for counting the calls to the flushSpy */ +static int flushSpyEnabled; +static int flushSpyCalls = 0; + +void startFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 1; } +void endFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 0; } +int getFlushSpyCalls(void) { return flushSpyCalls; } + +void flushSpy(void) +{ + if (flushSpyEnabled){ flushSpyCalls++; } +} + void testFailureCountIncrementsAndIsReturnedAtEnd(void) { UNITY_UINT savedFailures = Unity.TestFailures; Unity.CurrentTestFailed = 1; startPutcharSpy(); // Suppress output + startFlushSpy(); + TEST_ASSERT_EQUAL(0, getFlushSpyCalls()); UnityConcludeTest(); endPutcharSpy(); TEST_ASSERT_EQUAL(savedFailures + 1, Unity.TestFailures); +#if defined(UNITY_OUTPUT_FLUSH) && defined(UNITY_OUTPUT_FLUSH_HEADER_DECLARATION) + TEST_ASSERT_EQUAL(1, getFlushSpyCalls()); +#else + TEST_ASSERT_EQUAL(0, getFlushSpyCalls()); +#endif + endFlushSpy(); startPutcharSpy(); // Suppress output int failures = UnityEnd(); @@ -3412,6 +3437,7 @@ void testPrintNumbersUnsigned32(void) #endif } + // ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES 64 BIT SUPPORT ================== void testPrintNumbersInt64(void)