From 5cc5e3473d19edbeec1e83b99dc463295740225d Mon Sep 17 00:00:00 2001 From: jsalling Date: Fri, 18 Dec 2015 17:50:32 -0600 Subject: [PATCH 1/2] Add MACROs to check if tests are built using the Output Spy Ignore tests that need the Spy if we are not building with it --- extras/fixture/test/unity_fixture_Test.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/extras/fixture/test/unity_fixture_Test.c b/extras/fixture/test/unity_fixture_Test.c index 238be5f..f7570e8 100644 --- a/extras/fixture/test/unity_fixture_Test.c +++ b/extras/fixture/test/unity_fixture_Test.c @@ -308,8 +308,17 @@ TEST_TEAR_DOWN(LeakDetection) memcpy(Unity.AbortFrame, TestAbortFrame, sizeof(jmp_buf)); \ } +// This tricky set of defines lets us see if we are using the Spy, returns 1 if true, else 0 +#define USING_OUTPUT_SPY(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0) +#define ASSIGN_VALUE(a) VAL_FUNC_##a +#define VAL_FUNC_UnityOutputCharSpy_OutputChar() 0, 1 +#define EXPAND_AND_USE_2ND(a, b) SECOND_PARAM(a, b) +#define SECOND_PARAM(a, b, ...) b TEST(LeakDetection, DetectsLeak) { +#if USING_OUTPUT_SPY(UNITY_OUTPUT_CHAR()) == 0 + TEST_IGNORE_MESSAGE("Build with '-D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar' to enable tests"); +#else void* m = malloc(10); UnityOutputCharSpy_Enable(1); EXPECT_ABORT_BEGIN @@ -319,10 +328,15 @@ TEST(LeakDetection, DetectsLeak) Unity.CurrentTestFailed = 0; CHECK(strstr(UnityOutputCharSpy_Get(), "This test leaks!")); free(m); +#endif } TEST(LeakDetection, BufferOverrunFoundDuringFree) { +#if USING_OUTPUT_SPY(UNITY_OUTPUT_CHAR()) == 0 + UNITY_PRINT_EOL(); + TEST_IGNORE(); +#else void* m = malloc(10); char* s = (char*)m; s[10] = (char)0xFF; @@ -333,10 +347,15 @@ TEST(LeakDetection, BufferOverrunFoundDuringFree) UnityOutputCharSpy_Enable(0); Unity.CurrentTestFailed = 0; CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()")); +#endif } TEST(LeakDetection, BufferOverrunFoundDuringRealloc) { +#if USING_OUTPUT_SPY(UNITY_OUTPUT_CHAR()) == 0 + UNITY_PRINT_EOL(); + TEST_IGNORE(); +#else void* m = malloc(10); char* s = (char*)m; s[10] = (char)0xFF; @@ -347,4 +366,5 @@ TEST(LeakDetection, BufferOverrunFoundDuringRealloc) UnityOutputCharSpy_Enable(0); Unity.CurrentTestFailed = 0; CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()")); +#endif } From c5bfe0e1009d03e59f9b47041f178e07b3b4e966 Mon Sep 17 00:00:00 2001 From: jsalling Date: Tue, 22 Dec 2015 12:40:31 -0600 Subject: [PATCH 2/2] Fixture C99 compliance on tricky macros for Spy & match core Unity version Add CFLAGS in Fixture Makefile to catch C99 rules with '-pedantic' --- extras/fixture/test/Makefile | 8 ++++++-- extras/fixture/test/unity_fixture_Test.c | 13 ++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/extras/fixture/test/Makefile b/extras/fixture/test/Makefile index fe1d530..04ec722 100644 --- a/extras/fixture/test/Makefile +++ b/extras/fixture/test/Makefile @@ -1,4 +1,8 @@ CC = gcc +CFLAGS += -Werror +CFLAGS += -std=c99 +CFLAGS += -pedantic +CFLAGS += -Wundef DEFINES = -D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar SRC = ../src/unity_fixture.c \ ../../../src/unity.c \ @@ -11,5 +15,5 @@ INC_DIR = -I../src -I../../../src/ TARGET = fixture_tests.exe all: - @ $(CC) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) - @ ./$(TARGET) + $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) + ./$(TARGET) diff --git a/extras/fixture/test/unity_fixture_Test.c b/extras/fixture/test/unity_fixture_Test.c index f7570e8..667f1f1 100644 --- a/extras/fixture/test/unity_fixture_Test.c +++ b/extras/fixture/test/unity_fixture_Test.c @@ -309,14 +309,17 @@ TEST_TEAR_DOWN(LeakDetection) } // This tricky set of defines lets us see if we are using the Spy, returns 1 if true, else 0 -#define USING_OUTPUT_SPY(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0) +#define USING_SPY_AS(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0) #define ASSIGN_VALUE(a) VAL_FUNC_##a #define VAL_FUNC_UnityOutputCharSpy_OutputChar() 0, 1 -#define EXPAND_AND_USE_2ND(a, b) SECOND_PARAM(a, b) +#define EXPAND_AND_USE_2ND(a, b) SECOND_PARAM(a, b, throwaway) #define SECOND_PARAM(a, b, ...) b +#if USING_SPY_AS(UNITY_OUTPUT_CHAR()) + #define USING_OUTPUT_SPY +#endif TEST(LeakDetection, DetectsLeak) { -#if USING_OUTPUT_SPY(UNITY_OUTPUT_CHAR()) == 0 +#ifndef USING_OUTPUT_SPY TEST_IGNORE_MESSAGE("Build with '-D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar' to enable tests"); #else void* m = malloc(10); @@ -333,7 +336,7 @@ TEST(LeakDetection, DetectsLeak) TEST(LeakDetection, BufferOverrunFoundDuringFree) { -#if USING_OUTPUT_SPY(UNITY_OUTPUT_CHAR()) == 0 +#ifndef USING_OUTPUT_SPY UNITY_PRINT_EOL(); TEST_IGNORE(); #else @@ -352,7 +355,7 @@ TEST(LeakDetection, BufferOverrunFoundDuringFree) TEST(LeakDetection, BufferOverrunFoundDuringRealloc) { -#if USING_OUTPUT_SPY(UNITY_OUTPUT_CHAR()) == 0 +#ifndef USING_OUTPUT_SPY UNITY_PRINT_EOL(); TEST_IGNORE(); #else