Update to latest Unity and therefore newer Rubocop standards. Tweaked scripts to match latest standards.

This commit is contained in:
Mark VanderVoord
2023-11-22 17:40:07 -05:00
parent 32049399b3
commit a642b1fe49
22 changed files with 107 additions and 104 deletions
+1 -1
View File
@@ -8,5 +8,5 @@
[
'lib'
].each do |dir|
$:.unshift(File.join(__dir__ + '/../', dir))
$:.unshift(File.join("#{__dir__}//..//", dir))
end
+1 -1
View File
@@ -12,5 +12,5 @@
'./vendor/unity/auto/',
'./test/system/'
].each do |dir|
$:.unshift(File.join(File.expand_path(File.dirname(__FILE__) + '/../'), dir))
$:.unshift(File.join(File.expand_path("#{File.dirname(__FILE__)}//..//"), dir))
end
+1 -1
View File
@@ -1,4 +1,4 @@
HERE = __dir__ + '/'
HERE = "#{__dir__}//".freeze
require 'rake'
require 'rake/clean'
+22 -25
View File
@@ -10,21 +10,19 @@ module RakefileHelpers
C_EXTENSION = '.c'.freeze
def load_yaml(yaml_string)
begin
return YAML.load(yaml_string, aliases: true)
rescue ArgumentError
return YAML.load(yaml_string)
end
YAML.load(yaml_string, aliases: true)
rescue ArgumentError
YAML.load(yaml_string)
end
def load_configuration(config_file)
$cfg_file = config_file
$cfg = load_yaml(File.read('./targets/' + $cfg_file))
$cfg = load_yaml(File.read("./targets/#{$cfg_file}"))
$colour_output = false unless $cfg['colour']
end
def configure_clean
CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil?
CLEAN.include("#{$cfg['compiler']['build_path']}*.*") unless $cfg['compiler']['build_path'].nil?
end
def configure_toolchain(config_file = DEFAULT_CONFIG_FILE)
@@ -34,7 +32,7 @@ module RakefileHelpers
end
def unit_test_files
path = $cfg['compiler']['unit_tests_path'] + 'Test*' + C_EXTENSION
path = $cfg['compiler']['unit_tests_path'] + "Test*#{C_EXTENSION}"
path.tr!('\\', '/')
FileList.new(path)
end
@@ -49,7 +47,7 @@ module RakefileHelpers
includes = []
lines = File.readlines(filename)
lines.each do |line|
m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/)
m = line.match(/^\s*#include\s+"\s*(.+\.[hH])\s*"/)
unless m.nil?
includes << m[1]
end
@@ -95,7 +93,7 @@ module RakefileHelpers
end
options = squash('', $cfg['compiler']['options'])
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
includes = includes.gsub(/\\ /, ' ').gsub(/\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
{ :command => command, :defines => defines, :options => options, :includes => includes }
end
@@ -120,17 +118,17 @@ module RakefileHelpers
else
squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
end
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
includes = includes.gsub(/\\ /, ' ').gsub(/\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
{ :command => command, :options => options, :includes => includes }
end
def link_it(exe_name, obj_list)
linker = build_linker_fields
cmd_str = "#{linker[:command]}#{linker[:includes]} " +
(obj_list.map { |obj| "#{$cfg['linker']['object_files']['path']}#{obj} " }).join +
$cfg['linker']['bin_files']['prefix'] + ' ' +
$cfg['linker']['bin_files']['destination'] +
exe_name + $cfg['linker']['bin_files']['extension'] + " #{linker[:options]}"
cmd_str = "#{linker[:command]}#{linker[:includes]} " \
"#{(obj_list.map { |obj| "#{$cfg['linker']['object_files']['path']}#{obj} " }).join}" \
"#{$cfg['linker']['bin_files']['prefix']} " \
"#{$cfg['linker']['bin_files']['destination']}" \
"#{exe_name}#{$cfg['linker']['bin_files']['extension']} #{linker[:options]}"
execute(cmd_str)
end
@@ -140,7 +138,7 @@ module RakefileHelpers
command = if $cfg['simulator']['path'].nil?
''
else
(tackit($cfg['simulator']['path']) + ' ')
"#{tackit($cfg['simulator']['path'])} "
end
pre_support = if $cfg['simulator']['pre_support'].nil?
''
@@ -190,20 +188,19 @@ module RakefileHelpers
# Build and execute each unit test
test_files.each do |test|
obj_list = []
# Detect dependencies and build required required modules
header_list = (extract_headers(test) + ['cmock.h'] + [$cfg[:cmock][:unity_helper_path]]).compact.uniq
header_list.each do |header|
# create mocks if needed
next unless header =~ /Mock/
require '../../lib/cmock.rb'
@cmock ||= CMock.new('./targets/' + $cfg_file)
require '../../lib/cmock'
@cmock ||= CMock.new(".//targets//#{$cfg_file}")
@cmock.setup_mocks([$cfg['compiler']['source_path'] + header.gsub('Mock', '')])
end
# compile all mocks
obj_list = []
header_list.each do |header|
# compile source file header if it exists
src_file = find_source_file(header, include_dirs)
@@ -214,10 +211,10 @@ module RakefileHelpers
# Build the test runner (generate if configured to do so)
test_base = File.basename(test, C_EXTENSION)
runner_name = test_base + '_Runner.c'
runner_name = "#{test_base}_Runner.c"
if $cfg['compiler']['runner_path'].nil?
runner_path = $cfg['compiler']['build_path'] + runner_name
test_gen = UnityTestRunnerGenerator.new('./targets/' + $cfg_file)
runner_path = "#{$cfg['compiler']['build_path']}#{runner_name}"
test_gen = UnityTestRunnerGenerator.new(".//targets//#{$cfg_file}")
test_gen.run(test, runner_path)
else
runner_path = $cfg['compiler']['runner_path'] + runner_name
@@ -254,7 +251,7 @@ module RakefileHelpers
report 'Building application...'
obj_list = []
load_configuration('./targets/' + $cfg_file)
load_configuration(".//targets//#{$cfg_file}")
main_path = $cfg['compiler']['source_path'] + main + C_EXTENSION
# Detect dependencies and build required required modules
+6 -5
View File
@@ -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
View File
@@ -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
+4 -4
View File
@@ -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
+7 -7
View File
@@ -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
+3 -2
View File
@@ -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
+1 -2
View File
@@ -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
+1 -2
View File
@@ -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
+2 -3
View File
@@ -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
+5 -5
View File
@@ -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
View File
@@ -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
+2 -2
View File
@@ -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
+4 -3
View File
@@ -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]
+6 -6
View File
@@ -20,7 +20,7 @@ TEST_BIN_DIR = TEST_BUILD_DIR
MOCK_PREFIX = ENV.fetch('TEST_MOCK_PREFIX', 'mock_')
MOCK_SUFFIX = ENV.fetch('TEST_MOCK_SUFFIX', '')
TEST_MAKEFILE = ENV.fetch('TEST_MAKEFILE', File.join(TEST_BUILD_DIR, 'MakefileTestSupport'))
MOCK_MATCHER = /#{MOCK_PREFIX}[A-Za-z_][A-Za-z0-9_\-\.]+#{MOCK_SUFFIX}/
MOCK_MATCHER = /#{MOCK_PREFIX}[A-Za-z_][A-Za-z0-9_\-.]+#{MOCK_SUFFIX}/
[TEST_BUILD_DIR, OBJ_DIR, RUNNERS_DIR, MOCKS_DIR, TEST_BIN_DIR].each do |dir|
FileUtils.mkdir_p dir
@@ -83,7 +83,7 @@ File.open(TEST_MAKEFILE, 'w') do |mkfile|
runner_source = File.join(RUNNERS_DIR, "runner_#{module_name}.c")
runner_obj = File.join(OBJ_DIR, "runner_#{module_name}.o")
test_bin = File.join(TEST_BIN_DIR, module_name)
test_results = File.join(TEST_BIN_DIR, module_name + '.testresult')
test_results = File.join(TEST_BIN_DIR, "#{module_name}.testresult")
cfg = {
src: test,
@@ -151,7 +151,7 @@ File.open(TEST_MAKEFILE, 'w') do |mkfile|
all_headers_to_mock += headers_to_mock
mock_objs = headers_to_mock.map do |hdr|
mock_name = MOCK_PREFIX + File.basename(hdr, '.*')
File.join(MOCKS_DIR, mock_name + '.o')
File.join(MOCKS_DIR, "#{mock_name}.o")
end
all_headers_to_mock.uniq!
@@ -178,8 +178,8 @@ File.open(TEST_MAKEFILE, 'w') do |mkfile|
all_headers_to_mock.each do |hdr|
mock_name = MOCK_PREFIX + File.basename(hdr, '.*')
mock_header = File.join(MOCKS_DIR, mock_name + File.extname(hdr))
mock_src = File.join(MOCKS_DIR, mock_name + '.c')
mock_obj = File.join(MOCKS_DIR, mock_name + '.o')
mock_src = File.join(MOCKS_DIR, "#{mock_name}.c")
mock_obj = File.join(MOCKS_DIR, "#{mock_name}.o")
mkfile.puts "#{mock_src}: #{hdr}"
mkfile.puts "\t@CMOCK_DIR=${CMOCK_DIR} ruby ${CMOCK_DIR}/scripts/create_mock.rb #{hdr}"
@@ -198,6 +198,6 @@ File.open(TEST_MAKEFILE, 'w') do |mkfile|
mkfile.puts ''
# Create target to run all tests
mkfile.puts "test: #{test_targets.map { |t| t + '.testresult' }.join(' ')} test_summary"
mkfile.puts "test: #{test_targets.map { |t| "#{t}.testresult" }.join(' ')} test_summary"
mkfile.puts ''
end
+4 -1
View File
@@ -117,7 +117,10 @@ end
namespace :style do
desc "Check style"
task :check do
report "\nVERIFYING RUBY STYLE"
report "\n"
report "--------------------\n"
report "VERIFYING RUBY STYLE\n"
report "--------------------\n"
report execute("rubocop ../lib ../examples ../config ../scripts --config ../vendor/unity/test/.rubocop.yml", true)
report "Styling Ruby:PASS"
end
+4
View File
@@ -396,6 +396,10 @@ module RakefileHelpers
end
def run_examples()
report "\n"
report "-----------------\n"
report "VALIDATE EXAMPLES\n"
report "-----------------\n"
[ "cd #{File.join("..","examples","make_example")} && make clean && make setup && make test",
"cd #{File.join("..","examples","temp_sensor")} && rake ci"
].each do |cmd|
+1 -1