Catch up on Ruby style and formatting changes.

This commit is contained in:
Mark VanderVoord
2023-11-12 19:07:32 -05:00
parent bd32847abf
commit 3f7564ea3b
6 changed files with 45 additions and 42 deletions

View File

@ -45,6 +45,7 @@ class UnityTestRunnerGenerator
cmdline_args: false, cmdline_args: false,
omit_begin_end: false, omit_begin_end: false,
use_param_tests: false, use_param_tests: false,
use_system_files: true,
include_extensions: '(?:hpp|hh|H|h)', include_extensions: '(?:hpp|hh|H|h)',
source_extensions: '(?:cpp|cc|ino|C|c)' source_extensions: '(?:cpp|cc|ino|C|c)'
} }
@ -69,7 +70,7 @@ class UnityTestRunnerGenerator
source = source.force_encoding('ISO-8859-1').encode('utf-8', replace: nil) source = source.force_encoding('ISO-8859-1').encode('utf-8', replace: nil)
tests = find_tests(source) tests = find_tests(source)
headers = find_includes(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) used_mocks = find_mocks(testfile_includes)
testfile_includes = (testfile_includes - used_mocks) testfile_includes = (testfile_includes - used_mocks)
testfile_includes.delete_if { |inc| inc =~ /(unity|cmock)/ } testfile_includes.delete_if { |inc| inc =~ /(unity|cmock)/ }
@ -80,7 +81,7 @@ class UnityTestRunnerGenerator
# determine which files were used to return them # determine which files were used to return them
all_files_used = [input_file, output_file] 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 += @options[:includes] unless @options[:includes].empty?
all_files_used += headers[:linkonly] unless headers[:linkonly].empty? all_files_used += headers[:linkonly] unless headers[:linkonly].empty?
all_files_used.uniq all_files_used.uniq
@ -144,12 +145,12 @@ class UnityTestRunnerGenerator
if @options[:use_param_tests] && !arguments.empty? if @options[:use_param_tests] && !arguments.empty?
args = [] args = []
type_and_args = arguments.split(/TEST_(CASE|RANGE|MATRIX)/) 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] case type_and_args[i]
when "CASE" when 'CASE'
args << type_and_args[i + 1].sub(/^\s*\(\s*(.*?)\s*\)\s*$/m, '\1') 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| 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] == '>' exclude_end = arg_values_str[0] == '<' && arg_values_str[-1] == '>'
arg_values_str[1...-1].map do |arg_value_str| arg_values_str[1...-1].map do |arg_value_str|
@ -163,13 +164,13 @@ class UnityTestRunnerGenerator
arg_combinations.flatten.join(', ') arg_combinations.flatten.join(', ')
end end
when "MATRIX" when 'MATRIX'
single_arg_regex_string = /(?:(?:"(?:\\"|[^\\])*?")+|(?:'\\?.')+|(?:[^\s\]\["'\,]|\[[\d\S_-]+\])+)/.source single_arg_regex_string = /(?:(?:"(?:\\"|[^\\])*?")+|(?:'\\?.')+|(?:[^\s\]\["',]|\[[\d\S_-]+\])+)/.source
args_regex = /\[((?:\s*#{single_arg_regex_string}\s*,?)*(?:\s*#{single_arg_regex_string})?\s*)\]/m 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 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| 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| end.reduce do |result, arg_range_expanded|
result.product(arg_range_expanded) result.product(arg_range_expanded)
end.map do |arg_combinations| end.map do |arg_combinations|
@ -188,7 +189,7 @@ class UnityTestRunnerGenerator
source_lines = source.split("\n") source_lines = source.split("\n")
source_index = 0 source_index = 0
tests_and_line_numbers.size.times do |i| 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|\()/ next unless line =~ /\s+#{tests_and_line_numbers[i][:test]}(?:\s|\()/
source_index += index source_index += index
@ -210,7 +211,7 @@ class UnityTestRunnerGenerator
{ {
local: source.scan(/^\s*#include\s+"\s*(.+\.#{@options[:include_extensions]})\s*"/).flatten, local: source.scan(/^\s*#include\s+"\s*(.+\.#{@options[:include_extensions]})\s*"/).flatten,
system: source.scan(/^\s*#include\s+<\s*(.+)\s*>/).flatten.map { |inc| "<#{inc}>" }, 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 end
@ -368,7 +369,7 @@ class UnityTestRunnerGenerator
require 'erb' require 'erb'
file = File.read(File.join(__dir__, 'run_test.erb')) file = File.read(File.join(__dir__, 'run_test.erb'))
template = ERB.new(file, trim_mode: '<>') template = ERB.new(file, trim_mode: '<>')
output.puts("\n" + template.result(binding)) output.puts("\n#{template.result(binding)}")
end end
def create_args_wrappers(output, tests) def create_args_wrappers(output, tests)

View File

@ -56,7 +56,7 @@ class ParseOutput
# Set the flag to indicate if there will be an XML output file or not # Set the flag to indicate if there will be an XML output file or not
def test_suite_name=(cli_arg) def test_suite_name=(cli_arg)
@real_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 end
def xml_encode_s(str) def xml_encode_s(str)
@ -75,7 +75,7 @@ class ParseOutput
# Pushes the suite info as xml to the array list, which will be written later # Pushes the suite info as xml to the array list, which will be written later
def push_xml_output_suite_info def push_xml_output_suite_info
# Insert opening tag at front # Insert opening tag at front
heading = '<testsuite name=' + xml_encode_s(@real_test_suite_name) + ' tests="' + @total_tests.to_s + '" failures="' + @test_failed.to_s + '"' + ' skips="' + @test_ignored.to_s + '">' heading = "<testsuite name=#{xml_encode_s(@real_test_suite_name)} tests=\"#{@total_tests}\" failures=\"#{@test_failed}\" skips=\"#{@test_ignored}\">"
@array_list.insert(0, heading) @array_list.insert(0, heading)
# Push back the closing tag # Push back the closing tag
@array_list.push '</testsuite>' @array_list.push '</testsuite>'
@ -83,20 +83,20 @@ class ParseOutput
# Pushes xml output data to the array list, which will be written later # Pushes xml output data to the array list, which will be written later
def push_xml_output_passed(test_name, execution_time = 0) def push_xml_output_passed(test_name, execution_time = 0)
@array_list.push ' <testcase classname=' + xml_encode_s(@test_suite) + ' name=' + xml_encode_s(test_name) + ' time=' + xml_encode_s((execution_time / 1000.0).to_s) + ' />' @array_list.push " <testcase classname=#{xml_encode_s(@test_suite)} name=#{xml_encode_s(test_name)} time=#{xml_encode_s((execution_time / 1000.0).to_s)} />"
end end
# Pushes xml output data to the array list, which will be written later # Pushes xml output data to the array list, which will be written later
def push_xml_output_failed(test_name, reason, execution_time = 0) def push_xml_output_failed(test_name, reason, execution_time = 0)
@array_list.push ' <testcase classname=' + xml_encode_s(@test_suite) + ' name=' + xml_encode_s(test_name) + ' time=' + xml_encode_s((execution_time / 1000.0).to_s) + '>' @array_list.push " <testcase classname=#{xml_encode_s(@test_suite)} name=#{xml_encode_s(test_name)} time=#{xml_encode_s((execution_time / 1000.0).to_s)} >"
@array_list.push ' <failure type="ASSERT FAILED">' + reason + '</failure>' @array_list.push " <failure type=\"ASSERT FAILED\">#{reason}</failure>"
@array_list.push ' </testcase>' @array_list.push ' </testcase>'
end end
# Pushes xml output data to the array list, which will be written later # Pushes xml output data to the array list, which will be written later
def push_xml_output_ignored(test_name, reason, execution_time = 0) def push_xml_output_ignored(test_name, reason, execution_time = 0)
@array_list.push ' <testcase classname=' + xml_encode_s(@test_suite) + ' name=' + xml_encode_s(test_name) + ' time=' + xml_encode_s((execution_time / 1000.0).to_s) + '>' @array_list.push " <testcase classname=#{xml_encode_s(@test_suite)} name=#{xml_encode_s(test_name)} time=#{xml_encode_s((execution_time / 1000.0).to_s)} >"
@array_list.push ' <skipped type="TEST IGNORED">' + reason + '</skipped>' @array_list.push " <skipped type=\"TEST IGNORED\">#{reason}</skipped>"
@array_list.push ' </testcase>' @array_list.push ' </testcase>'
end end
@ -144,7 +144,7 @@ class ParseOutput
test_name = array[1] test_name = array[1]
test_suite_verify(class_name) test_suite_verify(class_name)
reason_array = array[2].split(':') 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 printf "%-40s FAILED\n", test_name
@ -189,12 +189,12 @@ class ParseOutput
def test_failed(array) def test_failed(array)
# ':' symbol will be valid in function args now # ':' symbol will be valid in function args now
real_method_name = array[@result_usual_idx - 1..-3].join(':') 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 last_item = array.length - 1
test_time = get_test_time(array[last_item]) test_time = get_test_time(array[last_item])
test_name = array[last_item - 2] 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] class_name = array[@class_name_idx]
if test_name.start_with? 'TEST(' if test_name.start_with? 'TEST('
@ -217,7 +217,7 @@ class ParseOutput
def test_ignored(array) def test_ignored(array)
# ':' symbol will be valid in function args now # ':' symbol will be valid in function args now
real_method_name = array[@result_usual_idx - 1..-3].join(':') 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 last_item = array.length - 1
test_time = get_test_time(array[last_item]) test_time = get_test_time(array[last_item])
@ -268,7 +268,7 @@ class ParseOutput
def process(file_name) def process(file_name)
@array_list = [] @array_list = []
puts 'Parsing file: ' + file_name puts "Parsing file: #{file_name}"
@test_passed = 0 @test_passed = 0
@test_failed = 0 @test_failed = 0
@ -333,17 +333,17 @@ class ParseOutput
@test_ignored += 1 @test_ignored += 1
elsif line_array.size >= 4 elsif line_array.size >= 4
# We will check output from color compilation # 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(line_array)
@test_passed += 1 @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(line_array)
@test_failed += 1 @test_failed += 1
elsif line_array[@result_usual_idx..-2].any? { |l| l.include? 'IGNORE' } elsif line_array[@result_usual_idx..-2].any? { |l| l.include? 'IGNORE' }
test_ignored(line_array) test_ignored(line_array)
@test_ignored += 1 @test_ignored += 1
elsif line_array[@result_usual_idx..-1].any? { |l| l.include? 'IGNORE' } 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..-1]).to_s + ' ms)') line_array.push("No reason given (#{get_test_time(line_array[@result_usual_idx..])} ms)")
test_ignored(line_array) test_ignored(line_array)
@test_ignored += 1 @test_ignored += 1
end end
@ -353,9 +353,9 @@ class ParseOutput
puts '' puts ''
puts '=================== SUMMARY =====================' puts '=================== SUMMARY ====================='
puts '' puts ''
puts 'Tests Passed : ' + @test_passed.to_s puts "Tests Passed : #{@test_passed}"
puts 'Tests Failed : ' + @test_failed.to_s puts "Tests Failed : #{@test_failed}"
puts 'Tests Ignored : ' + @test_ignored.to_s puts "Tests Ignored : #{@test_ignored}"
return unless @xml_out return unless @xml_out

View File

@ -99,7 +99,7 @@ class UnityToJUnit
test_file = if test_file_str.length < 2 test_file = if test_file_str.length < 2
result_file result_file
else else
test_file_str[0] + ':' + test_file_str[1] "#{test_file_str[0]}:#{test_file_str[1]}"
end end
result_output[:source][:path] = File.dirname(test_file) result_output[:source][:path] = File.dirname(test_file)
result_output[:source][:file] = File.basename(test_file) result_output[:source][:file] = File.basename(test_file)

View File

@ -112,7 +112,7 @@ if $0 == __FILE__
# parse out the command options # parse out the command options
opts, args = ARGV.partition { |v| v =~ /^--\w+/ } 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 # create an instance to work with
uts = UnityTestSummary.new(opts) uts = UnityTestSummary.new(opts)
@ -128,7 +128,7 @@ if $0 == __FILE__
uts.targets = results uts.targets = results
# set the root path # set the root path
args[1] ||= Dir.pwd + '/' args[1] ||= "#{Dir.pwd}/"
uts.root = ARGV[1] uts.root = ARGV[1]
# run the summarizer # run the summarizer

View File

@ -17,7 +17,7 @@ def load_configuration(config_file)
end end
def configure_clean 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 end
def configure_toolchain(config_file = DEFAULT_CONFIG_FILE) def configure_toolchain(config_file = DEFAULT_CONFIG_FILE)
@ -27,7 +27,7 @@ def configure_toolchain(config_file = DEFAULT_CONFIG_FILE)
end end
def unit_test_files def unit_test_files
path = $cfg['compiler']['unit_tests_path'] + 'Test*' + C_EXTENSION path = "#{$cfg['compiler']['unit_tests_path']}Test*#{C_EXTENSION}"
path.tr!('\\', '/') path.tr!('\\', '/')
FileList.new(path) FileList.new(path)
end end
@ -111,11 +111,11 @@ end
def link_it(exe_name, obj_list) def link_it(exe_name, obj_list)
linker = build_linker_fields linker = build_linker_fields
cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " + cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]}"
(obj_list.map { |obj| "#{$cfg['linker']['object_files']['path']}#{obj} " }).join + cmd_str += " #{(obj_list.map { |obj| "#{$cfg['linker']['object_files']['path']}#{obj}" }).join(' ')}"
$cfg['linker']['bin_files']['prefix'] + ' ' + cmd_str += " #{$cfg['linker']['bin_files']['prefix']} "
$cfg['linker']['bin_files']['destination'] + cmd_str += $cfg['linker']['bin_files']['destination']
exe_name + $cfg['linker']['bin_files']['extension'] cmd_str += exe_name + $cfg['linker']['bin_files']['extension']
execute(cmd_str) execute(cmd_str)
end end
@ -125,7 +125,7 @@ def build_simulator_fields
command = if $cfg['simulator']['path'].nil? command = if $cfg['simulator']['path'].nil?
'' ''
else else
(tackit($cfg['simulator']['path']) + ' ') "#{tackit($cfg['simulator']['path'])} "
end end
pre_support = if $cfg['simulator']['pre_support'].nil? 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) # Build the test runner (generate if configured to do so)
test_base = File.basename(test, C_EXTENSION) 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? if $cfg['compiler']['runner_path'].nil?
runner_path = $cfg['compiler']['build_path'] + runner_name runner_path = $cfg['compiler']['build_path'] + runner_name
test_gen = UnityTestRunnerGenerator.new($cfg_file) test_gen = UnityTestRunnerGenerator.new($cfg_file)

View File

@ -28,6 +28,8 @@ Style/EvalWithLocation:
Enabled: false Enabled: false
Style/MixinUsage: Style/MixinUsage:
Enabled: false Enabled: false
Style/OptionalBooleanParameter:
Enabled: false
# These are also places we diverge... but we will likely comply down the road # These are also places we diverge... but we will likely comply down the road
Style/IfUnlessModifier: Style/IfUnlessModifier: