Skip to content

Commit 3f7564e

Browse files
committed
Catch up on Ruby style and formatting changes.
1 parent bd32847 commit 3f7564e

File tree

6 files changed

+45
-42
lines changed

6 files changed

+45
-42
lines changed

auto/generate_test_runner.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def self.default_options
4545
cmdline_args: false,
4646
omit_begin_end: false,
4747
use_param_tests: false,
48+
use_system_files: true,
4849
include_extensions: '(?:hpp|hh|H|h)',
4950
source_extensions: '(?:cpp|cc|ino|C|c)'
5051
}
@@ -69,7 +70,7 @@ def run(input_file, output_file, options = nil)
6970
source = source.force_encoding('ISO-8859-1').encode('utf-8', replace: nil)
7071
tests = find_tests(source)
7172
headers = find_includes(source)
72-
testfile_includes = (headers[:local] + headers[:system])
73+
testfile_includes = @options[:use_system_files] ? (headers[:local] + headers[:system]) : (headers[:local])
7374
used_mocks = find_mocks(testfile_includes)
7475
testfile_includes = (testfile_includes - used_mocks)
7576
testfile_includes.delete_if { |inc| inc =~ /(unity|cmock)/ }
@@ -80,7 +81,7 @@ def run(input_file, output_file, options = nil)
8081

8182
# determine which files were used to return them
8283
all_files_used = [input_file, output_file]
83-
all_files_used += testfile_includes.map { |filename| filename + '.c' } unless testfile_includes.empty?
84+
all_files_used += testfile_includes.map { |filename| "#{filename}.c" } unless testfile_includes.empty?
8485
all_files_used += @options[:includes] unless @options[:includes].empty?
8586
all_files_used += headers[:linkonly] unless headers[:linkonly].empty?
8687
all_files_used.uniq
@@ -144,12 +145,12 @@ def find_tests(source)
144145
if @options[:use_param_tests] && !arguments.empty?
145146
args = []
146147
type_and_args = arguments.split(/TEST_(CASE|RANGE|MATRIX)/)
147-
for i in (1...type_and_args.length).step(2)
148+
(1...type_and_args.length).step(2).each do |i|
148149
case type_and_args[i]
149-
when "CASE"
150+
when 'CASE'
150151
args << type_and_args[i + 1].sub(/^\s*\(\s*(.*?)\s*\)\s*$/m, '\1')
151152

152-
when "RANGE"
153+
when 'RANGE'
153154
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|
154155
exclude_end = arg_values_str[0] == '<' && arg_values_str[-1] == '>'
155156
arg_values_str[1...-1].map do |arg_value_str|
@@ -163,13 +164,13 @@ def find_tests(source)
163164
arg_combinations.flatten.join(', ')
164165
end
165166

166-
when "MATRIX"
167-
single_arg_regex_string = /(?:(?:"(?:\\"|[^\\])*?")+|(?:'\\?.')+|(?:[^\s\]\["'\,]|\[[\d\S_-]+\])+)/.source
167+
when 'MATRIX'
168+
single_arg_regex_string = /(?:(?:"(?:\\"|[^\\])*?")+|(?:'\\?.')+|(?:[^\s\]\["',]|\[[\d\S_-]+\])+)/.source
168169
args_regex = /\[((?:\s*#{single_arg_regex_string}\s*,?)*(?:\s*#{single_arg_regex_string})?\s*)\]/m
169170
arg_elements_regex = /\s*(#{single_arg_regex_string})\s*,\s*/m
170171

171172
args += type_and_args[i + 1].scan(args_regex).flatten.map do |arg_values_str|
172-
(arg_values_str + ',').scan(arg_elements_regex)
173+
("#{arg_values_str},").scan(arg_elements_regex)
173174
end.reduce do |result, arg_range_expanded|
174175
result.product(arg_range_expanded)
175176
end.map do |arg_combinations|
@@ -188,7 +189,7 @@ def find_tests(source)
188189
source_lines = source.split("\n")
189190
source_index = 0
190191
tests_and_line_numbers.size.times do |i|
191-
source_lines[source_index..-1].each_with_index do |line, index|
192+
source_lines[source_index..].each_with_index do |line, index|
192193
next unless line =~ /\s+#{tests_and_line_numbers[i][:test]}(?:\s|\()/
193194

194195
source_index += index
@@ -210,7 +211,7 @@ def find_includes(source)
210211
{
211212
local: source.scan(/^\s*#include\s+"\s*(.+\.#{@options[:include_extensions]})\s*"/).flatten,
212213
system: source.scan(/^\s*#include\s+<\s*(.+)\s*>/).flatten.map { |inc| "<#{inc}>" },
213-
linkonly: source.scan(/^TEST_SOURCE_FILE\(\s*\"\s*(.+\.#{@options[:source_extensions]})\s*\"/).flatten
214+
linkonly: source.scan(/^TEST_SOURCE_FILE\(\s*"\s*(.+\.#{@options[:source_extensions]})\s*"/).flatten
214215
}
215216
end
216217

@@ -368,7 +369,7 @@ def create_run_test(output)
368369
require 'erb'
369370
file = File.read(File.join(__dir__, 'run_test.erb'))
370371
template = ERB.new(file, trim_mode: '<>')
371-
output.puts("\n" + template.result(binding))
372+
output.puts("\n#{template.result(binding)}")
372373
end
373374

374375
def create_args_wrappers(output, tests)

auto/parse_output.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def set_xml_output
5656
# Set the flag to indicate if there will be an XML output file or not
5757
def test_suite_name=(cli_arg)
5858
@real_test_suite_name = cli_arg
59-
puts 'Real test suite name will be \'' + @real_test_suite_name + '\''
59+
puts "Real test suite name will be '#{@real_test_suite_name}'"
6060
end
6161

6262
def xml_encode_s(str)
@@ -75,28 +75,28 @@ def write_xml_output
7575
# Pushes the suite info as xml to the array list, which will be written later
7676
def push_xml_output_suite_info
7777
# Insert opening tag at front
78-
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 + '">'
78+
heading = "<testsuite name=#{xml_encode_s(@real_test_suite_name)} tests=\"#{@total_tests}\" failures=\"#{@test_failed}\" skips=\"#{@test_ignored}\">"
7979
@array_list.insert(0, heading)
8080
# Push back the closing tag
8181
@array_list.push '</testsuite>'
8282
end
8383

8484
# Pushes xml output data to the array list, which will be written later
8585
def push_xml_output_passed(test_name, execution_time = 0)
86-
@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) + ' />'
86+
@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)} />"
8787
end
8888

8989
# Pushes xml output data to the array list, which will be written later
9090
def push_xml_output_failed(test_name, reason, execution_time = 0)
91-
@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) + '>'
92-
@array_list.push ' <failure type="ASSERT FAILED">' + reason + '</failure>'
91+
@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)} >"
92+
@array_list.push " <failure type=\"ASSERT FAILED\">#{reason}</failure>"
9393
@array_list.push ' </testcase>'
9494
end
9595

9696
# Pushes xml output data to the array list, which will be written later
9797
def push_xml_output_ignored(test_name, reason, execution_time = 0)
98-
@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) + '>'
99-
@array_list.push ' <skipped type="TEST IGNORED">' + reason + '</skipped>'
98+
@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)} >"
99+
@array_list.push " <skipped type=\"TEST IGNORED\">#{reason}</skipped>"
100100
@array_list.push ' </testcase>'
101101
end
102102

@@ -144,7 +144,7 @@ def test_failed_unity_fixture(array)
144144
test_name = array[1]
145145
test_suite_verify(class_name)
146146
reason_array = array[2].split(':')
147-
reason = reason_array[-1].lstrip.chomp + ' at line: ' + reason_array[-4]
147+
reason = "#{reason_array[-1].lstrip.chomp} at line: #{reason_array[-4]}"
148148

149149
printf "%-40s FAILED\n", test_name
150150

@@ -189,12 +189,12 @@ def test_passed(array)
189189
def test_failed(array)
190190
# ':' symbol will be valid in function args now
191191
real_method_name = array[@result_usual_idx - 1..-3].join(':')
192-
array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..-1]
192+
array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..]
193193

194194
last_item = array.length - 1
195195
test_time = get_test_time(array[last_item])
196196
test_name = array[last_item - 2]
197-
reason = array[last_item].chomp.lstrip + ' at line: ' + array[last_item - 3]
197+
reason = "#{array[last_item].chomp.lstrip} at line: #{array[last_item - 3]}"
198198
class_name = array[@class_name_idx]
199199

200200
if test_name.start_with? 'TEST('
@@ -217,7 +217,7 @@ def test_failed(array)
217217
def test_ignored(array)
218218
# ':' symbol will be valid in function args now
219219
real_method_name = array[@result_usual_idx - 1..-3].join(':')
220-
array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..-1]
220+
array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..]
221221

222222
last_item = array.length - 1
223223
test_time = get_test_time(array[last_item])
@@ -268,7 +268,7 @@ def detect_os_specifics(line)
268268
def process(file_name)
269269
@array_list = []
270270

271-
puts 'Parsing file: ' + file_name
271+
puts "Parsing file: #{file_name}"
272272

273273
@test_passed = 0
274274
@test_failed = 0
@@ -333,17 +333,17 @@ def process(file_name)
333333
@test_ignored += 1
334334
elsif line_array.size >= 4
335335
# We will check output from color compilation
336-
if line_array[@result_usual_idx..-1].any? { |l| l.include? 'PASS' }
336+
if line_array[@result_usual_idx..].any? { |l| l.include? 'PASS' }
337337
test_passed(line_array)
338338
@test_passed += 1
339-
elsif line_array[@result_usual_idx..-1].any? { |l| l.include? 'FAIL' }
339+
elsif line_array[@result_usual_idx..].any? { |l| l.include? 'FAIL' }
340340
test_failed(line_array)
341341
@test_failed += 1
342342
elsif line_array[@result_usual_idx..-2].any? { |l| l.include? 'IGNORE' }
343343
test_ignored(line_array)
344344
@test_ignored += 1
345-
elsif line_array[@result_usual_idx..-1].any? { |l| l.include? 'IGNORE' }
346-
line_array.push('No reason given (' + get_test_time(line_array[@result_usual_idx..-1]).to_s + ' ms)')
345+
elsif line_array[@result_usual_idx..].any? { |l| l.include? 'IGNORE' }
346+
line_array.push("No reason given (#{get_test_time(line_array[@result_usual_idx..])} ms)")
347347
test_ignored(line_array)
348348
@test_ignored += 1
349349
end
@@ -353,9 +353,9 @@ def process(file_name)
353353
puts ''
354354
puts '=================== SUMMARY ====================='
355355
puts ''
356-
puts 'Tests Passed : ' + @test_passed.to_s
357-
puts 'Tests Failed : ' + @test_failed.to_s
358-
puts 'Tests Ignored : ' + @test_ignored.to_s
356+
puts "Tests Passed : #{@test_passed}"
357+
puts "Tests Failed : #{@test_failed}"
358+
puts "Tests Ignored : #{@test_ignored}"
359359

360360
return unless @xml_out
361361

auto/stylize_as_junit.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def run
9999
test_file = if test_file_str.length < 2
100100
result_file
101101
else
102-
test_file_str[0] + ':' + test_file_str[1]
102+
"#{test_file_str[0]}:#{test_file_str[1]}"
103103
end
104104
result_output[:source][:path] = File.dirname(test_file)
105105
result_output[:source][:file] = File.basename(test_file)

auto/unity_test_summary.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def parse_test_summary(summary)
112112

113113
# parse out the command options
114114
opts, args = ARGV.partition { |v| v =~ /^--\w+/ }
115-
opts.map! { |v| v[2..-1].to_sym }
115+
opts.map! { |v| v[2..].to_sym }
116116

117117
# create an instance to work with
118118
uts = UnityTestSummary.new(opts)
@@ -128,7 +128,7 @@ def parse_test_summary(summary)
128128
uts.targets = results
129129

130130
# set the root path
131-
args[1] ||= Dir.pwd + '/'
131+
args[1] ||= "#{Dir.pwd}/"
132132
uts.root = ARGV[1]
133133

134134
# run the summarizer

examples/example_3/rakefile_helper.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def load_configuration(config_file)
1717
end
1818

1919
def configure_clean
20-
CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil?
20+
CLEAN.include("#{$cfg['compiler']['build_path']}*.*") unless $cfg['compiler']['build_path'].nil?
2121
end
2222

2323
def configure_toolchain(config_file = DEFAULT_CONFIG_FILE)
@@ -27,7 +27,7 @@ def configure_toolchain(config_file = DEFAULT_CONFIG_FILE)
2727
end
2828

2929
def unit_test_files
30-
path = $cfg['compiler']['unit_tests_path'] + 'Test*' + C_EXTENSION
30+
path = "#{$cfg['compiler']['unit_tests_path']}Test*#{C_EXTENSION}"
3131
path.tr!('\\', '/')
3232
FileList.new(path)
3333
end
@@ -111,11 +111,11 @@ def build_linker_fields
111111

112112
def link_it(exe_name, obj_list)
113113
linker = build_linker_fields
114-
cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " +
115-
(obj_list.map { |obj| "#{$cfg['linker']['object_files']['path']}#{obj} " }).join +
116-
$cfg['linker']['bin_files']['prefix'] + ' ' +
117-
$cfg['linker']['bin_files']['destination'] +
118-
exe_name + $cfg['linker']['bin_files']['extension']
114+
cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]}"
115+
cmd_str += " #{(obj_list.map { |obj| "#{$cfg['linker']['object_files']['path']}#{obj}" }).join(' ')}"
116+
cmd_str += " #{$cfg['linker']['bin_files']['prefix']} "
117+
cmd_str += $cfg['linker']['bin_files']['destination']
118+
cmd_str += exe_name + $cfg['linker']['bin_files']['extension']
119119
execute(cmd_str)
120120
end
121121

@@ -125,7 +125,7 @@ def build_simulator_fields
125125
command = if $cfg['simulator']['path'].nil?
126126
''
127127
else
128-
(tackit($cfg['simulator']['path']) + ' ')
128+
"#{tackit($cfg['simulator']['path'])} "
129129
end
130130
pre_support = if $cfg['simulator']['pre_support'].nil?
131131
''
@@ -188,7 +188,7 @@ def run_tests(test_files)
188188

189189
# Build the test runner (generate if configured to do so)
190190
test_base = File.basename(test, C_EXTENSION)
191-
runner_name = test_base + '_Runner.c'
191+
runner_name = "#{test_base}_Runner.c"
192192
if $cfg['compiler']['runner_path'].nil?
193193
runner_path = $cfg['compiler']['build_path'] + runner_name
194194
test_gen = UnityTestRunnerGenerator.new($cfg_file)

test/.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Style/EvalWithLocation:
2828
Enabled: false
2929
Style/MixinUsage:
3030
Enabled: false
31+
Style/OptionalBooleanParameter:
32+
Enabled: false
3133

3234
# These are also places we diverge... but we will likely comply down the road
3335
Style/IfUnlessModifier:

0 commit comments

Comments
 (0)