From 629b86d5412e3a6768987610c67172de0eff538d Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 1 Nov 2017 11:36:26 -0400 Subject: [PATCH] Merge unity_setup.h into unity.h. --- auto/generate_test_runner.rb | 4 ++-- src/unity.c | 2 +- src/unity.h | 35 +++++++++++++++++++++++++++++------ src/unity_setup.h | 33 --------------------------------- 4 files changed, 32 insertions(+), 42 deletions(-) delete mode 100644 src/unity_setup.h diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index b049bca..344a2d0 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -157,10 +157,10 @@ class UnityTestRunnerGenerator output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */') create_runtest(output, mocks) output.puts("\n/*=======Automagically Detected Files To Include=====*/") - output.puts("#include \"#{@options[:framework]}.h\"") output.puts('#ifdef __WIN32__') - output.puts("#include \"#{@options[:framework]}_setup.h\"") + output.puts('#define UNITY_INCLUDE_SETUP_STUBS') output.puts('#endif') + output.puts("#include \"#{@options[:framework]}.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 739358f..ab1e2fd 100644 --- a/src/unity.c +++ b/src/unity.c @@ -4,8 +4,8 @@ [Released under MIT License. Please refer to license.txt for details] ============================================================================ */ +#define UNITY_INCLUDE_SETUP_STUBS #include "unity.h" -#include "unity_setup.h" #include /* If omitted from header, declare overrideable prototypes here so they're ready for use */ diff --git a/src/unity.h b/src/unity.h index 1fa8b94..d95f1c1 100644 --- a/src/unity.h +++ b/src/unity.h @@ -15,20 +15,43 @@ extern "C" #include "unity_internals.h" -/* These functions are intended to be called before and after each test. Unity - * provides stub implementations annotated as weak symbols (if supported by the - * compiler). */ +/*------------------------------------------------------- + * Test Setup / Teardown + *-------------------------------------------------------*/ + +/* These functions are intended to be called before and after each test. */ void setUp(void); void tearDown(void); /* These functions are intended to be called at the beginning and end of an * entire test suite. suiteTearDown() is passed the number of tests that - * failed, and its return value becomes the exit code of main(). Unity - * provides stub implementations annotated as weak symbols (if supported by the - * compiler). */ + * failed, and its return value becomes the exit code of main(). */ void suiteSetUp(void); int suiteTearDown(int num_failures); +/* If the compiler supports it, the following block provides stub + * implementations of the above functions as weak symbols. Note that on + * some platforms (MinGW for example), weak function implementations need + * to be in the same translation unit they are called from. This can be + * achieved by defining UNITY_INCLUDE_SETUP_STUBS before including unity.h. */ +#ifdef UNITY_INCLUDE_SETUP_STUBS + #ifdef 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 + /*------------------------------------------------------- * Configuration Options *------------------------------------------------------- diff --git a/src/unity_setup.h b/src/unity_setup.h deleted file mode 100644 index 4672b76..0000000 --- a/src/unity_setup.h +++ /dev/null @@ -1,33 +0,0 @@ -/* ========================================== - 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