mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-10-20 21:59:59 +08:00
Bump rubocop up to newer ruby versions (in progress)
This commit is contained in:
@@ -12,7 +12,7 @@ def report(message)
|
|||||||
if !$colour_output
|
if !$colour_output
|
||||||
$stdout.puts(message)
|
$stdout.puts(message)
|
||||||
else
|
else
|
||||||
message = message.join('\n') if message.class == Array
|
message = message.join('\n') if message.instance_of?(Array)
|
||||||
message.each_line do |line|
|
message.each_line do |line|
|
||||||
line.chomp!
|
line.chomp!
|
||||||
colour = case line
|
colour = case line
|
||||||
|
@@ -133,7 +133,7 @@ class UnityModuleGenerator
|
|||||||
|
|
||||||
# create triad definition
|
# create triad definition
|
||||||
prefix = @options[:test_prefix] || 'Test'
|
prefix = @options[:test_prefix] || 'Test'
|
||||||
triad = [{ ext: '.c', path: @options[:path_src], prefix: '', template: TEMPLATE_SRC, inc: :src, boilerplate: @options[:boilerplates][:src] },
|
triad = [{ ext: '.c', path: @options[:path_src], prefix: '', template: TEMPLATE_SRC, inc: :src, boilerplate: @options[:boilerplates][:src] },
|
||||||
{ ext: '.h', path: @options[:path_inc], prefix: '', template: TEMPLATE_INC, inc: :inc, boilerplate: @options[:boilerplates][:inc] },
|
{ ext: '.h', path: @options[:path_inc], prefix: '', template: TEMPLATE_INC, inc: :inc, boilerplate: @options[:boilerplates][:inc] },
|
||||||
{ ext: '.c', path: @options[:path_tst], prefix: prefix, template: TEMPLATE_TST, inc: :tst, boilerplate: @options[:boilerplates][:tst], test_define: @options[:test_define] }]
|
{ ext: '.c', path: @options[:path_tst], prefix: prefix, template: TEMPLATE_TST, inc: :tst, boilerplate: @options[:boilerplates][:tst], test_define: @options[:test_define] }]
|
||||||
|
|
||||||
|
@@ -144,8 +144,8 @@ 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)/)
|
type_and_args = arguments.split(/TEST_(CASE|RANGE)/)
|
||||||
for i in (1...type_and_args.length).step(2)
|
(1...type_and_args.length).step(2).each do |i|
|
||||||
if type_and_args[i] == "CASE"
|
if type_and_args[i] == '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')
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
@@ -194,12 +194,11 @@ class UnityTestRunnerGenerator
|
|||||||
source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain)
|
source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain)
|
||||||
|
|
||||||
# parse out includes
|
# parse out includes
|
||||||
includes = {
|
{
|
||||||
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_FILE\(\s*\"\s*(.+\.#{@options[:source_extensions]})\s*\"/).flatten
|
linkonly: source.scan(/^TEST_FILE\(\s*"\s*(.+\.#{@options[:source_extensions]})\s*"/).flatten
|
||||||
}
|
}
|
||||||
includes
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_mocks(includes)
|
def find_mocks(includes)
|
||||||
@@ -446,7 +445,7 @@ class UnityTestRunnerGenerator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_h_file(output, filename, tests, testfile_includes, used_mocks)
|
def create_h_file(output, filename, tests, testfile_includes, used_mocks)
|
||||||
filename = File.basename(filename).gsub(/[-\/\\\.\,\s]/, '_').upcase
|
filename = File.basename(filename).gsub(/[-\/\\.,\s]/, '_').upcase
|
||||||
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
|
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
|
||||||
output.puts("#ifndef _#{filename}")
|
output.puts("#ifndef _#{filename}")
|
||||||
output.puts("#define _#{filename}\n\n")
|
output.puts("#define _#{filename}\n\n")
|
||||||
@@ -485,7 +484,7 @@ if $0 == __FILE__
|
|||||||
when /\.*\.ya?ml$/
|
when /\.*\.ya?ml$/
|
||||||
options = UnityTestRunnerGenerator.grab_config(arg)
|
options = UnityTestRunnerGenerator.grab_config(arg)
|
||||||
true
|
true
|
||||||
when /--(\w+)=\"?(.*)\"?/
|
when /--(\w+)="?(.*)"?/
|
||||||
options[Regexp.last_match(1).to_sym] = Regexp.last_match(2)
|
options[Regexp.last_match(1).to_sym] = Regexp.last_match(2)
|
||||||
true
|
true
|
||||||
when /\.*\.(?:hpp|hh|H|h)$/
|
when /\.*\.(?:hpp|hh|H|h)$/
|
||||||
|
@@ -15,6 +15,7 @@ module RakefileHelpers
|
|||||||
|
|
||||||
file = 'test_file_filter.yml'
|
file = 'test_file_filter.yml'
|
||||||
return unless File.exist?(file)
|
return unless File.exist?(file)
|
||||||
|
|
||||||
filters = YamlHelper.load_file(file)
|
filters = YamlHelper.load_file(file)
|
||||||
@all_files = filters[:all_files]
|
@all_files = filters[:all_files]
|
||||||
@only_files = filters[:only_files]
|
@only_files = filters[:only_files]
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
module TypeSanitizer
|
module TypeSanitizer
|
||||||
def self.sanitize_c_identifier(unsanitized)
|
def self.sanitize_c_identifier(unsanitized)
|
||||||
# convert filename to valid C identifier by replacing invalid chars with '_'
|
# convert filename to valid C identifier by replacing invalid chars with '_'
|
||||||
unsanitized.gsub(/[-\/\\\.\,\s]/, '_')
|
unsanitized.gsub(/[-\/\\.,\s]/, '_')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -86,8 +86,9 @@ class UnityTestSummary
|
|||||||
def get_details(_result_file, lines)
|
def get_details(_result_file, lines)
|
||||||
results = { failures: [], ignores: [], successes: [] }
|
results = { failures: [], ignores: [], successes: [] }
|
||||||
lines.each do |line|
|
lines.each do |line|
|
||||||
status_match = line.match(/^[^:]+:[^:]+:\w+(?:\([^\)]*\))?:([^:]+):?/)
|
status_match = line.match(/^[^:]+:[^:]+:\w+(?:\([^)]*\))?:([^:]+):?/)
|
||||||
next unless status_match
|
next unless status_match
|
||||||
|
|
||||||
status = status_match.captures[0]
|
status = status_match.captures[0]
|
||||||
|
|
||||||
line_out = (@root && (@root != 0) ? "#{@root}#{line}" : line).gsub(/\//, '\\')
|
line_out = (@root && (@root != 0) ? "#{@root}#{line}" : line).gsub(/\//, '\\')
|
||||||
|
@@ -8,8 +8,11 @@ require 'yaml'
|
|||||||
|
|
||||||
module YamlHelper
|
module YamlHelper
|
||||||
def self.load(body)
|
def self.load(body)
|
||||||
YAML.respond_to?(:unsafe_load) ?
|
if YAML.respond_to?(:unsafe_load)
|
||||||
YAML.unsafe_load(body) : YAML.load(body)
|
YAML.unsafe_load(body)
|
||||||
|
else
|
||||||
|
YAML.load(body)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.load_file(file)
|
def self.load_file(file)
|
||||||
|
@@ -42,7 +42,7 @@ def extract_headers(filename)
|
|||||||
includes = []
|
includes = []
|
||||||
lines = File.readlines(filename)
|
lines = File.readlines(filename)
|
||||||
lines.each do |line|
|
lines.each do |line|
|
||||||
m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/)
|
m = line.match(/^\s*#include\s+"\s*(.+\.[hH])\s*"/)
|
||||||
includes << m[1] unless m.nil?
|
includes << m[1] unless m.nil?
|
||||||
end
|
end
|
||||||
includes
|
includes
|
||||||
@@ -57,12 +57,11 @@ def find_source_file(header, paths)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tackit(strings)
|
def tackit(strings)
|
||||||
result = if strings.is_a?(Array)
|
if strings.is_a?(Array)
|
||||||
"\"#{strings.join}\""
|
"\"#{strings.join}\""
|
||||||
else
|
else
|
||||||
strings
|
strings
|
||||||
end
|
end
|
||||||
result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def squash(prefix, items)
|
def squash(prefix, items)
|
||||||
@@ -80,7 +79,7 @@ def build_compiler_fields
|
|||||||
end
|
end
|
||||||
options = squash('', $cfg['compiler']['options'])
|
options = squash('', $cfg['compiler']['options'])
|
||||||
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
|
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
|
||||||
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
includes = includes.gsub(/\\ /, ' ').gsub(/\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
||||||
|
|
||||||
{ command: command, defines: defines, options: options, includes: includes }
|
{ command: command, defines: defines, options: options, includes: includes }
|
||||||
end
|
end
|
||||||
@@ -105,7 +104,7 @@ def build_linker_fields
|
|||||||
''
|
''
|
||||||
else
|
else
|
||||||
squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
|
squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
|
||||||
end.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
end.gsub(/\\ /, ' ').gsub(/\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
||||||
|
|
||||||
{ command: command, options: options, includes: includes }
|
{ command: command, options: options, includes: includes }
|
||||||
end
|
end
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
#inherit_from: .rubocop_todo.yml
|
#inherit_from: .rubocop_todo.yml
|
||||||
|
|
||||||
AllCops:
|
AllCops:
|
||||||
TargetRubyVersion: 2.3
|
TargetRubyVersion: 3.0
|
||||||
|
|
||||||
# These are areas where ThrowTheSwitch's coding style diverges from the Ruby standard
|
# These are areas where ThrowTheSwitch's coding style diverges from the Ruby standard
|
||||||
Style/SpecialGlobalVars:
|
Style/SpecialGlobalVars:
|
||||||
@@ -36,10 +36,12 @@ Style/FormatStringToken:
|
|||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
# This is disabled because it seems to get confused over nested hashes
|
# This is disabled because it seems to get confused over nested hashes
|
||||||
Layout/AlignHash:
|
Layout/HashAlignment:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
EnforcedHashRocketStyle: table
|
EnforcedHashRocketStyle: table
|
||||||
EnforcedColonStyle: table
|
EnforcedColonStyle: table
|
||||||
|
Layout/LineLength:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
# We purposefully use these insecure features because they're what makes Ruby awesome
|
# We purposefully use these insecure features because they're what makes Ruby awesome
|
||||||
Security/Eval:
|
Security/Eval:
|
||||||
@@ -64,8 +66,6 @@ Metrics/ClassLength:
|
|||||||
Enabled: false
|
Enabled: false
|
||||||
Metrics/CyclomaticComplexity:
|
Metrics/CyclomaticComplexity:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
Metrics/LineLength:
|
|
||||||
Enabled: false
|
|
||||||
Metrics/MethodLength:
|
Metrics/MethodLength:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
Metrics/ModuleLength:
|
Metrics/ModuleLength:
|
||||||
|
Reference in New Issue
Block a user