mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-10-02 06:57:35 +00:00
Merge pull request #73 from SteinHeselmans/master
add mock_suffix configuration option
This commit is contained in:
@@ -284,6 +284,9 @@ Defined in the yaml file, they look more like this:
|
|||||||
The prefix to append to your mock files. Defaults to “Mock”, so a file
|
The prefix to append to your mock files. Defaults to “Mock”, so a file
|
||||||
“USART.h” will get a mock called “MockUSART.c”
|
“USART.h” will get a mock called “MockUSART.c”
|
||||||
|
|
||||||
|
* `:mock_suffix`:
|
||||||
|
The suffix to append to your mock files. Defaults to “”.
|
||||||
|
|
||||||
* `:subdir`:
|
* `:subdir`:
|
||||||
Relative subdir for your mocks. Set this to e.g. "sys" in order to
|
Relative subdir for your mocks. Set this to e.g. "sys" in order to
|
||||||
create mock for `sys/types.h` in `:mock_path`/sys/
|
create mock for `sys/types.h` in `:mock_path`/sys/
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class CMockConfig
|
|||||||
:framework => :unity,
|
:framework => :unity,
|
||||||
:mock_path => 'mocks',
|
:mock_path => 'mocks',
|
||||||
:mock_prefix => 'Mock',
|
:mock_prefix => 'Mock',
|
||||||
|
:mock_suffix => '',
|
||||||
:subdir => nil,
|
:subdir => nil,
|
||||||
:plugins => [],
|
:plugins => [],
|
||||||
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
|
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class CMockGenerator
|
|||||||
@plugins = plugins
|
@plugins = plugins
|
||||||
@config = config
|
@config = config
|
||||||
@prefix = @config.mock_prefix
|
@prefix = @config.mock_prefix
|
||||||
|
@suffix = @config.mock_suffix
|
||||||
@ordered = @config.enforce_strict_ordering
|
@ordered = @config.enforce_strict_ordering
|
||||||
@framework = @config.framework.to_s
|
@framework = @config.framework.to_s
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ class CMockGenerator
|
|||||||
|
|
||||||
def create_mock(module_name, parsed_stuff)
|
def create_mock(module_name, parsed_stuff)
|
||||||
@module_name = module_name
|
@module_name = module_name
|
||||||
@mock_name = @prefix + @module_name
|
@mock_name = @prefix + @module_name + @suffix
|
||||||
@clean_mock_name = TypeSanitizer.sanitize_c_identifier(@mock_name)
|
@clean_mock_name = TypeSanitizer.sanitize_c_identifier(@mock_name)
|
||||||
create_mock_subdir()
|
create_mock_subdir()
|
||||||
create_mock_header_file(parsed_stuff)
|
create_mock_header_file(parsed_stuff)
|
||||||
@@ -83,7 +84,7 @@ class CMockGenerator
|
|||||||
|
|
||||||
def create_mock_header_header(file, filename)
|
def create_mock_header_header(file, filename)
|
||||||
define_name = @clean_mock_name.upcase
|
define_name = @clean_mock_name.upcase
|
||||||
orig_filename = (@subdir ? @subdir + "/" : "") + filename[@config.mock_prefix.size..-1]
|
orig_filename = (@subdir ? @subdir + "/" : "") + @module_name + ".h"
|
||||||
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
|
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
|
||||||
file << "#ifndef _#{define_name}_H\n"
|
file << "#ifndef _#{define_name}_H\n"
|
||||||
file << "#define _#{define_name}_H\n\n"
|
file << "#define _#{define_name}_H\n\n"
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
|||||||
|
|
||||||
#no strict handling
|
#no strict handling
|
||||||
@config.expect :mock_prefix, "Mock"
|
@config.expect :mock_prefix, "Mock"
|
||||||
|
@config.expect :mock_suffix, ""
|
||||||
@config.expect :enforce_strict_ordering, nil
|
@config.expect :enforce_strict_ordering, nil
|
||||||
@config.expect :framework, :unity
|
@config.expect :framework, :unity
|
||||||
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"]
|
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"]
|
||||||
@@ -58,6 +59,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
|||||||
|
|
||||||
#strict handling
|
#strict handling
|
||||||
@config.expect :mock_prefix, "Mock"
|
@config.expect :mock_prefix, "Mock"
|
||||||
|
@config.expect :mock_suffix, ""
|
||||||
@config.expect :enforce_strict_ordering, true
|
@config.expect :enforce_strict_ordering, true
|
||||||
@config.expect :framework, :unity
|
@config.expect :framework, :unity
|
||||||
@config.expect :includes, nil
|
@config.expect :includes, nil
|
||||||
@@ -77,6 +79,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
|
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_prefix, "Mock"
|
||||||
|
@config.expect :mock_suffix, ""
|
||||||
orig_filename = "PoutPoutFish.h"
|
orig_filename = "PoutPoutFish.h"
|
||||||
define_name = "MOCKPOUTPOUTFISH_H"
|
define_name = "MOCKPOUTPOUTFISH_H"
|
||||||
mock_name = "MockPoutPoutFish"
|
mock_name = "MockPoutPoutFish"
|
||||||
@@ -112,6 +115,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
|||||||
it "handle dashes and spaces in the module name" do
|
it "handle dashes and spaces in the module name" do
|
||||||
#no strict handling
|
#no strict handling
|
||||||
@config.expect :mock_prefix, "Mock"
|
@config.expect :mock_prefix, "Mock"
|
||||||
|
@config.expect :mock_suffix, ""
|
||||||
@config.expect :enforce_strict_ordering, nil
|
@config.expect :enforce_strict_ordering, nil
|
||||||
@config.expect :framework, :unity
|
@config.expect :framework, :unity
|
||||||
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"]
|
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"]
|
||||||
@@ -125,6 +129,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
|||||||
@cmock_generator2.clean_mock_name = "MockPout_Pout_Fish"
|
@cmock_generator2.clean_mock_name = "MockPout_Pout_Fish"
|
||||||
|
|
||||||
@config.expect :mock_prefix, "Mock"
|
@config.expect :mock_prefix, "Mock"
|
||||||
|
@config.expect :mock_suffix, ""
|
||||||
orig_filename = "Pout-Pout Fish.h"
|
orig_filename = "Pout-Pout Fish.h"
|
||||||
define_name = "MOCKPOUT_POUT_FISH_H"
|
define_name = "MOCKPOUT_POUT_FISH_H"
|
||||||
mock_name = "MockPout_Pout_Fish"
|
mock_name = "MockPout_Pout_Fish"
|
||||||
@@ -159,6 +164,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
|||||||
|
|
||||||
it "create the top of a header file with optional include files from config" do
|
it "create the top of a header file with optional include files from config" do
|
||||||
@config.expect :mock_prefix, "Mock"
|
@config.expect :mock_prefix, "Mock"
|
||||||
|
@config.expect :mock_suffix, ""
|
||||||
orig_filename = "PoutPoutFish.h"
|
orig_filename = "PoutPoutFish.h"
|
||||||
define_name = "MOCKPOUTPOUTFISH_H"
|
define_name = "MOCKPOUTPOUTFISH_H"
|
||||||
mock_name = "MockPoutPoutFish"
|
mock_name = "MockPoutPoutFish"
|
||||||
@@ -192,6 +198,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
|||||||
|
|
||||||
it "create the top of a header file with include file from plugin" do
|
it "create the top of a header file with include file from plugin" do
|
||||||
@config.expect :mock_prefix, "Mock"
|
@config.expect :mock_prefix, "Mock"
|
||||||
|
@config.expect :mock_suffix, ""
|
||||||
orig_filename = "PoutPoutFish.h"
|
orig_filename = "PoutPoutFish.h"
|
||||||
define_name = "MOCKPOUTPOUTFISH_H"
|
define_name = "MOCKPOUTPOUTFISH_H"
|
||||||
mock_name = "MockPoutPoutFish"
|
mock_name = "MockPoutPoutFish"
|
||||||
|
|||||||
Reference in New Issue
Block a user