diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index edb79894208fc79a5748426f449f3c238481b41d..f436634f3715cec21dd6df794c3f7142ef2af4e3 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -158,6 +158,7 @@ class UnityTestRunnerGenerator create_runtest(output, mocks) output.puts("\n/*=======Automagically Detected Files To Include=====*/") output.puts("#include \"#{@options[:framework]}.h\"") + output.puts("#include \"#{@options[:framework]}_setup.h\"") output.puts('#include "cmock.h"') unless mocks.empty? output.puts('#include ') output.puts('#include ') diff --git a/src/unity.c b/src/unity.c index 08ecf63aa42aba2190ecfa88d5e5bc2db3fe5e3b..739358f2afb42b2435283c6bcd09f60b19e0ed06 100644 --- a/src/unity.c +++ b/src/unity.c @@ -5,6 +5,7 @@ ============================================================================ */ #include "unity.h" +#include "unity_setup.h" #include /* If omitted from header, declare overrideable prototypes here so they're ready for use */ @@ -1310,23 +1311,6 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) UNITY_IGNORE_AND_BAIL; } -/*-----------------------------------------------*/ -#if defined(UNITY_WEAK_ATTRIBUTE) - UNITY_WEAK_ATTRIBUTE void setUp(void) { } - UNITY_WEAK_ATTRIBUTE void tearDown(void) { } - UNITY_WEAK_ATTRIBUTE void suiteSetUp(void) { } - UNITY_WEAK_ATTRIBUTE int suiteTearDown(int num_failures) { return num_failures; } -#elif defined(UNITY_WEAK_PRAGMA) - #pragma weak setUp - void setUp(void) { } - #pragma weak tearDown - void tearDown(void) { } - #pragma weak suiteSetUp - void suiteSetUp(void) { } - #pragma weak suiteTearDown - int suiteTearDown(int num_failures) { return num_failures; } -#endif - /*-----------------------------------------------*/ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum) { diff --git a/src/unity_setup.h b/src/unity_setup.h new file mode 100644 index 0000000000000000000000000000000000000000..4672b76cac811fccf5cff55b188562b1b7539746 --- /dev/null +++ b/src/unity_setup.h @@ -0,0 +1,33 @@ +/* ========================================== + Unity Project - A Test Framework for C + Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams + [Released under MIT License. Please refer to license.txt for details] +========================================== */ + +#ifndef UNITY_SETUP_H +#define UNITY_SETUP_H + +#include "unity_internals.h" + +/* On some platforms (MinGW for example), weak function implementations + * need to be in the same translation unit they are called from. This + * header can be included to provide implementations of setUp(), tearDown(), + * suiteSetUp(), and suiteTearDown(). */ + +#if defined(UNITY_WEAK_ATTRIBUTE) + UNITY_WEAK_ATTRIBUTE void setUp(void) { } + UNITY_WEAK_ATTRIBUTE void tearDown(void) { } + UNITY_WEAK_ATTRIBUTE void suiteSetUp(void) { } + UNITY_WEAK_ATTRIBUTE int suiteTearDown(int num_failures) { return num_failures; } +#elif defined(UNITY_WEAK_PRAGMA) + #pragma weak setUp + void setUp(void) { } + #pragma weak tearDown + void tearDown(void) { } + #pragma weak suiteSetUp + void suiteSetUp(void) { } + #pragma weak suiteTearDown + int suiteTearDown(int num_failures) { return num_failures; } +#endif + +#endif