Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion auto/generate_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ def create_header(output, mocks, testfile_includes = [])
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
create_runtest(output, mocks)
output.puts("\n/*=======Automagically Detected Files To Include=====*/")
output.puts('#define UNITY_INCLUDE_SETUP_STUBS') if @options[:suite_setup].nil?
output.puts("#include \"#{@options[:framework]}.h\"")
output.puts('#ifdef _WIN32')
output.puts("#include \"#{@options[:framework]}_setup_stubs.h\"")
output.puts('#endif')
output.puts('#include "cmock.h"') unless mocks.empty?
output.puts('#ifndef UNITY_EXCLUDE_SETJMP_H')
output.puts('#include <setjmp.h>')
Expand Down
1 change: 1 addition & 0 deletions src/unity.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
============================================================================ */

#include "unity.h"
#include "unity_setup_stubs.h"
#include <stddef.h>

#ifdef AVR
Expand Down
24 changes: 2 additions & 22 deletions src/unity.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,8 @@ void tearDown(void);
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
/* Stubs of the above four functions are provided as weak symbols in
* unity_setup_stubs.h. */

/*-------------------------------------------------------
* Configuration Options
Expand Down
46 changes: 46 additions & 0 deletions src/unity_setup_stubs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* ==========================================
Unity Project - A Test Framework for C
Copyright (c) 2007-19 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */

#ifndef UNITY_SETUP_STUBS_H
#define UNITY_SETUP_STUBS_H

#include "unity.h"

/* If the compiler supports it, this header provides stub implementations
* of the following functions as weak symbols:
*
* - setUp()
* - tearDown()
* - suiteSetUp()
* - suiteTearDown()
*
* This header is always included by unity.c, which is sufficient when
* targeting GNU/Linux and other ELF targets. On some other platforms
* (MinGW for example), weak function implementations need to be in the
* same translation unit they are called from, so this header is also
* included by each generated test runner.
*
* If neither UNITY_WEAK_ATTRIBUTE nor UNITY_WEAK_PRAGMA is defined, the
* compiler is assumed to have no support for weak symbols, and this
* header has no effect. */

#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