mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-10-06 00:47:37 +00:00
Update to latest Unity and therefore newer Rubocop standards. Tweaked scripts to match latest standards.
This commit is contained in:
+6
-5
@@ -59,7 +59,7 @@ def option_maker(options, key, val)
|
||||
options ||= {}
|
||||
options[key.to_sym] =
|
||||
if val.chr == ':'
|
||||
val[1..-1].to_sym
|
||||
val[1..].to_sym
|
||||
elsif val.include? ';'
|
||||
val.split(';')
|
||||
elsif val == 'true'
|
||||
@@ -87,15 +87,16 @@ if $0 == __FILE__
|
||||
options = {}
|
||||
filelist = []
|
||||
ARGV.each do |arg|
|
||||
if arg =~ /^-o\"?([a-zA-Z0-9@._\\\/:\s]+)\"?/
|
||||
case arg
|
||||
when /^-o"?([a-zA-Z0-9@._\\\/:\s]+)"?/
|
||||
options.merge! CMockConfig.load_config_file_from_yaml(arg.gsub(/^-o/, ''))
|
||||
elsif arg == '--skeleton'
|
||||
when '--skeleton'
|
||||
options[:skeleton] = true
|
||||
elsif arg =~ /^--strippables=\"?(.*)\"?/
|
||||
when /^--strippables="?(.*)"?/
|
||||
# --strippables are dealt with separately since the user is allowed to
|
||||
# enter any valid regular expression as argument
|
||||
options = option_maker(options, 'strippables', Regexp.last_match(1))
|
||||
elsif arg =~ /^--([a-zA-Z0-9._\\\/:\s]+)=\"?([a-zA-Z0-9._\-\\\/:\s\;]*)\"?/x
|
||||
when /^--([a-zA-Z0-9._\\\/:\s]+)="?([a-zA-Z0-9._\-\\\/:\s;]*)"?/x
|
||||
options = option_maker(options, Regexp.last_match(1),
|
||||
Regexp.last_match(2))
|
||||
else
|
||||
|
||||
+5
-5
@@ -63,13 +63,13 @@ class CMockConfig
|
||||
|
||||
# do some quick type verification
|
||||
%i[plugins attributes treat_as_void].each do |opt|
|
||||
unless options[opt].class == Array
|
||||
unless options[opt].instance_of?(Array)
|
||||
options[opt] = []
|
||||
puts "WARNING: :#{opt} should be an array." unless options[:verbosity] < 1
|
||||
end
|
||||
end
|
||||
%i[includes includes_h_pre_orig_header includes_h_post_orig_header includes_c_pre_header includes_c_post_header].each do |opt|
|
||||
unless options[opt].nil? || (options[opt].class == Array)
|
||||
unless options[opt].nil? || options[opt].instance_of?(Array)
|
||||
options[opt] = []
|
||||
puts "WARNING: :#{opt} should be an array." unless options[:verbosity] < 1
|
||||
end
|
||||
@@ -109,9 +109,9 @@ class CMockConfig
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
begin
|
||||
return YAML.load_file(yaml_filename, aliases: true)[:cmock]
|
||||
YAML.load_file(yaml_filename, aliases: true)[:cmock]
|
||||
rescue ArgumentError
|
||||
return YAML.load_file(yaml_filename)[:cmock]
|
||||
YAML.load_file(yaml_filename)[:cmock]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -123,7 +123,7 @@ class CMockConfig
|
||||
return nil unless @options[:unity_helper_path]
|
||||
|
||||
@options[:unity_helper_path].inject('') do |unity_helper, filename|
|
||||
unity_helper + "\n" + File.new(filename).read
|
||||
unity_helper + "\n#{File.new(filename).read}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -14,14 +14,14 @@ class CMockFileWriter
|
||||
def create_subdir(subdir)
|
||||
require 'fileutils'
|
||||
FileUtils.mkdir_p "#{@config.mock_path}/" unless Dir.exist?("#{@config.mock_path}/")
|
||||
FileUtils.mkdir_p "#{@config.mock_path}/#{subdir + '/' if subdir}" if subdir && !Dir.exist?("#{@config.mock_path}/#{subdir + '/' if subdir}")
|
||||
FileUtils.mkdir_p "#{@config.mock_path}/#{"#{subdir}/" if subdir}" if subdir && !Dir.exist?("#{@config.mock_path}/#{"#{subdir}/" if subdir}")
|
||||
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}/#{subdir + '/' if subdir}#{filename}.new"
|
||||
full_file_name_done = "#{@config.mock_path}/#{subdir + '/' if subdir}#{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
|
||||
@@ -31,7 +31,7 @@ class CMockFileWriter
|
||||
def append_file(filename, subdir)
|
||||
raise "Where's the block of data to create?" unless block_given?
|
||||
|
||||
full_file_name = "#{@config.skeleton_path}/#{subdir + '/' if subdir}#{filename}"
|
||||
full_file_name = "#{@config.skeleton_path}/#{"#{subdir}/" if subdir}#{filename}"
|
||||
File.open(full_file_name, 'a') do |file|
|
||||
yield(file, filename)
|
||||
end
|
||||
|
||||
@@ -117,7 +117,7 @@ class CMockGenerator
|
||||
end
|
||||
|
||||
def create_mock_source_file(mock_project)
|
||||
@file_writer.create_file(mock_project[:mock_name] + '.c', mock_project[:folder]) do |file, filename|
|
||||
@file_writer.create_file("#{mock_project[:mock_name]}.c", mock_project[:folder]) do |file, filename|
|
||||
create_source_header_section(file, filename, mock_project)
|
||||
create_instance_structure(file, mock_project)
|
||||
create_extern_declarations(file)
|
||||
@@ -132,9 +132,9 @@ class CMockGenerator
|
||||
end
|
||||
|
||||
def create_skeleton_source_file(mock_project)
|
||||
filename = "#{@config.mock_path}/#{@subdir + '/' if @subdir}#{mock_project[:module_name]}.c"
|
||||
filename = "#{@config.mock_path}/#{"#{@subdir}/" if @subdir}#{mock_project[:module_name]}.c"
|
||||
existing = File.exist?(filename) ? File.read(filename) : ''
|
||||
@file_writer.create_file(mock_project[:module_name] + '.c', @subdir) do |file, fullname|
|
||||
@file_writer.create_file("#{mock_project[:module_name]}.c", @subdir) do |file, fullname|
|
||||
blank_project = mock_project.clone
|
||||
blank_project[:parsed_stuff] = { :functions => [] }
|
||||
if existing.empty?
|
||||
@@ -156,7 +156,7 @@ class CMockGenerator
|
||||
file << "#define _#{define_name}_H\n\n"
|
||||
file << "#include \"#{@framework}.h\"\n"
|
||||
@includes_h_pre_orig_header.each { |inc| file << "#include #{inc}\n" }
|
||||
file << @config.orig_header_include_fmt.gsub(/%s/, orig_filename.to_s) + "\n"
|
||||
file << "#{@config.orig_header_include_fmt.gsub(/%s/, orig_filename.to_s)}\n"
|
||||
@includes_h_post_orig_header.each { |inc| file << "#include #{inc}\n" }
|
||||
plugin_includes = @plugins.run(:include_files)
|
||||
file << plugin_includes unless plugin_includes.empty?
|
||||
@@ -303,7 +303,7 @@ class CMockGenerator
|
||||
(function[:return][:type]) +
|
||||
(function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
|
||||
args_string = function[:args_string]
|
||||
args_string += (', ' + function[:var_arg]) unless function[:var_arg].nil?
|
||||
args_string += ", #{function[:var_arg]}" unless function[:var_arg].nil?
|
||||
|
||||
# Encapsulate in namespace(s) if applicable
|
||||
function[:namespace].each do |ns|
|
||||
@@ -364,7 +364,7 @@ class CMockGenerator
|
||||
(function[:return][:type]) +
|
||||
(function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
|
||||
args_string = function[:args_string]
|
||||
args_string += (', ' + function[:var_arg]) unless function[:var_arg].nil?
|
||||
args_string += ", #{function[:var_arg]}" unless function[:var_arg].nil?
|
||||
|
||||
decl = "#{function_mod_and_rettype} #{function[:name]}(#{args_string})"
|
||||
|
||||
@@ -374,7 +374,7 @@ class CMockGenerator
|
||||
file << "{\n"
|
||||
file << " /*TODO: Implement Me!*/\n"
|
||||
function[:args].each { |arg| file << " (void)#{arg[:name]};\n" }
|
||||
file << " return (#{(function[:return][:type])})0;\n" unless function[:return][:void?]
|
||||
file << " return (#{function[:return][:type]})0;\n" unless function[:return][:void?]
|
||||
file << "}\n\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
class CMockGeneratorPluginArray
|
||||
attr_reader :priority
|
||||
attr_accessor :config, :utils, :unity_helper, :ordered
|
||||
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
@ptr_handling = @config.when_ptr
|
||||
@@ -31,10 +32,10 @@ class CMockGeneratorPluginArray
|
||||
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
||||
end.join(', ')
|
||||
if function[:return][:void?]
|
||||
return "#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" \
|
||||
"#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" \
|
||||
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string});\n"
|
||||
else
|
||||
return "#define #{function[:name]}_ExpectWithArrayAndReturn(#{args_call}, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, #{args_call}, cmock_retval)\n" \
|
||||
"#define #{function[:name]}_ExpectWithArrayAndReturn(#{args_call}, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, #{args_call}, cmock_retval)\n" \
|
||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]});\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
|
||||
class CMockGeneratorPluginCallback
|
||||
attr_accessor :include_count
|
||||
attr_reader :priority
|
||||
attr_reader :config, :utils
|
||||
attr_reader :priority, :config, :utils
|
||||
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
class CMockGeneratorPluginCexception
|
||||
attr_reader :priority
|
||||
attr_reader :config, :utils
|
||||
attr_reader :priority, :config, :utils
|
||||
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
class CMockGeneratorPluginExpectAnyArgs
|
||||
attr_reader :priority
|
||||
attr_reader :config, :utils
|
||||
attr_reader :priority, :config, :utils
|
||||
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
class CMockGeneratorPluginIgnore
|
||||
attr_reader :priority
|
||||
attr_reader :config, :utils
|
||||
attr_reader :priority, :config, :utils
|
||||
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
@@ -45,7 +44,7 @@ class CMockGeneratorPluginIgnore
|
||||
else
|
||||
retval = function[:return].merge(:name => 'cmock_call_instance->ReturnVal')
|
||||
lines << " if (cmock_call_instance == NULL)\n return Mock.#{function[:name]}_FinalReturn;\n"
|
||||
lines << ' ' + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless retval[:void?]
|
||||
lines << " #{@utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval)}" unless retval[:void?]
|
||||
lines << " return cmock_call_instance->ReturnVal;\n }\n"
|
||||
end
|
||||
lines
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
class CMockGeneratorPluginIgnoreStateless
|
||||
attr_reader :priority
|
||||
attr_reader :config, :utils
|
||||
attr_reader :priority, :config, :utils
|
||||
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
@@ -45,7 +44,7 @@ class CMockGeneratorPluginIgnoreStateless
|
||||
else
|
||||
retval = function[:return].merge(:name => 'cmock_call_instance->ReturnVal')
|
||||
lines << " if (cmock_call_instance == NULL)\n return Mock.#{function[:name]}_FinalReturn;\n"
|
||||
lines << ' ' + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless retval[:void?]
|
||||
lines << " #{@utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval)}" unless retval[:void?]
|
||||
lines << " return cmock_call_instance->ReturnVal;\n }\n"
|
||||
end
|
||||
lines
|
||||
|
||||
@@ -63,7 +63,7 @@ class CMockGeneratorUtils
|
||||
|
||||
def code_add_an_arg_expectation(arg, depth = 1)
|
||||
lines = code_assign_argument_quickly("cmock_call_instance->Expected_#{arg[:name]}", arg)
|
||||
lines << " cmock_call_instance->Expected_#{arg[:name]}_Depth = #{arg[:name]}_Depth;\n" if @arrays && (depth.class == String)
|
||||
lines << " cmock_call_instance->Expected_#{arg[:name]}_Depth = #{arg[:name]}_Depth;\n" if @arrays && depth.instance_of?(String)
|
||||
lines << " cmock_call_instance->IgnoreArg_#{arg[:name]} = 0;\n" if @ignore_arg
|
||||
lines << " cmock_call_instance->ReturnThruPtr_#{arg[:name]}_Used = 0;\n" if @return_thru_ptr && ptr_or_str?(arg[:type]) && !(arg[:const?])
|
||||
lines
|
||||
@@ -88,13 +88,13 @@ class CMockGeneratorUtils
|
||||
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
||||
end.join(', ')
|
||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string});\n" \
|
||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string})\n{\n" +
|
||||
function[:args].inject('') { |all, arg| all + code_add_an_arg_expectation(arg, (arg[:ptr?] ? "#{arg[:name]}_Depth" : 1)) } +
|
||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string})\n{\n" \
|
||||
"#{function[:args].inject('') { |all, arg| all + code_add_an_arg_expectation(arg, (arg[:ptr?] ? "#{arg[:name]}_Depth" : 1)) }}" \
|
||||
"}\n\n"
|
||||
else
|
||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{function[:args_string]});\n" \
|
||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{function[:args_string]})\n{\n" +
|
||||
function[:args].inject('') { |all, arg| all + code_add_an_arg_expectation(arg) } +
|
||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{function[:args_string]})\n{\n" \
|
||||
"#{function[:args].inject('') { |all, arg| all + code_add_an_arg_expectation(arg) }}" \
|
||||
"}\n\n"
|
||||
end
|
||||
else
|
||||
|
||||
+24
-23
@@ -79,7 +79,7 @@ class CMockHeaderParser
|
||||
r = '\\{([^\\{\\}]*|\\g<0>)*\\}'
|
||||
source.gsub!(/#{r}/m, '{ }')
|
||||
else
|
||||
while source.gsub!(/\{[^\{\}]*\{[^\{\}]*\}[^\{\}]*\}/m, '{ }')
|
||||
while source.gsub!(/\{[^{}]*\{[^{}]*\}[^{}]*\}/m, '{ }')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -94,11 +94,12 @@ class CMockHeaderParser
|
||||
total_pairs = 0
|
||||
|
||||
source.each_char do |c|
|
||||
if c == '{'
|
||||
case c
|
||||
when '{'
|
||||
curr_level += 1
|
||||
total_pairs += 1
|
||||
is_function_start_found = true
|
||||
elsif c == '}'
|
||||
when '}'
|
||||
curr_level -= 1
|
||||
end
|
||||
|
||||
@@ -116,14 +117,14 @@ class CMockHeaderParser
|
||||
# +source+:: String containing the source to be processed
|
||||
def transform_inline_functions(source)
|
||||
inline_function_regex_formats = []
|
||||
square_bracket_pair_regex_format = /\{[^\{\}]*\}/ # Regex to match one whole block enclosed by two square brackets
|
||||
square_bracket_pair_regex_format = /\{[^{}]*\}/ # Regex to match one whole block enclosed by two square brackets
|
||||
|
||||
# Convert user provided string patterns to regex
|
||||
# Use word bounderies before and after the user regex to limit matching to actual word iso part of a word
|
||||
@inline_function_patterns.each do |user_format_string|
|
||||
user_regex = Regexp.new(user_format_string)
|
||||
word_boundary_before_user_regex = /\b/
|
||||
cleanup_spaces_after_user_regex = /[ ]*\b/
|
||||
cleanup_spaces_after_user_regex = / *\b/
|
||||
inline_function_regex_formats << Regexp.new(word_boundary_before_user_regex.source + user_regex.source + cleanup_spaces_after_user_regex.source)
|
||||
end
|
||||
|
||||
@@ -170,7 +171,7 @@ class CMockHeaderParser
|
||||
if /(#define\s*)\z/ =~ inline_function_match.pre_match
|
||||
# Remove the macro from the source
|
||||
stripped_pre_match = inline_function_match.pre_match.sub(/(#define\s*)\z/, '')
|
||||
stripped_post_match = inline_function_match.post_match.sub(/\A(.*[\n]?)/, '')
|
||||
stripped_post_match = inline_function_match.post_match.sub(/\A(.*\n?)/, '')
|
||||
inspected_source += stripped_pre_match
|
||||
source = stripped_post_match
|
||||
next
|
||||
@@ -220,7 +221,7 @@ class CMockHeaderParser
|
||||
# void must be void for cmock _ExpectAndReturn calls to process properly, not some weird typedef which equates to void
|
||||
# to a certain extent, this action assumes we're chewing on pre-processed header files, otherwise we'll most likely just get stuff from @treat_as_void
|
||||
@local_as_void = @treat_as_void
|
||||
void_types = source.scan(/typedef\s+(?:\(\s*)?void(?:\s*\))?\s+([\w]+)\s*;/)
|
||||
void_types = source.scan(/typedef\s+(?:\(\s*)?void(?:\s*\))?\s+(\w+)\s*;/)
|
||||
if void_types
|
||||
@local_as_void += void_types.flatten.uniq.compact
|
||||
end
|
||||
@@ -245,18 +246,18 @@ class CMockHeaderParser
|
||||
source.gsub!(/__attribute(?:__)?\s*\(\(+.*\)\)+/, '')
|
||||
|
||||
# remove preprocessor statements and extern "C"
|
||||
source.gsub!(/extern\s+\"C\"\s*\{/, '')
|
||||
source.gsub!(/extern\s+"C"\s*\{/, '')
|
||||
source.gsub!(/^\s*#.*/, '')
|
||||
|
||||
# enums, unions, structs, and typedefs can all contain things (e.g. function pointers) that parse like function prototypes, so yank them
|
||||
# forward declared structs are removed before struct definitions so they don't mess up real thing later. we leave structs keywords in function prototypes
|
||||
source.gsub!(/^[\w\s]*struct[^;\{\}\(\)]+;/m, '') # remove forward declared structs
|
||||
source.gsub!(/^[\w\s]*(enum|union|struct|typedef)[\w\s]*\{[^\}]+\}[\w\s\*\,]*;/m, '') # remove struct, union, and enum definitions and typedefs with braces
|
||||
source.gsub!(/^[\w\s]*struct[^;{}()]+;/m, '') # remove forward declared structs
|
||||
source.gsub!(/^[\w\s]*(enum|union|struct|typedef)[\w\s]*\{[^}]+\}[\w\s*,]*;/m, '') # remove struct, union, and enum definitions and typedefs with braces
|
||||
# remove problem keywords
|
||||
source.gsub!(/(\W)(?:register|auto|restrict)(\W)/, '\1\2')
|
||||
source.gsub!(/(\W)(?:static)(\W)/, '\1\2') unless cpp
|
||||
|
||||
source.gsub!(/\s*=\s*['"a-zA-Z0-9_\.]+\s*/, '') # remove default value statements from argument lists
|
||||
source.gsub!(/\s*=\s*['"a-zA-Z0-9_.]+\s*/, '') # remove default value statements from argument lists
|
||||
source.gsub!(/^(?:[\w\s]*\W)?typedef\W[^;]*/m, '') # remove typedef statements
|
||||
source.gsub!(/\)(\w)/, ') \1') # add space between parenthese and alphanumeric
|
||||
source.gsub!(/(^|\W+)(?:#{@c_strippables.join('|')})(?=$|\W+)/, '\1') unless @c_strippables.empty? # remove known attributes slated to be stripped
|
||||
@@ -265,7 +266,7 @@ class CMockHeaderParser
|
||||
source.gsub!(/\w+\s*\(\s*\*\s*\w+\s*\)\s*\([^)]*\)\s*;/, ';')
|
||||
|
||||
# scan for functions which return function pointers, because they are a pain
|
||||
source.gsub!(/([\w\s\*]+)\(*\(\s*\*([\w\s\*]+)\s*\(([\w\s\*,]*)\)\)\s*\(([\w\s\*,]*)\)\)*/) do |_m|
|
||||
source.gsub!(/([\w\s*]+)\(*\(\s*\*([\w\s*]+)\s*\(([\w\s*,]*)\)\)\s*\(([\w\s*,]*)\)\)*/) do |_m|
|
||||
functype = "cmock_#{parse_project[:module_name]}_func_ptr#{parse_project[:typedefs].size + 1}"
|
||||
unless cpp # only collect once
|
||||
parse_project[:typedefs] << "typedef #{Regexp.last_match(1).strip}(*#{functype})(#{Regexp.last_match(4)});"
|
||||
@@ -282,7 +283,7 @@ class CMockHeaderParser
|
||||
end
|
||||
|
||||
# remove function definitions by stripping off the arguments right now
|
||||
source.gsub!(/\([^\)]*\)\s*\{[^\}]*\}/m, ';')
|
||||
source.gsub!(/\([^)]*\)\s*\{[^}]*\}/m, ';')
|
||||
|
||||
# drop extra white space to make the rest go faster
|
||||
source.gsub!(/^\s+/, '') # remove extra white space from beginning of line
|
||||
@@ -295,7 +296,7 @@ class CMockHeaderParser
|
||||
src_lines = source.split(/\s*;\s*/)
|
||||
src_lines = src_lines.uniq unless cpp # must retain closing braces for class/namespace
|
||||
src_lines.delete_if { |line| line.strip.empty? } # remove blank lines
|
||||
src_lines.delete_if { |line| !(line =~ /[\w\s\*]+\(+\s*\*[\*\s]*[\w\s]+(?:\[[\w\s]*\]\s*)+\)+\s*\((?:[\w\s\*]*,?)*\s*\)/).nil? } # remove function pointer arrays
|
||||
src_lines.delete_if { |line| !(line =~ /[\w\s*]+\(+\s*\*[*\s]*[\w\s]+(?:\[[\w\s]*\]\s*)+\)+\s*\((?:[\w\s*]*,?)*\s*\)/).nil? } # remove function pointer arrays
|
||||
|
||||
unless @treat_externs == :include
|
||||
src_lines.delete_if { |line| !(line =~ /(?:^|\s+)(?:extern)\s+/).nil? } # remove extern functions
|
||||
@@ -484,7 +485,7 @@ class CMockHeaderParser
|
||||
arg_list.gsub!(/\*(\w)/, '* \1')
|
||||
|
||||
# scan argument list for function pointers and replace them with custom types
|
||||
arg_list.gsub!(/([\w\s\*]+)\(+([\w\s]*)\*[\*\s]*([\w\s]*)\s*\)+\s*\(((?:[\w\s\*]*,?)*)\s*\)*/) do |_m|
|
||||
arg_list.gsub!(/([\w\s*]+)\(+([\w\s]*)\*[*\s]*([\w\s]*)\s*\)+\s*\(((?:[\w\s*]*,?)*)\s*\)*/) do |_m|
|
||||
functype = "cmock_#{parse_project[:module_name]}_func_ptr#{parse_project[:typedefs].size + 1}"
|
||||
funcret = Regexp.last_match(1).strip
|
||||
funcdecl = Regexp.last_match(2).strip
|
||||
@@ -504,7 +505,7 @@ class CMockHeaderParser
|
||||
end
|
||||
|
||||
# scan argument list for function pointers with shorthand notation and replace them with custom types
|
||||
arg_list.gsub!(/([\w\s\*]+)\s+(\w+)\s*\(((?:[\w\s\*]*,?)*)\s*\)*/) do |_m|
|
||||
arg_list.gsub!(/([\w\s*]+)\s+(\w+)\s*\(((?:[\w\s*]*,?)*)\s*\)*/) do |_m|
|
||||
functype = "cmock_#{parse_project[:module_name]}_func_ptr#{parse_project[:typedefs].size + 1}"
|
||||
funcret = Regexp.last_match(1).strip
|
||||
funcname = Regexp.last_match(2).strip
|
||||
@@ -574,13 +575,13 @@ class CMockHeaderParser
|
||||
:const_ptr? => parsed[:const_ptr?] || false }
|
||||
|
||||
# remove default argument statements from mock definitions
|
||||
args.gsub!(/=\s*[a-zA-Z0-9_\.]+\s*/, ' ')
|
||||
args.gsub!(/=\s*[a-zA-Z0-9_.]+\s*/, ' ')
|
||||
|
||||
# check for var args
|
||||
if args =~ /\.\.\./
|
||||
decl[:var_arg] = args.match(/[\w\s]*\.\.\./).to_s.strip
|
||||
args = if args =~ /\,[\w\s]*\.\.\./
|
||||
args.gsub!(/\,[\w\s]*\.\.\./, '')
|
||||
args = if args =~ /,[\w\s]*\.\.\./
|
||||
args.gsub!(/,[\w\s]*\.\.\./, '')
|
||||
else
|
||||
'void'
|
||||
end
|
||||
@@ -608,7 +609,7 @@ class CMockHeaderParser
|
||||
|
||||
def prototype_inspect_hash(hash)
|
||||
pairs = []
|
||||
hash.each_pair { |name, value| pairs << ":#{name} => #{"'" if value.class == String}#{value}#{"'" if value.class == String}" }
|
||||
hash.each_pair { |name, value| pairs << ":#{name} => #{"'" if value.instance_of?(String)}#{value}#{"'" if value.instance_of?(String)}" }
|
||||
"{#{pairs.join(', ')}}"
|
||||
end
|
||||
|
||||
@@ -617,11 +618,11 @@ class CMockHeaderParser
|
||||
array.each { |hash| hashes << prototype_inspect_hash(hash) }
|
||||
case array.size
|
||||
when 0
|
||||
return '[]'
|
||||
'[]'
|
||||
when 1
|
||||
return "[#{hashes[0]}]"
|
||||
"[#{hashes[0]}]"
|
||||
else
|
||||
return "[\n #{hashes.join("\n ")}\n ]\n"
|
||||
"[\n #{hashes.join("\n ")}\n ]\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,7 +12,7 @@ class CMockPluginManager
|
||||
plugins_to_load = [:expect, config.plugins].flatten.uniq.compact
|
||||
plugins_to_load.each do |plugin|
|
||||
plugin_name = plugin.to_s
|
||||
object_name = 'CMockGeneratorPlugin' + camelize(plugin_name)
|
||||
object_name = "CMockGeneratorPlugin#{camelize(plugin_name)}"
|
||||
self.class.mutex.synchronize { load_plugin(plugin_name, object_name, config, utils) }
|
||||
end
|
||||
@plugins.sort! { |a, b| a.priority <=> b.priority }
|
||||
@@ -27,7 +27,7 @@ class CMockPluginManager
|
||||
end
|
||||
|
||||
def camelize(lower_case_and_underscored_word)
|
||||
lower_case_and_underscored_word.gsub(/\/(.?)/) { '::' + Regexp.last_match(1).upcase }.gsub(/(^|_)(.)/) { Regexp.last_match(2).upcase }
|
||||
lower_case_and_underscored_word.gsub(/\/(.?)/) { "::#{Regexp.last_match(1).upcase}" }.gsub(/(^|_)(.)/) { Regexp.last_match(2).upcase }
|
||||
end
|
||||
|
||||
def self.mutex
|
||||
|
||||
@@ -38,12 +38,13 @@ class CMockUnityHelperParser
|
||||
if ctype.is_a?(Symbol)
|
||||
raise ":treat_as expects a list of identifier: identifier mappings, but got a symbol: #{ctype}. Check the indentation in your project.yml"
|
||||
end
|
||||
|
||||
c_type = ctype.gsub(/\s+/, '_')
|
||||
if expecttype =~ /\*/
|
||||
c_types[c_type] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype.delete('*')}_ARRAY"
|
||||
else
|
||||
c_types[c_type] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype}"
|
||||
c_types[c_type + '*'] ||= "UNITY_TEST_ASSERT_EQUAL_#{expecttype}_ARRAY"
|
||||
c_types["#{c_type}*"] ||= "UNITY_TEST_ASSERT_EQUAL_#{expecttype}_ARRAY"
|
||||
end
|
||||
end
|
||||
c_types
|
||||
@@ -58,7 +59,7 @@ class CMockUnityHelperParser
|
||||
source = source.gsub(/\/\*.*?\*\//m, '') # remove block comments
|
||||
|
||||
# scan for comparison helpers
|
||||
match_regex = Regexp.new('^\s*#define\s+(UNITY_TEST_ASSERT_EQUAL_(\w+))\s*\(' + Array.new(4, '\s*\w+\s*').join(',') + '\)')
|
||||
match_regex = Regexp.new("^\\s*#define\\s+(UNITY_TEST_ASSERT_EQUAL_(\\w+))\\s*\\(#{Array.new(4, '\s*\w+\s*').join(',')}\\)")
|
||||
pairs = source.scan(match_regex).flatten.compact
|
||||
(pairs.size / 2).times do |i|
|
||||
expect = pairs[i * 2]
|
||||
@@ -67,7 +68,7 @@ class CMockUnityHelperParser
|
||||
end
|
||||
|
||||
# scan for array variants of those helpers
|
||||
match_regex = Regexp.new('^\s*#define\s+(UNITY_TEST_ASSERT_EQUAL_(\w+_ARRAY))\s*\(' + Array.new(5, '\s*\w+\s*').join(',') + '\)')
|
||||
match_regex = Regexp.new("^\\s*#define\\s+(UNITY_TEST_ASSERT_EQUAL_(\\w+_ARRAY))\\s*\\(#{Array.new(5, '\s*\w+\s*').join(',')}\\)")
|
||||
pairs = source.scan(match_regex).flatten.compact
|
||||
(pairs.size / 2).times do |i|
|
||||
expect = pairs[i * 2]
|
||||
|
||||
Reference in New Issue
Block a user