Merge pull request #52 from eivindt/subdir_support

Add support for subdirs (ref issue #1)
This commit is contained in:
Mark VanderVoord
2015-04-10 20:32:55 -04:00
5 changed files with 31 additions and 7 deletions
+4
View File
@@ -284,6 +284,10 @@ Defined in the yaml file, they look more like this:
The prefix to append to your mock files. Defaults to “Mock”, so a file
“USART.h” will get a mock called “MockUSART.c”
* `: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/
* `:plugins`:
An array of which plugins to enable. 'expect' is always active. Also
available currently are `:ignore,` `:ignore_args,` `:array,`
+1
View File
@@ -11,6 +11,7 @@ class CMockConfig
:framework => :unity,
:mock_path => 'mocks',
:mock_prefix => 'Mock',
:subdir => nil,
:plugins => [],
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
:attributes => ['__ramfunc', '__irq', '__fiq', 'register', 'extern'],
+10 -3
View File
@@ -12,10 +12,17 @@ class CMockFileWriter
@config = config
end
def create_file(filename)
def create_subdir(subdir)
if subdir && !Dir.exists?("#{@config.mock_path}/#{subdir+'/' if subdir}")
require 'fileutils'
FileUtils.mkdir_p "#{@config.mock_path}/#{subdir+'/' if subdir}"
end
end
def create_file(filename, subdir)
raise "Where's the block of data to create?" unless block_given?
full_file_name_temp = "#{@config.mock_path}/#{filename}.new"
full_file_name_done = "#{@config.mock_path}/#{filename}"
full_file_name_temp = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}.new"
full_file_name_done = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}"
File.open(full_file_name_temp, 'w') do |file|
yield(file, filename)
end
+13 -4
View File
@@ -17,6 +17,8 @@ class CMockGenerator
@ordered = @config.enforce_strict_ordering
@framework = @config.framework.to_s
@subdir = @config.subdir
@includes_h_pre_orig_header = (@config.includes || @config.includes_h_pre_orig_header || []).map{|h| h =~ /</ ? h : "\"#{h}\""}
@includes_h_post_orig_header = (@config.includes_h_post_orig_header || []).map{|h| h =~ /</ ? h : "\"#{h}\""}
@includes_c_pre_header = (@config.includes_c_pre_header || []).map{|h| h =~ /</ ? h : "\"#{h}\""}
@@ -39,14 +41,21 @@ class CMockGenerator
@module_name = module_name
@mock_name = @prefix + @module_name
@clean_mock_name = TypeSanitizer.sanitize_c_identifier(@mock_name)
create_mock_subdir()
create_mock_header_file(parsed_stuff)
create_mock_source_file(parsed_stuff)
end
private if $ThisIsOnlyATest.nil? ##############################
def create_mock_subdir()
if @subdir
@file_writer.create_subdir(@subdir)
end
end
def create_mock_header_file(parsed_stuff)
@file_writer.create_file(@mock_name + ".h") do |file, filename|
@file_writer.create_file(@mock_name + ".h", @subdir) do |file, filename|
create_mock_header_header(file, filename)
create_mock_header_service_call_declarations(file)
create_typedefs(file, parsed_stuff[:typedefs])
@@ -58,7 +67,7 @@ class CMockGenerator
end
def create_mock_source_file(parsed_stuff)
@file_writer.create_file(@mock_name + ".c") do |file, filename|
@file_writer.create_file(@mock_name + ".c", @subdir) do |file, filename|
create_source_header_section(file, filename)
create_instance_structure(file, parsed_stuff[:functions])
create_extern_declarations(file)
@@ -74,7 +83,7 @@ class CMockGenerator
def create_mock_header_header(file, filename)
define_name = @clean_mock_name.upcase
orig_filename = filename[@config.mock_prefix.size..-1]
orig_filename = (@subdir ? @subdir + "/" : "") + filename[@config.mock_prefix.size..-1]
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
file << "#ifndef _#{define_name}_H\n"
file << "#define _#{define_name}_H\n\n"
@@ -112,7 +121,7 @@ class CMockGenerator
end
def create_source_header_section(file, filename)
header_file = filename.gsub(".c",".h")
header_file = (@subdir ? @subdir + '/' : '') + filename.gsub(".c",".h")
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
file << "#include <string.h>\n"
file << "#include <stdlib.h>\n"
+3
View File
@@ -50,6 +50,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
@config.expect :includes_h_post_orig_header, nil
@config.expect :includes_c_pre_header, nil
@config.expect :includes_c_post_header, nil
@config.expect :subdir, nil
@cmock_generator = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
@cmock_generator.module_name = @module_name
@cmock_generator.mock_name = "Mock#{@module_name}"
@@ -64,6 +65,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
@config.expect :includes_h_post_orig_header, nil
@config.expect :includes_c_pre_header, nil
@config.expect :includes_c_post_header, nil
@config.expect :subdir, nil
@cmock_generator_strict = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
@cmock_generator_strict.module_name = @module_name
@cmock_generator_strict.mock_name = "Mock#{@module_name}"
@@ -116,6 +118,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
@config.expect :includes_h_post_orig_header, nil
@config.expect :includes_c_pre_header, nil
@config.expect :includes_c_post_header, nil
@config.expect :subdir, nil
@cmock_generator2 = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
@cmock_generator2.module_name = "Pout-Pout Fish"
@cmock_generator2.mock_name = "MockPout-Pout Fish"