From 9b393ad4fbc62029b52410a42be87139aac895e9 Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Thu, 19 Mar 2020 10:00:12 -0400 Subject: [PATCH] Further style changes to match standard. Pull in latest Unity. Update testing parameters to include Ruby 2.7 --- .travis.yml | 23 +++++++++------ examples/temp_sensor/rakefile.rb | 2 +- examples/temp_sensor/rakefile_helper.rb | 8 +++--- lib/cmock_config.rb | 14 +++++----- lib/cmock_file_writer.rb | 11 ++------ lib/cmock_generator.rb | 16 +++++------ lib/cmock_generator_plugin_expect.rb | 20 ++++++------- lib/cmock_generator_plugin_expect_any_args.rb | 12 ++++---- lib/cmock_header_parser.rb | 12 ++++---- lib/cmock_plugin_manager.rb | 8 +++--- lib/cmock_unityhelper_parser.rb | 4 +-- scripts/create_runner.rb | 3 +- test/rakefile | 4 +-- test/unit/cmock_config_test.rb | 28 +++++++++---------- vendor/unity | 2 +- 15 files changed, 82 insertions(+), 85 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9b143b8..9f58a33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/examples/temp_sensor/rakefile.rb b/examples/temp_sensor/rakefile.rb index 8d87293..06ab1d5 100644 --- a/examples/temp_sensor/rakefile.rb +++ b/examples/temp_sensor/rakefile.rb @@ -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' diff --git a/examples/temp_sensor/rakefile_helper.rb b/examples/temp_sensor/rakefile_helper.rb index 021eb3a..7b4e6dd 100644 --- a/examples/temp_sensor/rakefile_helper.rb +++ b/examples/temp_sensor/rakefile_helper.rb @@ -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? diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 02892ad..9515481 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -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 diff --git a/lib/cmock_file_writer.rb b/lib/cmock_file_writer.rb index 6c31848..787d688 100644 --- a/lib/cmock_file_writer.rb +++ b/lib/cmock_file_writer.rb @@ -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) diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index 09622ff..8b70c05 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -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 diff --git a/lib/cmock_generator_plugin_expect.rb b/lib/cmock_generator_plugin_expect.rb index 9832631..3a79c1a 100644 --- a/lib/cmock_generator_plugin_expect.rb +++ b/lib/cmock_generator_plugin_expect.rb @@ -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) diff --git a/lib/cmock_generator_plugin_expect_any_args.rb b/lib/cmock_generator_plugin_expect_any_args.rb index 1261792..1ef3880 100644 --- a/lib/cmock_generator_plugin_expect_any_args.rb +++ b/lib/cmock_generator_plugin_expect_any_args.rb @@ -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 diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 9e72501..632513d 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -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) diff --git a/lib/cmock_plugin_manager.rb b/lib/cmock_plugin_manager.rb index bc7be48..342014e 100644 --- a/lib/cmock_plugin_manager.rb +++ b/lib/cmock_plugin_manager.rb @@ -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" diff --git a/lib/cmock_unityhelper_parser.rb b/lib/cmock_unityhelper_parser.rb index d30d322..3423138 100644 --- a/lib/cmock_unityhelper_parser.rb +++ b/lib/cmock_unityhelper_parser.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+/, '_') diff --git a/scripts/create_runner.rb b/scripts/create_runner.rb index 23bf23d..6219805 100644 --- a/scripts/create_runner.rb +++ b/scripts/create_runner.rb @@ -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 diff --git a/test/rakefile b/test/rakefile index 06dc98f..3832ecb 100644 --- a/test/rakefile +++ b/test/rakefile @@ -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" diff --git a/test/unit/cmock_config_test.rb b/test/unit/cmock_config_test.rb index aa081aa..8c5e410 100644 --- a/test/unit/cmock_config_test.rb +++ b/test/unit/cmock_config_test.rb @@ -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) diff --git a/vendor/unity b/vendor/unity index 8c4ae7a..615cf23 160000 --- a/vendor/unity +++ b/vendor/unity @@ -1 +1 @@ -Subproject commit 8c4ae7aacd18a1abb35b42fc644972052c99d555 +Subproject commit 615cf2349e700aa2aae7d166c33d340a82cc1d41