mirror of
https://github.com/ThrowTheSwitch/Unity
synced 2025-05-22 02:19:33 -04:00
Merge pull request #324 from farrrb/origin/fix-UNITY_OUTPUT_FLUSH
Re: Fix custom UNITY_OUTPUT_FLUSH and add tests #287
This commit is contained in:
commit
d915bf7ae5
@ -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`
|
||||
|
@ -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 <stdio.h>
|
||||
#define UNITY_OUTPUT_CHAR(a) (void)putchar(a)
|
||||
/* Default to using putchar, which is defined in stdio.h */
|
||||
#include <stdio.h>
|
||||
#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 <stdio.h>
|
||||
#define UNITY_OUTPUT_FLUSH() (void)fflush(stdout)
|
||||
#ifdef UNITY_USE_FLUSH_STDOUT
|
||||
/* We want to use the stdout flush utility */
|
||||
#include <stdio.h>
|
||||
#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
|
||||
|
@ -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
|
||||
|
5
test/testdata/testRunnerGenerator.c
vendored
5
test/testdata/testRunnerGenerator.c
vendored
@ -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;
|
||||
|
5
test/testdata/testRunnerGeneratorSmall.c
vendored
5
test/testdata/testRunnerGeneratorSmall.c
vendored
@ -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;
|
||||
|
5
test/testdata/testRunnerGeneratorWithMocks.c
vendored
5
test/testdata/testRunnerGeneratorWithMocks.c
vendored
@ -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;
|
||||
|
@ -8,10 +8,13 @@
|
||||
#include <stdio.h>
|
||||
#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()) \
|
||||
{
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user