mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-05 10:47:49 +00:00
More configuration options for weak symbols
This commit is contained in:
@@ -287,8 +287,9 @@ Defined in the yaml file, they look more like this:
|
||||
* `:mock_suffix`:
|
||||
The suffix to append to your mock files. Defaults to “”.
|
||||
|
||||
* `:weak_mocks`:
|
||||
When set to true, the generated mocks are defined as weak symbols. Defaults to false.
|
||||
* `:weak`:
|
||||
When set to some value, the generated mocks are defined as weak symbols using the configured format. Defaults to ''.
|
||||
Set to '__attribute ((weak))' for weak mocks when using GCC. Set to any non-empty string for weak mocks when using IAR.
|
||||
|
||||
* `:subdir`:
|
||||
Relative subdir for your mocks. Set this to e.g. "sys" in order to
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ class CMockConfig
|
||||
:mock_path => 'mocks',
|
||||
:mock_prefix => 'Mock',
|
||||
:mock_suffix => '',
|
||||
:weak_mocks => false,
|
||||
:weak => '',
|
||||
:subdir => nil,
|
||||
:plugins => [],
|
||||
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
|
||||
|
||||
@@ -15,7 +15,7 @@ class CMockGenerator
|
||||
@config = config
|
||||
@prefix = @config.mock_prefix
|
||||
@suffix = @config.mock_suffix
|
||||
@weak = @config.weak_mocks
|
||||
@weak = @config.weak
|
||||
@ordered = @config.enforce_strict_ordering
|
||||
@framework = @config.framework.to_s
|
||||
|
||||
@@ -207,8 +207,12 @@ class CMockGenerator
|
||||
args_string += (", " + function[:var_arg]) unless (function[:var_arg].nil?)
|
||||
|
||||
# Create mock function
|
||||
if (@weak)
|
||||
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string}) __attribute ((weak));\n"
|
||||
if (not @weak.empty?)
|
||||
file << "#if defined (__IAR_SYSTEMS_ICC__)\n"
|
||||
file << "#pragma weak #{function[:name]}\n"
|
||||
file << "#else\n"
|
||||
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string}) #{weak};\n"
|
||||
file << "#endif\n\n"
|
||||
end
|
||||
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string})\n"
|
||||
file << "{\n"
|
||||
|
||||
@@ -44,7 +44,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
#no strict handling
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak_mocks, false
|
||||
@config.expect :weak, ""
|
||||
@config.expect :enforce_strict_ordering, nil
|
||||
@config.expect :framework, :unity
|
||||
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"]
|
||||
@@ -61,7 +61,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
#strict handling
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak_mocks, false
|
||||
@config.expect :weak, ""
|
||||
@config.expect :enforce_strict_ordering, true
|
||||
@config.expect :framework, :unity
|
||||
@config.expect :includes, nil
|
||||
@@ -82,7 +82,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
it "create the top of a header file with optional include files from config and include file from plugin" do
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak_mocks, false
|
||||
@config.expect :weak, ""
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
mock_name = "MockPoutPoutFish"
|
||||
@@ -119,7 +119,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
#no strict handling
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak_mocks, false
|
||||
@config.expect :weak, ""
|
||||
@config.expect :enforce_strict_ordering, nil
|
||||
@config.expect :framework, :unity
|
||||
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"]
|
||||
@@ -134,7 +134,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak_mocks, false
|
||||
@config.expect :weak, ""
|
||||
orig_filename = "Pout-Pout Fish.h"
|
||||
define_name = "MOCKPOUT_POUT_FISH_H"
|
||||
mock_name = "MockPout_Pout_Fish"
|
||||
@@ -170,7 +170,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
it "create the top of a header file with optional include files from config" do
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak_mocks, false
|
||||
@config.expect :weak, ""
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
mock_name = "MockPoutPoutFish"
|
||||
@@ -205,7 +205,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
it "create the top of a header file with include file from plugin" do
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak_mocks, false
|
||||
@config.expect :weak, ""
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
mock_name = "MockPoutPoutFish"
|
||||
|
||||
Reference in New Issue
Block a user