From 8c37d7b98a9ddc9abcf953fb16e771cbe5b8afc0 Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Wed, 13 Apr 2016 11:33:57 +0200 Subject: [PATCH 1/3] Fix #182, remove redundant function declarations --- src/unity.c | 8 -------- test/Makefile | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/unity.c b/src/unity.c index e281d6a..b398b3f 100644 --- a/src/unity.c +++ b/src/unity.c @@ -67,9 +67,6 @@ const _U_UINT UnitySizeMask[] = #endif }; -void UnityPrintFail(void); -void UnityPrintOk(void); - //----------------------------------------------- // Pretty Printers & Test Result Output Handlers //----------------------------------------------- @@ -1261,8 +1258,6 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) //----------------------------------------------- #if defined(UNITY_WEAK_ATTRIBUTE) - void setUp(void); - void tearDown(void); UNITY_WEAK_ATTRIBUTE void setUp(void) { } UNITY_WEAK_ATTRIBUTE void tearDown(void) { } #elif defined(UNITY_WEAK_PRAGMA) @@ -1270,9 +1265,6 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) void setUp(void) { } # pragma weak tearDown void tearDown(void) { } -#else - void setUp(void); - void tearDown(void); #endif //----------------------------------------------- void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum) diff --git a/test/Makefile b/test/Makefile index ef44540..8ae752c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,7 +3,7 @@ ifeq ($(shell uname -s), Darwin) CC = clang endif #DEBUG = -O0 -g -CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror +CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror -Wredundant-decls CFLAGS += $(DEBUG) DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy -D UNITY_INCLUDE_DOUBLE SRC = ../src/unity.c tests/testunity.c build/testunityRunner.c From a27b03c79a63d518b2a98cfd324aa54e83b49c3d Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Wed, 13 Apr 2016 12:19:04 +0200 Subject: [PATCH 2/3] UNITY_OUTPUT_CHAR can emit a redundant declaration, we scope the extern declartion to the unity.c --- src/unity.c | 5 +++++ src/unity_internals.h | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/unity.c b/src/unity.c index b398b3f..8541274 100644 --- a/src/unity.c +++ b/src/unity.c @@ -7,6 +7,11 @@ #include "unity.h" #include +#ifndef UNITY_OUTPUT_CHAR_USE_PUTC +//If defined as something else, make sure we declare it here so it's ready for use +extern int UNITY_OUTPUT_CHAR(int); +#endif + #define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; longjmp(Unity.AbortFrame, 1); } #define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; longjmp(Unity.AbortFrame, 1); } /// return prematurely if we are already in failure or ignore state diff --git a/src/unity_internals.h b/src/unity_internals.h index 6549656..81058be 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -291,9 +291,12 @@ typedef UNITY_DOUBLE_TYPE _UD; //Default to using putchar, which is defined in stdio.h #include #define UNITY_OUTPUT_CHAR(a) putchar(a) -#else -//If defined as something else, make sure we declare it here so it's ready for use -extern int UNITY_OUTPUT_CHAR(int); +// We need to flag the output char function uses putc in +// unity.c the extern function is not declared then. +// Previously the extern was declared in this header but +// when redundant function declaration compiler flag is enabled +// it wont compile. +#define UNITY_OUTPUT_CHAR_USE_PUTC #endif #ifndef UNITY_PRINT_EOL From 720ea42a82b65aa5165aef09259e0323e1ef7c4b Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Wed, 13 Apr 2016 12:59:31 +0200 Subject: [PATCH 3/3] tests/testunity.c: Fix after redundant declarations fix --- test/tests/testunity.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 9fae64e..77eeb21 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -8,6 +8,8 @@ #include "unity.h" #include +int putcharSpy(int c); + // Dividing by these constants produces +/- infinity. // The rationale is given in UnityAssertFloatIsInf's body. #ifndef UNITY_EXCLUDE_FLOAT