mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-05-17 23:47:11 +08:00
Catch up on Ruby style and formatting changes.
This commit is contained in:
@ -45,6 +45,7 @@ class UnityTestRunnerGenerator
|
||||
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 @@ class UnityTestRunnerGenerator
|
||||
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 @@ class UnityTestRunnerGenerator
|
||||
|
||||
# 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 @@ class UnityTestRunnerGenerator
|
||||
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 @@ class UnityTestRunnerGenerator
|
||||
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 @@ class UnityTestRunnerGenerator
|
||||
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 @@ class UnityTestRunnerGenerator
|
||||
{
|
||||
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 @@ class UnityTestRunnerGenerator
|
||||
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)
|
||||
|
@ -56,7 +56,7 @@ class ParseOutput
|
||||
# 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 @@ class ParseOutput
|
||||
# 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>'
|
||||
@ -83,20 +83,20 @@ class ParseOutput
|
||||
|
||||
# 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
|
||||
|
||||
@ -144,7 +144,7 @@ class ParseOutput
|
||||
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 @@ class ParseOutput
|
||||
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 @@ class ParseOutput
|
||||
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 @@ class ParseOutput
|
||||
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 @@ class ParseOutput
|
||||
@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 @@ class ParseOutput
|
||||
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
|
||||
|
||||
|
@ -99,7 +99,7 @@ class UnityToJUnit
|
||||
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)
|
||||
|
@ -112,7 +112,7 @@ if $0 == __FILE__
|
||||
|
||||
# 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 @@ if $0 == __FILE__
|
||||
uts.targets = results
|
||||
|
||||
# set the root path
|
||||
args[1] ||= Dir.pwd + '/'
|
||||
args[1] ||= "#{Dir.pwd}/"
|
||||
uts.root = ARGV[1]
|
||||
|
||||
# run the summarizer
|
||||
|
@ -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 @@ end
|
||||
|
||||
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)
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user