Add config option that allows for weak mocked functions

This commit is contained in:
Stein Heselmans
2016-10-14 13:43:02 +02:00
parent 9f1ae5e2a5
commit 6c8054dc34
4 changed files with 16 additions and 1 deletions
+3
View File
@@ -287,6 +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.
* `:subdir`:
Relative subdir for your mocks. Set this to e.g. "sys" in order to
create mock for `sys/types.h` in `:mock_path`/sys/
+1
View File
@@ -12,6 +12,7 @@ class CMockConfig
:mock_path => 'mocks',
:mock_prefix => 'Mock',
:mock_suffix => '',
:weak_mocks => false,
:subdir => nil,
:plugins => [],
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
+5 -1
View File
@@ -6,7 +6,7 @@
class CMockGenerator
attr_accessor :config, :file_writer, :module_name, :clean_mock_name, :mock_name, :utils, :plugins, :ordered
attr_accessor :config, :file_writer, :module_name, :clean_mock_name, :mock_name, :utils, :plugins, :weak, :ordered
def initialize(config, file_writer, utils, plugins)
@file_writer = file_writer
@@ -15,6 +15,7 @@ class CMockGenerator
@config = config
@prefix = @config.mock_prefix
@suffix = @config.mock_suffix
@weak = @config.weak_mocks
@ordered = @config.enforce_strict_ordering
@framework = @config.framework.to_s
@@ -206,6 +207,9 @@ 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"
end
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string})\n"
file << "{\n"
file << " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n"
+7
View File
@@ -44,6 +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 :enforce_strict_ordering, nil
@config.expect :framework, :unity
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"]
@@ -60,6 +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 :enforce_strict_ordering, true
@config.expect :framework, :unity
@config.expect :includes, nil
@@ -80,6 +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
orig_filename = "PoutPoutFish.h"
define_name = "MOCKPOUTPOUTFISH_H"
mock_name = "MockPoutPoutFish"
@@ -116,6 +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 :enforce_strict_ordering, nil
@config.expect :framework, :unity
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"]
@@ -130,6 +134,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
@config.expect :mock_prefix, "Mock"
@config.expect :mock_suffix, ""
@config.expect :weak_mocks, false
orig_filename = "Pout-Pout Fish.h"
define_name = "MOCKPOUT_POUT_FISH_H"
mock_name = "MockPout_Pout_Fish"
@@ -165,6 +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
orig_filename = "PoutPoutFish.h"
define_name = "MOCKPOUTPOUTFISH_H"
mock_name = "MockPoutPoutFish"
@@ -199,6 +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
orig_filename = "PoutPoutFish.h"
define_name = "MOCKPOUTPOUTFISH_H"
mock_name = "MockPoutPoutFish"