diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 483739b7..057c02fb 100755 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -45,6 +45,7 @@ def self.default_options cmdline_args: false, omit_begin_end: false, use_param_tests: false, + use_system_files: true, include_extensions: '(?:hpp|hh|H|h)', source_extensions: '(?:cpp|cc|ino|C|c)' } @@ -69,7 +70,7 @@ def run(input_file, output_file, options = nil) source = source.force_encoding('ISO-8859-1').encode('utf-8', replace: nil) tests = find_tests(source) headers = find_includes(source) - testfile_includes = (headers[:local] + headers[:system]) + testfile_includes = @options[:use_system_files] ? (headers[:local] + headers[:system]) : (headers[:local]) used_mocks = find_mocks(testfile_includes) testfile_includes = (testfile_includes - used_mocks) testfile_includes.delete_if { |inc| inc =~ /(unity|cmock)/ } @@ -80,7 +81,7 @@ def run(input_file, output_file, options = nil) # determine which files were used to return them all_files_used = [input_file, output_file] - all_files_used += testfile_includes.map { |filename| filename + '.c' } unless testfile_includes.empty? + all_files_used += testfile_includes.map { |filename| "#{filename}.c" } unless testfile_includes.empty? all_files_used += @options[:includes] unless @options[:includes].empty? all_files_used += headers[:linkonly] unless headers[:linkonly].empty? all_files_used.uniq @@ -144,12 +145,12 @@ def find_tests(source) if @options[:use_param_tests] && !arguments.empty? args = [] type_and_args = arguments.split(/TEST_(CASE|RANGE|MATRIX)/) - for i in (1...type_and_args.length).step(2) + (1...type_and_args.length).step(2).each do |i| case type_and_args[i] - when "CASE" + when 'CASE' args << type_and_args[i + 1].sub(/^\s*\(\s*(.*?)\s*\)\s*$/m, '\1') - when "RANGE" + when 'RANGE' args += type_and_args[i + 1].scan(/(\[|<)\s*(-?\d+.?\d*)\s*,\s*(-?\d+.?\d*)\s*,\s*(-?\d+.?\d*)\s*(\]|>)/m).map do |arg_values_str| exclude_end = arg_values_str[0] == '<' && arg_values_str[-1] == '>' arg_values_str[1...-1].map do |arg_value_str| @@ -163,13 +164,13 @@ def find_tests(source) arg_combinations.flatten.join(', ') end - when "MATRIX" - single_arg_regex_string = /(?:(?:"(?:\\"|[^\\])*?")+|(?:'\\?.')+|(?:[^\s\]\["'\,]|\[[\d\S_-]+\])+)/.source + when 'MATRIX' + single_arg_regex_string = /(?:(?:"(?:\\"|[^\\])*?")+|(?:'\\?.')+|(?:[^\s\]\["',]|\[[\d\S_-]+\])+)/.source args_regex = /\[((?:\s*#{single_arg_regex_string}\s*,?)*(?:\s*#{single_arg_regex_string})?\s*)\]/m arg_elements_regex = /\s*(#{single_arg_regex_string})\s*,\s*/m args += type_and_args[i + 1].scan(args_regex).flatten.map do |arg_values_str| - (arg_values_str + ',').scan(arg_elements_regex) + ("#{arg_values_str},").scan(arg_elements_regex) end.reduce do |result, arg_range_expanded| result.product(arg_range_expanded) end.map do |arg_combinations| @@ -188,7 +189,7 @@ def find_tests(source) source_lines = source.split("\n") source_index = 0 tests_and_line_numbers.size.times do |i| - source_lines[source_index..-1].each_with_index do |line, index| + source_lines[source_index..].each_with_index do |line, index| next unless line =~ /\s+#{tests_and_line_numbers[i][:test]}(?:\s|\()/ source_index += index @@ -210,7 +211,7 @@ def find_includes(source) { local: source.scan(/^\s*#include\s+"\s*(.+\.#{@options[:include_extensions]})\s*"/).flatten, system: source.scan(/^\s*#include\s+<\s*(.+)\s*>/).flatten.map { |inc| "<#{inc}>" }, - linkonly: source.scan(/^TEST_SOURCE_FILE\(\s*\"\s*(.+\.#{@options[:source_extensions]})\s*\"/).flatten + linkonly: source.scan(/^TEST_SOURCE_FILE\(\s*"\s*(.+\.#{@options[:source_extensions]})\s*"/).flatten } end @@ -368,7 +369,7 @@ def create_run_test(output) require 'erb' file = File.read(File.join(__dir__, 'run_test.erb')) template = ERB.new(file, trim_mode: '<>') - output.puts("\n" + template.result(binding)) + output.puts("\n#{template.result(binding)}") end def create_args_wrappers(output, tests) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index 864104be..aa306e2c 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -56,7 +56,7 @@ def set_xml_output # Set the flag to indicate if there will be an XML output file or not def test_suite_name=(cli_arg) @real_test_suite_name = cli_arg - puts 'Real test suite name will be \'' + @real_test_suite_name + '\'' + puts "Real test suite name will be '#{@real_test_suite_name}'" end def xml_encode_s(str) @@ -75,7 +75,7 @@ def write_xml_output # Pushes the suite info as xml to the array list, which will be written later def push_xml_output_suite_info # Insert opening tag at front - heading = '' + heading = "" @array_list.insert(0, heading) # Push back the closing tag @array_list.push '' @@ -83,20 +83,20 @@ def push_xml_output_suite_info # Pushes xml output data to the array list, which will be written later def push_xml_output_passed(test_name, execution_time = 0) - @array_list.push ' ' + @array_list.push " " end # Pushes xml output data to the array list, which will be written later def push_xml_output_failed(test_name, reason, execution_time = 0) - @array_list.push ' ' - @array_list.push ' ' + reason + '' + @array_list.push " " + @array_list.push " #{reason}" @array_list.push ' ' end # Pushes xml output data to the array list, which will be written later def push_xml_output_ignored(test_name, reason, execution_time = 0) - @array_list.push ' ' - @array_list.push ' ' + reason + '' + @array_list.push " " + @array_list.push " #{reason}" @array_list.push ' ' end @@ -144,7 +144,7 @@ def test_failed_unity_fixture(array) test_name = array[1] test_suite_verify(class_name) reason_array = array[2].split(':') - reason = reason_array[-1].lstrip.chomp + ' at line: ' + reason_array[-4] + reason = "#{reason_array[-1].lstrip.chomp} at line: #{reason_array[-4]}" printf "%-40s FAILED\n", test_name @@ -189,12 +189,12 @@ def test_passed(array) def test_failed(array) # ':' symbol will be valid in function args now real_method_name = array[@result_usual_idx - 1..-3].join(':') - array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..-1] + array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..] last_item = array.length - 1 test_time = get_test_time(array[last_item]) test_name = array[last_item - 2] - reason = array[last_item].chomp.lstrip + ' at line: ' + array[last_item - 3] + reason = "#{array[last_item].chomp.lstrip} at line: #{array[last_item - 3]}" class_name = array[@class_name_idx] if test_name.start_with? 'TEST(' @@ -217,7 +217,7 @@ def test_failed(array) def test_ignored(array) # ':' symbol will be valid in function args now real_method_name = array[@result_usual_idx - 1..-3].join(':') - array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..-1] + array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..] last_item = array.length - 1 test_time = get_test_time(array[last_item]) @@ -268,7 +268,7 @@ def detect_os_specifics(line) def process(file_name) @array_list = [] - puts 'Parsing file: ' + file_name + puts "Parsing file: #{file_name}" @test_passed = 0 @test_failed = 0 @@ -333,17 +333,17 @@ def process(file_name) @test_ignored += 1 elsif line_array.size >= 4 # We will check output from color compilation - if line_array[@result_usual_idx..-1].any? { |l| l.include? 'PASS' } + if line_array[@result_usual_idx..].any? { |l| l.include? 'PASS' } test_passed(line_array) @test_passed += 1 - elsif line_array[@result_usual_idx..-1].any? { |l| l.include? 'FAIL' } + elsif line_array[@result_usual_idx..].any? { |l| l.include? 'FAIL' } test_failed(line_array) @test_failed += 1 elsif line_array[@result_usual_idx..-2].any? { |l| l.include? 'IGNORE' } test_ignored(line_array) @test_ignored += 1 - elsif line_array[@result_usual_idx..-1].any? { |l| l.include? 'IGNORE' } - line_array.push('No reason given (' + get_test_time(line_array[@result_usual_idx..-1]).to_s + ' ms)') + elsif line_array[@result_usual_idx..].any? { |l| l.include? 'IGNORE' } + line_array.push("No reason given (#{get_test_time(line_array[@result_usual_idx..])} ms)") test_ignored(line_array) @test_ignored += 1 end @@ -353,9 +353,9 @@ def process(file_name) puts '' puts '=================== SUMMARY =====================' puts '' - puts 'Tests Passed : ' + @test_passed.to_s - puts 'Tests Failed : ' + @test_failed.to_s - puts 'Tests Ignored : ' + @test_ignored.to_s + puts "Tests Passed : #{@test_passed}" + puts "Tests Failed : #{@test_failed}" + puts "Tests Ignored : #{@test_ignored}" return unless @xml_out diff --git a/auto/stylize_as_junit.rb b/auto/stylize_as_junit.rb index e01f7912..e4b911eb 100755 --- a/auto/stylize_as_junit.rb +++ b/auto/stylize_as_junit.rb @@ -99,7 +99,7 @@ def run test_file = if test_file_str.length < 2 result_file else - test_file_str[0] + ':' + test_file_str[1] + "#{test_file_str[0]}:#{test_file_str[1]}" end result_output[:source][:path] = File.dirname(test_file) result_output[:source][:file] = File.basename(test_file) diff --git a/auto/unity_test_summary.rb b/auto/unity_test_summary.rb index 0253b5d7..03d67a68 100644 --- a/auto/unity_test_summary.rb +++ b/auto/unity_test_summary.rb @@ -112,7 +112,7 @@ def parse_test_summary(summary) # parse out the command options opts, args = ARGV.partition { |v| v =~ /^--\w+/ } - opts.map! { |v| v[2..-1].to_sym } + opts.map! { |v| v[2..].to_sym } # create an instance to work with uts = UnityTestSummary.new(opts) @@ -128,7 +128,7 @@ def parse_test_summary(summary) uts.targets = results # set the root path - args[1] ||= Dir.pwd + '/' + args[1] ||= "#{Dir.pwd}/" uts.root = ARGV[1] # run the summarizer diff --git a/examples/example_3/rakefile_helper.rb b/examples/example_3/rakefile_helper.rb index d88df584..cbc4549f 100644 --- a/examples/example_3/rakefile_helper.rb +++ b/examples/example_3/rakefile_helper.rb @@ -17,7 +17,7 @@ def load_configuration(config_file) 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) @@ -27,7 +27,7 @@ def configure_toolchain(config_file = DEFAULT_CONFIG_FILE) 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 @@ -111,11 +111,11 @@ def build_linker_fields def link_it(exe_name, obj_list) linker = build_linker_fields - cmd_str = "#{linker[:command]}#{linker[:options]}#{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'] + cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]}" + cmd_str += " #{(obj_list.map { |obj| "#{$cfg['linker']['object_files']['path']}#{obj}" }).join(' ')}" + cmd_str += " #{$cfg['linker']['bin_files']['prefix']} " + cmd_str += $cfg['linker']['bin_files']['destination'] + cmd_str += exe_name + $cfg['linker']['bin_files']['extension'] execute(cmd_str) end @@ -125,7 +125,7 @@ def build_simulator_fields command = if $cfg['simulator']['path'].nil? '' else - (tackit($cfg['simulator']['path']) + ' ') + "#{tackit($cfg['simulator']['path'])} " end pre_support = if $cfg['simulator']['pre_support'].nil? '' @@ -188,7 +188,7 @@ def run_tests(test_files) # 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($cfg_file) diff --git a/test/.rubocop.yml b/test/.rubocop.yml index 44b01605..a3b811bd 100644 --- a/test/.rubocop.yml +++ b/test/.rubocop.yml @@ -28,6 +28,8 @@ Style/EvalWithLocation: Enabled: false Style/MixinUsage: Enabled: false +Style/OptionalBooleanParameter: + Enabled: false # These are also places we diverge... but we will likely comply down the road Style/IfUnlessModifier: