Skip to content

Commit

Permalink
Catch up on Ruby style and formatting changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandervoord committed Nov 13, 2023
1 parent bd32847 commit 3f7564e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 42 deletions.
23 changes: 12 additions & 11 deletions auto/generate_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
}
Expand All @@ -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)/ }
Expand All @@ -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
Expand Down Expand Up @@ -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|
Expand All @@ -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|
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
38 changes: 19 additions & 19 deletions auto/parse_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -75,28 +75,28 @@ 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 = '<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)
# Push back the closing tag
@array_list.push '</testsuite>'
end

# 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 ' <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

# 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 ' <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 " <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 ' </testcase>'
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 ' <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 " <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 ' </testcase>'
end

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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('
Expand All @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion auto/stylize_as_junit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions auto/unity_test_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions examples/example_3/rakefile_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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?
''
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions test/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3f7564e

Please sign in to comment.