mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-05 21:15:20 +00:00
Further style changes to match standard.
Pull in latest Unity. Update testing parameters to include Ruby 2.7
This commit is contained in:
+15
-8
@@ -1,12 +1,19 @@
|
||||
language: ruby
|
||||
sudo: required
|
||||
language: ruby c
|
||||
|
||||
os:
|
||||
- linux
|
||||
|
||||
rvm:
|
||||
- "2.3"
|
||||
- "2.4"
|
||||
- "2.6"
|
||||
matrix:
|
||||
include:
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode7.3
|
||||
- os: linux
|
||||
dist: trusty
|
||||
rvm: "2.4"
|
||||
compiler: gcc
|
||||
- os: linux
|
||||
dist: xenial
|
||||
rvm: "2.7"
|
||||
compiler: clang
|
||||
|
||||
before_install:
|
||||
- sudo apt-get install --assume-yes --quiet gcc-multilib
|
||||
|
||||
@@ -17,7 +17,7 @@ DEFAULT_CONFIG_FILE = 'gcc.yml'.freeze
|
||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||
|
||||
task :unit do
|
||||
run_tests(get_unit_test_files)
|
||||
run_tests(unit_test_files)
|
||||
end
|
||||
|
||||
desc 'Generate test summary'
|
||||
|
||||
@@ -25,13 +25,13 @@ module RakefileHelpers
|
||||
configure_clean
|
||||
end
|
||||
|
||||
def get_unit_test_files
|
||||
def unit_test_files
|
||||
path = $cfg['compiler']['unit_tests_path'] + 'Test*' + C_EXTENSION
|
||||
path.gsub!(/\\/, '/')
|
||||
FileList.new(path)
|
||||
end
|
||||
|
||||
def get_local_include_dirs
|
||||
def local_include_dirs
|
||||
include_dirs = $cfg['compiler']['includes']['items'].dup
|
||||
include_dirs.delete_if { |dir| dir.is_a?(Array) }
|
||||
include_dirs
|
||||
@@ -178,7 +178,7 @@ module RakefileHelpers
|
||||
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
|
||||
$cfg['compiler']['defines']['items'] << 'TEST'
|
||||
|
||||
include_dirs = get_local_include_dirs
|
||||
include_dirs = local_include_dirs
|
||||
|
||||
# Build and execute each unit test
|
||||
test_files.each do |test|
|
||||
@@ -250,7 +250,7 @@ module RakefileHelpers
|
||||
main_path = $cfg['compiler']['source_path'] + main + C_EXTENSION
|
||||
|
||||
# Detect dependencies and build required required modules
|
||||
include_dirs = get_local_include_dirs
|
||||
include_dirs = local_include_dirs
|
||||
extract_headers(main_path).each do |header|
|
||||
src_file = find_source_file(header, include_dirs)
|
||||
unless src_file.nil?
|
||||
|
||||
+7
-7
@@ -5,7 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
class CMockConfig
|
||||
CMockDefaultOptions =
|
||||
CMOCK_DEFAULT_OPTIONS =
|
||||
{
|
||||
:framework => :unity,
|
||||
:mock_path => 'mocks',
|
||||
@@ -50,13 +50,13 @@ class CMockConfig
|
||||
# so we check for word boundaries when searching for them
|
||||
# - We first remove "static inline" combinations and boil down to single inline or static statements
|
||||
:inline_function_patterns => ['(static\s+inline|inline\s+static)\s*', '(\bstatic\b|\binline\b)\s*'] # Last part (\s*) is just to remove whitespaces (only to prettify the output)
|
||||
}
|
||||
}.freeze
|
||||
|
||||
def initialize(options = nil)
|
||||
case options
|
||||
when NilClass then options = CMockDefaultOptions.clone
|
||||
when String then options = CMockDefaultOptions.clone.merge(load_config_file_from_yaml(options))
|
||||
when Hash then options = CMockDefaultOptions.clone.merge(options)
|
||||
when NilClass then options = CMOCK_DEFAULT_OPTIONS.dup
|
||||
when String then options = CMOCK_DEFAULT_OPTIONS.dup.merge(load_config_file_from_yaml(options))
|
||||
when Hash then options = CMOCK_DEFAULT_OPTIONS.dup.merge(options)
|
||||
else raise 'If you specify arguments, it should be a filename or a hash of options'
|
||||
end
|
||||
|
||||
@@ -110,8 +110,8 @@ class CMockConfig
|
||||
YAML.load_file(yaml_filename)[:cmock]
|
||||
end
|
||||
|
||||
def set_path(path)
|
||||
@src_path = path
|
||||
def path(new_path)
|
||||
@src_path = new_path
|
||||
end
|
||||
|
||||
def load_unity_helper
|
||||
|
||||
@@ -12,14 +12,9 @@ class CMockFileWriter
|
||||
end
|
||||
|
||||
def create_subdir(subdir)
|
||||
unless Dir.exist?("#{@config.mock_path}/")
|
||||
require 'fileutils'
|
||||
FileUtils.mkdir_p "#{@config.mock_path}/"
|
||||
end
|
||||
if subdir && !Dir.exist?("#{@config.mock_path}/#{subdir + '/' if subdir}")
|
||||
require 'fileutils'
|
||||
FileUtils.mkdir_p "#{@config.mock_path}/#{subdir + '/' if subdir}"
|
||||
end
|
||||
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}")
|
||||
end
|
||||
|
||||
def create_file(filename, subdir)
|
||||
|
||||
@@ -298,13 +298,13 @@ class CMockGenerator
|
||||
|
||||
decl = "#{function_mod_and_rettype} #{function[:name]}(#{args_string})"
|
||||
|
||||
unless existing.include?(decl)
|
||||
file << "#{decl}\n"
|
||||
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 << "}\n\n"
|
||||
end
|
||||
return if existing.include?(decl)
|
||||
|
||||
file << "#{decl}\n"
|
||||
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 << "}\n\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -42,14 +42,12 @@ class CMockGeneratorPluginExpect
|
||||
"#define #{function[:name]}_ExpectAndReturn(cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, cmock_retval)\n" \
|
||||
"void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
||||
end
|
||||
elsif function[:return][:void?]
|
||||
"#define #{function[:name]}_Expect(#{function[:args_call]}) #{function[:name]}_CMockExpect(__LINE__, #{function[:args_call]})\n" \
|
||||
"void #{function[:name]}_CMockExpect(UNITY_LINE_TYPE cmock_line, #{function[:args_string]});\n"
|
||||
else
|
||||
if function[:return][:void?]
|
||||
"#define #{function[:name]}_Expect(#{function[:args_call]}) #{function[:name]}_CMockExpect(__LINE__, #{function[:args_call]})\n" \
|
||||
"void #{function[:name]}_CMockExpect(UNITY_LINE_TYPE cmock_line, #{function[:args_string]});\n"
|
||||
else
|
||||
"#define #{function[:name]}_ExpectAndReturn(#{function[:args_call]}, cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, #{function[:args_call]}, cmock_retval)\n" \
|
||||
"void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, #{function[:return][:str]});\n"
|
||||
end
|
||||
"#define #{function[:name]}_ExpectAndReturn(#{function[:args_call]}, cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, #{function[:args_call]}, cmock_retval)\n" \
|
||||
"void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, #{function[:return][:str]});\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -81,12 +79,10 @@ class CMockGeneratorPluginExpect
|
||||
else
|
||||
"void #{func_name}_CMockExpect(UNITY_LINE_TYPE cmock_line, #{function[:args_string]})\n{\n"
|
||||
end
|
||||
elsif function[:args_string] == 'void'
|
||||
"void #{func_name}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
||||
else
|
||||
if function[:args_string] == 'void'
|
||||
"void #{func_name}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
||||
else
|
||||
"void #{func_name}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, #{function[:return][:str]})\n{\n"
|
||||
end
|
||||
"void #{func_name}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, #{function[:return][:str]})\n{\n"
|
||||
end
|
||||
lines << @utils.code_add_base_expectation(func_name)
|
||||
lines << @utils.code_call_argument_loader(function)
|
||||
|
||||
@@ -21,14 +21,12 @@ class CMockGeneratorPluginExpectAnyArgs
|
||||
def mock_function_declarations(function)
|
||||
if function[:args].empty?
|
||||
''
|
||||
elsif function[:return][:void?]
|
||||
"#define #{function[:name]}_ExpectAnyArgs() #{function[:name]}_CMockExpectAnyArgs(__LINE__)\n" \
|
||||
"void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n"
|
||||
else
|
||||
if function[:return][:void?]
|
||||
"#define #{function[:name]}_ExpectAnyArgs() #{function[:name]}_CMockExpectAnyArgs(__LINE__)\n" \
|
||||
"void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n"
|
||||
else
|
||||
"#define #{function[:name]}_ExpectAnyArgsAndReturn(cmock_retval) #{function[:name]}_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n" \
|
||||
"void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
||||
end
|
||||
"#define #{function[:name]}_ExpectAnyArgsAndReturn(cmock_retval) #{function[:name]}_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n" \
|
||||
"void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ class CMockHeaderParser
|
||||
# 1. Determine if we are dealing with a user defined macro to declare inline functions
|
||||
# If the end of the pre-match string is a macro-declaration-like string,
|
||||
# we are dealing with a user defined macro to declare inline functions
|
||||
if /(#define\s*)\z/ === inline_function_match.pre_match
|
||||
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]?)/, '')
|
||||
@@ -155,7 +155,7 @@ class CMockHeaderParser
|
||||
# 2. Determine if we are dealing with an inline function declaration iso function definition
|
||||
# If the start of the post-match string is a function-declaration-like string (something ending with semicolon after the function arguments),
|
||||
# we are dealing with a inline function declaration
|
||||
if /\A#{@function_declaration_parse_base_match}\s*;/m === inline_function_match.post_match
|
||||
if /\A#{@function_declaration_parse_base_match}\s*;/m =~ inline_function_match.post_match
|
||||
# Only remove the inline part from the function declaration, leaving the function declaration won't do any harm
|
||||
source = inline_function_match.pre_match + inline_function_match.post_match
|
||||
next
|
||||
@@ -367,9 +367,11 @@ class CMockHeaderParser
|
||||
def divine_const(arg)
|
||||
# a non-pointer arg containing "const" is a constant
|
||||
# an arg containing "const" before the last * is a pointer to a constant
|
||||
(arg.include?('*') ? (/(^|\s|\*)const(\s(\w|\s)*)?\*(?!.*\*)/ =~ arg)
|
||||
: (/(^|\s)const(\s|$)/ =~ arg)
|
||||
) ? true : false
|
||||
if arg.include?('*') ? (/(^|\s|\*)const(\s(\w|\s)*)?\*(?!.*\*)/ =~ arg) : (/(^|\s)const(\s|$)/ =~ arg)
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def divine_ptr_and_const(arg)
|
||||
|
||||
@@ -13,7 +13,7 @@ class CMockPluginManager
|
||||
plugins_to_load.each do |plugin|
|
||||
plugin_name = plugin.to_s
|
||||
object_name = 'CMockGeneratorPlugin' + camelize(plugin_name)
|
||||
self.class.plugin_require_mutex.synchronize { load_plugin(plugin_name, object_name, config, utils) }
|
||||
self.class.mutex.synchronize { load_plugin(plugin_name, object_name, config, utils) }
|
||||
end
|
||||
@plugins.sort! { |a, b| a.priority <=> b.priority }
|
||||
end
|
||||
@@ -30,12 +30,12 @@ class CMockPluginManager
|
||||
lower_case_and_underscored_word.gsub(/\/(.?)/) { '::' + Regexp.last_match(1).upcase }.gsub(/(^|_)(.)/) { Regexp.last_match(2).upcase }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.plugin_require_mutex
|
||||
def self.mutex
|
||||
@mutex ||= Mutex.new
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_plugin(plugin_name, object_name, config, utils)
|
||||
unless Object.const_defined? object_name
|
||||
file_name = "#{__dir__}/cmock_generator_plugin_#{plugin_name.downcase}.rb"
|
||||
|
||||
@@ -10,7 +10,7 @@ class CMockUnityHelperParser
|
||||
def initialize(config)
|
||||
@config = config
|
||||
@fallback = @config.plugins.include?(:array) ? 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY' : 'UNITY_TEST_ASSERT_EQUAL_MEMORY'
|
||||
@c_types = map_C_types.merge(import_source)
|
||||
@c_types = map_c_types.merge(import_source)
|
||||
end
|
||||
|
||||
def get_helper(ctype)
|
||||
@@ -32,7 +32,7 @@ class CMockUnityHelperParser
|
||||
|
||||
private ###########################
|
||||
|
||||
def map_C_types
|
||||
def map_c_types
|
||||
c_types = {}
|
||||
@config.treat_as.each_pair do |ctype, expecttype|
|
||||
c_type = ctype.gsub(/\s+/, '_')
|
||||
|
||||
@@ -14,6 +14,5 @@ if $0 == __FILE__
|
||||
|
||||
test = ARGV[0]
|
||||
runner = ARGV[1]
|
||||
generator = UnityTestRunnerGenerator.new.run(test, runner)
|
||||
|
||||
UnityTestRunnerGenerator.new.run(test, runner)
|
||||
end
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ configure_clean
|
||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||
|
||||
task :default => [:test]
|
||||
task :ci => [:no_color, :default]
|
||||
task :ci => [:no_color, :default, 'style:check', 'style:c']
|
||||
task :cruise => :ci
|
||||
|
||||
desc "Load configuration"
|
||||
@@ -43,7 +43,7 @@ task :config, :config_file do |t, args|
|
||||
end
|
||||
|
||||
# Still support testing everything with just 'test' but switch default to ceedling-like test:all
|
||||
task :test => [:clobber, :prep_system_tests, 'test:units', 'test:c', 'test:system']
|
||||
task :test => ['test:all']
|
||||
|
||||
namespace :test do
|
||||
desc "Run all unit, c, and system tests"
|
||||
|
||||
@@ -13,34 +13,34 @@ describe CMockConfig, "Verify CMockConfig Module" do
|
||||
|
||||
it "use default settings when no parameters are specified" do
|
||||
config = CMockConfig.new
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
||||
assert_nil(CMockConfig::CMockDefaultOptions[:includes])
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path)
|
||||
assert_nil(CMockConfig::CMOCK_DEFAULT_OPTIONS[:includes])
|
||||
assert_nil(config.includes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:attributes], config.attributes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_inlines], config.treat_inlines)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:inline_function_patterns], config.inline_function_patterns)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:attributes], config.attributes)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_externs], config.treat_externs)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_inlines], config.treat_inlines)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:inline_function_patterns], config.inline_function_patterns)
|
||||
end
|
||||
|
||||
it "replace only options specified in a hash" do
|
||||
test_includes = ['hello']
|
||||
test_attributes = ['blah', 'bleh']
|
||||
config = CMockConfig.new(:includes => test_includes, :attributes => test_attributes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path)
|
||||
assert_equal(test_includes, config.includes)
|
||||
assert_equal(test_attributes, config.attributes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_inlines], config.treat_inlines)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:inline_function_patterns], config.inline_function_patterns)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_externs], config.treat_externs)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_inlines], config.treat_inlines)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:inline_function_patterns], config.inline_function_patterns)
|
||||
end
|
||||
|
||||
it "replace only options specified in a yaml file" do
|
||||
test_plugins = [:soda, :pizza]
|
||||
config = CMockConfig.new("#{File.expand_path(File.dirname(__FILE__))}/cmock_config_test.yml")
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
||||
assert_nil(CMockConfig::CMockDefaultOptions[:includes])
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path)
|
||||
assert_nil(CMockConfig::CMOCK_DEFAULT_OPTIONS[:includes])
|
||||
assert_nil(config.includes)
|
||||
assert_equal(test_plugins, config.plugins)
|
||||
assert_equal(:include, config.treat_externs)
|
||||
|
||||
Vendored
+1
-1
Submodule vendor/unity updated: 8c4ae7aacd...615cf2349e
Reference in New Issue
Block a user