diff --git a/extras/fixture/src/unity_fixture_internals.h b/extras/fixture/src/unity_fixture_internals.h index 1fdbb9893dac8d7275b2453e195598280ca974d7..daeebb338ad5175ef29a84a24bad16fafc0e9517 100644 --- a/extras/fixture/src/unity_fixture_internals.h +++ b/extras/fixture/src/unity_fixture_internals.h @@ -15,6 +15,7 @@ struct _UnityFixture const char* NameFilter; const char* GroupFilter; }; +extern struct _UnityFixture UnityFixture; typedef void unityfunction(void); void UnityTestRunner(unityfunction* setup, diff --git a/extras/fixture/test/Makefile b/extras/fixture/test/Makefile index f3f7ab1bc3bc8f70e2d912b384dcb3c2f5dde065..6e096ae088dcee1e00b72bb9fdd252456a400b33 100644 --- a/extras/fixture/test/Makefile +++ b/extras/fixture/test/Makefile @@ -34,6 +34,11 @@ noStdlibMalloc: ../build/ @ echo "build with noStdlibMalloc" ./$(TARGET) +clang89: ../build/ + clang $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -m32 -std=c89 -Wno-comment + clang $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -m32 \ + -D UNITY_EXCLUDE_STDLIB_MALLOC -std=c89 -Wno-comment ; ./$(TARGET) + clangEverything: clang $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -m64 -Weverything @@ -56,5 +61,6 @@ CFLAGS += -Wstrict-overflow=5 CFLAGS += -Wstrict-prototypes CFLAGS += -Wswitch-default CFLAGS += -Wundef +CFLAGS += -Wno-error=undef # Warning only, this should not stop the build CFLAGS += -Wunused CFLAGS += -fstrict-aliasing diff --git a/extras/fixture/test/unity_fixture_Test.c b/extras/fixture/test/unity_fixture_Test.c index 07178d6b73d582c40a0c2904d50fb4657cf48bcd..25249464aaf13eda028083dc17825574b513b1db 100644 --- a/extras/fixture/test/unity_fixture_Test.c +++ b/extras/fixture/test/unity_fixture_Test.c @@ -10,8 +10,6 @@ #include #include -extern struct _UnityFixture UnityFixture; - TEST_GROUP(UnityFixture); TEST_SETUP(UnityFixture) @@ -314,6 +312,9 @@ TEST_TEAR_DOWN(LeakDetection) } // This tricky set of defines lets us see if we are using the Spy, returns 1 if true +#ifdef __STDC_VERSION__ + +#if __STDC_VERSION__ >= 199901L #define USING_SPY_AS(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0) #define ASSIGN_VALUE(a) VAL_##a #define VAL_UnityOutputCharSpy_OutputChar 0, 1 @@ -322,6 +323,16 @@ TEST_TEAR_DOWN(LeakDetection) #if USING_SPY_AS(UNITY_OUTPUT_CHAR) #define USING_OUTPUT_SPY // UNITY_OUTPUT_CHAR = UnityOutputCharSpy_OutputChar #endif +#endif // >= 199901 + +#else // __STDC_VERSION__ else +#define UnityOutputCharSpy_OutputChar 42 +#if UNITY_OUTPUT_CHAR == UnityOutputCharSpy_OutputChar // Works if no -Wundef -Werror + #define USING_OUTPUT_SPY +#endif +#undef UnityOutputCharSpy_OutputChar +#endif // __STDC_VERSION__ + TEST(LeakDetection, DetectsLeak) { #ifndef USING_OUTPUT_SPY @@ -346,8 +357,8 @@ TEST(LeakDetection, BufferOverrunFoundDuringFree) TEST_IGNORE(); #else void* m = malloc(10); - TEST_ASSERT_NOT_NULL(m); char* s = (char*)m; + TEST_ASSERT_NOT_NULL(m); s[10] = (char)0xFF; UnityOutputCharSpy_Enable(1); EXPECT_ABORT_BEGIN @@ -365,8 +376,8 @@ TEST(LeakDetection, BufferOverrunFoundDuringRealloc) TEST_IGNORE(); #else void* m = malloc(10); - TEST_ASSERT_NOT_NULL(m); char* s = (char*)m; + TEST_ASSERT_NOT_NULL(m); s[10] = (char)0xFF; UnityOutputCharSpy_Enable(1); EXPECT_ABORT_BEGIN @@ -384,8 +395,8 @@ TEST(LeakDetection, BufferGuardWriteFoundDuringFree) TEST_IGNORE(); #else void* m = malloc(10); - TEST_ASSERT_NOT_NULL(m); char* s = (char*)m; + TEST_ASSERT_NOT_NULL(m); s[-1] = (char)0x00; // Will not detect 0 s[-2] = (char)0x01; UnityOutputCharSpy_Enable(1); @@ -404,8 +415,8 @@ TEST(LeakDetection, BufferGuardWriteFoundDuringRealloc) TEST_IGNORE(); #else void* m = malloc(10); - TEST_ASSERT_NOT_NULL(m); char* s = (char*)m; + TEST_ASSERT_NOT_NULL(m); s[-1] = (char)0x0A; UnityOutputCharSpy_Enable(1); EXPECT_ABORT_BEGIN @@ -445,8 +456,8 @@ TEST(InternalMalloc, MallocPastBufferFails) { #ifdef UNITY_EXCLUDE_STDLIB_MALLOC void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1); - TEST_ASSERT_NOT_NULL(m); void* n = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2); + TEST_ASSERT_NOT_NULL(m); TEST_ASSERT_NULL(n); free(m); #endif @@ -456,8 +467,8 @@ TEST(InternalMalloc, CallocPastBufferFails) { #ifdef UNITY_EXCLUDE_STDLIB_MALLOC void* m = calloc(1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1); - TEST_ASSERT_NOT_NULL(m); void* n = calloc(1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2); + TEST_ASSERT_NOT_NULL(m); TEST_ASSERT_NULL(n); free(m); #endif @@ -467,8 +478,8 @@ TEST(InternalMalloc, MallocThenReallocGrowsMemoryInPlace) { #ifdef UNITY_EXCLUDE_STDLIB_MALLOC void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1); - TEST_ASSERT_NOT_NULL(m); void* n = realloc(m, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 9); + TEST_ASSERT_NOT_NULL(m); TEST_ASSERT_EQUAL(m, n); free(n); #endif @@ -478,11 +489,11 @@ TEST(InternalMalloc, ReallocFailDoesNotFreeMem) { #ifdef UNITY_EXCLUDE_STDLIB_MALLOC void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2); - TEST_ASSERT_NOT_NULL(m); void* n1 = malloc(10); void* out_of_mem = realloc(n1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1); - TEST_ASSERT_NULL(out_of_mem); void* n2 = malloc(10); + TEST_ASSERT_NOT_NULL(m); + TEST_ASSERT_NULL(out_of_mem); TEST_ASSERT_NOT_EQUAL(n2, n1); free(n2); free(n1); diff --git a/src/unity_internals.h b/src/unity_internals.h index 90cac977b18d32dd7bbf70724edb43c502c32fac..b6f1061005f74b3f1c3a873d84797ae866ec17a5 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -396,7 +396,7 @@ typedef enum _UNITY_FLOAT_TRAIT_T UNITY_FLOAT_IS_NOT_NAN, UNITY_FLOAT_IS_NAN, UNITY_FLOAT_IS_NOT_DET, - UNITY_FLOAT_IS_DET, + UNITY_FLOAT_IS_DET } UNITY_FLOAT_TRAIT_T; #endif