From 5cc5e3473d19edbeec1e83b99dc463295740225d Mon Sep 17 00:00:00 2001 From: jsalling Date: Fri, 18 Dec 2015 17:50:32 -0600 Subject: [PATCH] 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 } -- GitLab