From 8efa8ffc621e0986d82a77a63362a96af7d5ca59 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 13:57:34 +0100 Subject: [PATCH 1/9] Removed UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION to simplify the behaviour --- docs/UnityConfigurationGuide.md | 8 +++----- src/unity_internals.h | 32 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index 96e5358..1b69828 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 3ba6fae..415a29b 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) + #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 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 From fe950b9fa3466077b96fa93031f8f8fe1e2875bd Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 14:11:19 +0100 Subject: [PATCH 2/9] Makefile preparations --- test/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Makefile b/test/Makefile index c2710f1..f37b9ea 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 From 456759296b407189c0b48b02dd3c479b4ddff4f3 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 14:23:26 +0100 Subject: [PATCH 3/9] Added flushSpy --- test/Makefile | 4 ++-- test/testdata/testRunnerGenerator.c | 5 ++++- test/testdata/testRunnerGeneratorSmall.c | 5 ++++- test/testdata/testRunnerGeneratorWithMocks.c | 5 ++++- test/tests/testparameterized.c | 7 +++++-- test/tests/testunity.c | 8 ++++++++ 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/test/Makefile b/test/Makefile index f37b9ea..89ece81 100644 --- a/test/Makefile +++ b/test/Makefile @@ -15,8 +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 += -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 e036dd9..7a4d63b 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(int c) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/testdata/testRunnerGeneratorSmall.c b/test/testdata/testRunnerGeneratorSmall.c index c683749..a8707fb 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(int c) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/testdata/testRunnerGeneratorWithMocks.c b/test/testdata/testRunnerGeneratorWithMocks.c index 7eb0b67..a7d622d 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(int c) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/tests/testparameterized.c b/test/tests/testparameterized.c index aa6d173..7be7f2b 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(int c) {} + #define EXPECT_ABORT_BEGIN \ if (TEST_PROTECT()) \ { diff --git a/test/tests/testunity.c b/test/tests/testunity.c index af06647..1884cbb 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -3335,6 +3335,14 @@ void putcharSpy(int c) #endif } +#if 0 +void flushSpy(void) +{ + static unsigned int calls = 0; + calls++; // count every call +} +#endif + void testFailureCountIncrementsAndIsReturnedAtEnd(void) { UNITY_UINT savedFailures = Unity.TestFailures; From 25804f3ab4bec897019333022bbb44472f5b6534 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 14:46:42 +0100 Subject: [PATCH 4/9] Added flushSpy and the respective helper functions --- test/tests/testunity.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 1884cbb..3496990 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); +unsigned int getFlushSpyCalls(void); + static int SetToOneToFailInTearDown; static int SetToOneMeanWeAlreadyCheckedThisGuy; @@ -3335,13 +3339,18 @@ void putcharSpy(int c) #endif } -#if 0 +/* This is for counting the calls to the flushSpy */ +static int flushSpyEnabled; +static unsigned int flushSpyCalls = 0; + +void startFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 1; } +void endFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 0; } +unsigned int getFlushSpyCalls(void) { return flushSpyCalls; } + void flushSpy(void) { - static unsigned int calls = 0; - calls++; // count every call + if (flushSpyEnabled){ flushSpyCalls++; } } -#endif void testFailureCountIncrementsAndIsReturnedAtEnd(void) { @@ -3420,6 +3429,20 @@ void testPrintNumbersUnsigned32(void) #endif } + +/* This is for counting the calls to the flushSpy */ +static int flushSpyEnabled; +static unsigned int flushSpyCalls = 0; + +void startFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 1; } +void endFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 0; } +unsigned int getFlushSpyCalls(void) { return flushSpyCalls; } + +void flushSpy(void) +{ + if (flushSpyEnabled){ flushSpyCalls++; } +} + // ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES 64 BIT SUPPORT ================== void testPrintNumbersInt64(void) From 37271e8a131d12bb73bfdf2a1fc5612d3f142b03 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 14:53:39 +0100 Subject: [PATCH 5/9] Fixed copy and paste error --- test/tests/testunity.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 3496990..0f74bc5 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -3430,19 +3430,6 @@ void testPrintNumbersUnsigned32(void) } -/* This is for counting the calls to the flushSpy */ -static int flushSpyEnabled; -static unsigned int flushSpyCalls = 0; - -void startFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 1; } -void endFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 0; } -unsigned int getFlushSpyCalls(void) { return flushSpyCalls; } - -void flushSpy(void) -{ - if (flushSpyEnabled){ flushSpyCalls++; } -} - // ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES 64 BIT SUPPORT ================== void testPrintNumbersInt64(void) From 5f67ac6ab2b3adf37f9cf62bda1eb3efe1383f88 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 16:32:04 +0100 Subject: [PATCH 6/9] Fixed copy and paste error, changed the signature from: void flushSpy(int c) {} to: void flushSpy(void) {} --- test/testdata/testRunnerGenerator.c | 2 +- test/testdata/testRunnerGeneratorSmall.c | 2 +- test/testdata/testRunnerGeneratorWithMocks.c | 2 +- test/tests/testparameterized.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/testdata/testRunnerGenerator.c b/test/testdata/testRunnerGenerator.c index 7a4d63b..62989a0 100644 --- a/test/testdata/testRunnerGenerator.c +++ b/test/testdata/testRunnerGenerator.c @@ -24,7 +24,7 @@ /* Include Passthroughs for Linking Tests */ void putcharSpy(int c) { (void)putchar(c);} -void flushSpy(int 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 a8707fb..c8aaf74 100644 --- a/test/testdata/testRunnerGeneratorSmall.c +++ b/test/testdata/testRunnerGeneratorSmall.c @@ -16,7 +16,7 @@ TEST_FILE("some_file.c") /* Include Passthroughs for Linking Tests */ void putcharSpy(int c) { (void)putchar(c);} -void flushSpy(int 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 a7d622d..4aacbf9 100644 --- a/test/testdata/testRunnerGeneratorWithMocks.c +++ b/test/testdata/testRunnerGeneratorWithMocks.c @@ -25,7 +25,7 @@ /* Include Passthroughs for Linking Tests */ void putcharSpy(int c) { (void)putchar(c);} -void flushSpy(int 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 7be7f2b..136cd2f 100644 --- a/test/tests/testparameterized.c +++ b/test/tests/testparameterized.c @@ -13,7 +13,7 @@ /* Include Passthroughs for Linking Tests */ void putcharSpy(int c) { (void)putchar(c);} -void flushSpy(int c) {} +void flushSpy(void) {} #define EXPECT_ABORT_BEGIN \ if (TEST_PROTECT()) \ From 2480a6124e6ace123041bbdaa14b0f42bcefafe1 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 17:08:49 +0100 Subject: [PATCH 7/9] Added unit test for the call to flush --- test/tests/testunity.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 0f74bc5..5258b6e 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -56,7 +56,7 @@ char* getBufferPutcharSpy(void); void startFlushSpy(void); void endFlushSpy(void); -unsigned int getFlushSpyCalls(void); +int getFlushSpyCalls(void); static int SetToOneToFailInTearDown; static int SetToOneMeanWeAlreadyCheckedThisGuy; @@ -3341,11 +3341,11 @@ void putcharSpy(int c) /* This is for counting the calls to the flushSpy */ static int flushSpyEnabled; -static unsigned int flushSpyCalls = 0; +static int flushSpyCalls = 0; void startFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 1; } void endFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 0; } -unsigned int getFlushSpyCalls(void) { return flushSpyCalls; } +int getFlushSpyCalls(void) { return flushSpyCalls; } void flushSpy(void) { @@ -3357,9 +3357,13 @@ 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); + TEST_ASSERT_EQUAL(1, getFlushSpyCalls()); + endFlushSpy(); startPutcharSpy(); // Suppress output int failures = UnityEnd(); From 436a46d8efea78c23b6fe163214a30ff2bb10f51 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 17:43:08 +0100 Subject: [PATCH 8/9] Got the tests running --- test/Makefile | 1 + test/tests/testunity.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/test/Makefile b/test/Makefile index 89ece81..f3981bd 100644 --- a/test/Makefile +++ b/test/Makefile @@ -17,6 +17,7 @@ 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 += -D USING_FLUSH_SPY 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/tests/testunity.c b/test/tests/testunity.c index 5258b6e..e05b2ba 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -3357,13 +3357,17 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void) UNITY_UINT savedFailures = Unity.TestFailures; Unity.CurrentTestFailed = 1; startPutcharSpy(); // Suppress output +#ifdef USING_FLUSH_SPY startFlushSpy(); TEST_ASSERT_EQUAL(0, getFlushSpyCalls()); +#endif UnityConcludeTest(); endPutcharSpy(); TEST_ASSERT_EQUAL(savedFailures + 1, Unity.TestFailures); +#ifdef USING_FLUSH_SPY TEST_ASSERT_EQUAL(1, getFlushSpyCalls()); endFlushSpy(); +#endif startPutcharSpy(); // Suppress output int failures = UnityEnd(); From e038ae2ade1e9436322a92a043d3a5abf3866a6e Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 18:44:58 +0100 Subject: [PATCH 9/9] Refactored the test evaluation of the flushSpy --- test/Makefile | 1 - test/tests/testunity.c | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test/Makefile b/test/Makefile index f3981bd..89ece81 100644 --- a/test/Makefile +++ b/test/Makefile @@ -17,7 +17,6 @@ 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 += -D USING_FLUSH_SPY 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/tests/testunity.c b/test/tests/testunity.c index e05b2ba..95c8280 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -3357,17 +3357,17 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void) UNITY_UINT savedFailures = Unity.TestFailures; Unity.CurrentTestFailed = 1; startPutcharSpy(); // Suppress output -#ifdef USING_FLUSH_SPY startFlushSpy(); TEST_ASSERT_EQUAL(0, getFlushSpyCalls()); -#endif UnityConcludeTest(); endPutcharSpy(); TEST_ASSERT_EQUAL(savedFailures + 1, Unity.TestFailures); -#ifdef USING_FLUSH_SPY +#if defined(UNITY_OUTPUT_FLUSH) && defined(UNITY_OUTPUT_FLUSH_HEADER_DECLARATION) TEST_ASSERT_EQUAL(1, getFlushSpyCalls()); - endFlushSpy(); +#else + TEST_ASSERT_EQUAL(0, getFlushSpyCalls()); #endif + endFlushSpy(); startPutcharSpy(); // Suppress output int failures = UnityEnd();