mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-08-06 13:50:49 +08:00
Updated to newer coding standard
This commit is contained in:
@ -22,6 +22,7 @@ end
|
|||||||
class ColourCommandLine
|
class ColourCommandLine
|
||||||
def initialize
|
def initialize
|
||||||
return unless RUBY_PLATFORM =~ /(win|w)32$/
|
return unless RUBY_PLATFORM =~ /(win|w)32$/
|
||||||
|
|
||||||
get_std_handle = Win32API.new('kernel32', 'GetStdHandle', ['L'], 'L')
|
get_std_handle = Win32API.new('kernel32', 'GetStdHandle', ['L'], 'L')
|
||||||
@set_console_txt_attrb =
|
@set_console_txt_attrb =
|
||||||
Win32API.new('kernel32', 'SetConsoleTextAttribute', %w[L N], 'I')
|
Win32API.new('kernel32', 'SetConsoleTextAttribute', %w[L N], 'I')
|
||||||
|
@ -264,6 +264,7 @@ if $0 == __FILE__
|
|||||||
when /^-y\"?(.+)\"?/ then options = UnityModuleGenerator.grab_config(Regexp.last_match(1))
|
when /^-y\"?(.+)\"?/ then options = UnityModuleGenerator.grab_config(Regexp.last_match(1))
|
||||||
when /^(\w+)/
|
when /^(\w+)/
|
||||||
raise "ERROR: You can't have more than one Module name specified!" unless module_name.nil?
|
raise "ERROR: You can't have more than one Module name specified!" unless module_name.nil?
|
||||||
|
|
||||||
module_name = arg
|
module_name = arg
|
||||||
when /^-(h|-help)/
|
when /^-(h|-help)/
|
||||||
ARGV = [].freeze
|
ARGV = [].freeze
|
||||||
@ -298,6 +299,7 @@ if $0 == __FILE__
|
|||||||
end
|
end
|
||||||
|
|
||||||
raise 'ERROR: You must have a Module name specified! (use option -h for help)' if module_name.nil?
|
raise 'ERROR: You must have a Module name specified! (use option -h for help)' if module_name.nil?
|
||||||
|
|
||||||
if destroy
|
if destroy
|
||||||
UnityModuleGenerator.new(options).destroy(module_name)
|
UnityModuleGenerator.new(options).destroy(module_name)
|
||||||
else
|
else
|
||||||
|
@ -127,17 +127,21 @@ class UnityTestRunnerGenerator
|
|||||||
lines.each_with_index do |line, _index|
|
lines.each_with_index do |line, _index|
|
||||||
# find tests
|
# find tests
|
||||||
next unless line =~ /^((?:\s*TEST_CASE\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]}).*)\s*\(\s*(.*)\s*\)/m
|
next unless line =~ /^((?:\s*TEST_CASE\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]}).*)\s*\(\s*(.*)\s*\)/m
|
||||||
|
|
||||||
arguments = Regexp.last_match(1)
|
arguments = Regexp.last_match(1)
|
||||||
name = Regexp.last_match(2)
|
name = Regexp.last_match(2)
|
||||||
call = Regexp.last_match(3)
|
call = Regexp.last_match(3)
|
||||||
params = Regexp.last_match(4)
|
params = Regexp.last_match(4)
|
||||||
args = nil
|
args = nil
|
||||||
|
|
||||||
if @options[:use_param_tests] && !arguments.empty?
|
if @options[:use_param_tests] && !arguments.empty?
|
||||||
args = []
|
args = []
|
||||||
arguments.scan(/\s*TEST_CASE\s*\((.*)\)\s*$/) { |a| args << a[0] }
|
arguments.scan(/\s*TEST_CASE\s*\((.*)\)\s*$/) { |a| args << a[0] }
|
||||||
end
|
end
|
||||||
|
|
||||||
tests_and_line_numbers << { test: name, args: args, call: call, params: params, line_number: 0 }
|
tests_and_line_numbers << { test: name, args: args, call: call, params: params, line_number: 0 }
|
||||||
end
|
end
|
||||||
|
|
||||||
tests_and_line_numbers.uniq! { |v| v[:test] }
|
tests_and_line_numbers.uniq! { |v| v[:test] }
|
||||||
|
|
||||||
# determine line numbers and create tests to run
|
# determine line numbers and create tests to run
|
||||||
@ -146,6 +150,7 @@ class UnityTestRunnerGenerator
|
|||||||
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..-1].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
|
||||||
tests_and_line_numbers[i][:line_number] = source_index + 1
|
tests_and_line_numbers[i][:line_number] = source_index + 1
|
||||||
break
|
break
|
||||||
@ -266,18 +271,21 @@ class UnityTestRunnerGenerator
|
|||||||
|
|
||||||
def create_setup(output)
|
def create_setup(output)
|
||||||
return if @options[:has_setup]
|
return if @options[:has_setup]
|
||||||
|
|
||||||
output.puts("\n/*=======Setup (stub)=====*/")
|
output.puts("\n/*=======Setup (stub)=====*/")
|
||||||
output.puts("void #{@options[:setup_name]}(void) {}")
|
output.puts("void #{@options[:setup_name]}(void) {}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_teardown(output)
|
def create_teardown(output)
|
||||||
return if @options[:has_teardown]
|
return if @options[:has_teardown]
|
||||||
|
|
||||||
output.puts("\n/*=======Teardown (stub)=====*/")
|
output.puts("\n/*=======Teardown (stub)=====*/")
|
||||||
output.puts("void #{@options[:teardown_name]}(void) {}")
|
output.puts("void #{@options[:teardown_name]}(void) {}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_suite_setup(output)
|
def create_suite_setup(output)
|
||||||
return if @options[:suite_setup].nil?
|
return if @options[:suite_setup].nil?
|
||||||
|
|
||||||
output.puts("\n/*=======Suite Setup=====*/")
|
output.puts("\n/*=======Suite Setup=====*/")
|
||||||
output.puts('void suiteSetUp(void)')
|
output.puts('void suiteSetUp(void)')
|
||||||
output.puts('{')
|
output.puts('{')
|
||||||
@ -287,6 +295,7 @@ class UnityTestRunnerGenerator
|
|||||||
|
|
||||||
def create_suite_teardown(output)
|
def create_suite_teardown(output)
|
||||||
return if @options[:suite_teardown].nil?
|
return if @options[:suite_teardown].nil?
|
||||||
|
|
||||||
output.puts("\n/*=======Suite Teardown=====*/")
|
output.puts("\n/*=======Suite Teardown=====*/")
|
||||||
output.puts('int suiteTearDown(int num_failures)')
|
output.puts('int suiteTearDown(int num_failures)')
|
||||||
output.puts('{')
|
output.puts('{')
|
||||||
@ -315,9 +324,11 @@ class UnityTestRunnerGenerator
|
|||||||
|
|
||||||
def create_args_wrappers(output, tests)
|
def create_args_wrappers(output, tests)
|
||||||
return unless @options[:use_param_tests]
|
return unless @options[:use_param_tests]
|
||||||
|
|
||||||
output.puts("\n/*=======Parameterized Test Wrappers=====*/")
|
output.puts("\n/*=======Parameterized Test Wrappers=====*/")
|
||||||
tests.each do |test|
|
tests.each do |test|
|
||||||
next if test[:args].nil? || test[:args].empty?
|
next if test[:args].nil? || test[:args].empty?
|
||||||
|
|
||||||
test[:args].each.with_index(1) do |args, idx|
|
test[:args].each.with_index(1) do |args, idx|
|
||||||
output.puts("static void runner_args#{idx}_#{test[:test]}(void)")
|
output.puts("static void runner_args#{idx}_#{test[:test]}(void)")
|
||||||
output.puts('{')
|
output.puts('{')
|
||||||
|
@ -152,6 +152,7 @@ class UnityToJUnit
|
|||||||
|
|
||||||
def parse_test_summary(summary)
|
def parse_test_summary(summary)
|
||||||
raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ }
|
raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ }
|
||||||
|
|
||||||
[Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i]
|
[Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -230,7 +231,9 @@ if $0 == __FILE__
|
|||||||
targets = "#{options.results_dir.tr('\\', '/')}**/*.test*"
|
targets = "#{options.results_dir.tr('\\', '/')}**/*.test*"
|
||||||
|
|
||||||
results = Dir[targets]
|
results = Dir[targets]
|
||||||
|
|
||||||
raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty?
|
raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty?
|
||||||
|
|
||||||
utj.targets = results
|
utj.targets = results
|
||||||
|
|
||||||
# set the root path
|
# set the root path
|
||||||
|
@ -99,6 +99,7 @@ class UnityTestSummary
|
|||||||
|
|
||||||
def parse_test_summary(summary)
|
def parse_test_summary(summary)
|
||||||
raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ }
|
raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ }
|
||||||
|
|
||||||
[Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i]
|
[Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -117,7 +118,9 @@ if $0 == __FILE__
|
|||||||
args[0] ||= './'
|
args[0] ||= './'
|
||||||
targets = "#{ARGV[0].tr('\\', '/')}**/*.test*"
|
targets = "#{ARGV[0].tr('\\', '/')}**/*.test*"
|
||||||
results = Dir[targets]
|
results = Dir[targets]
|
||||||
|
|
||||||
raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty?
|
raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty?
|
||||||
|
|
||||||
uts.targets = results
|
uts.targets = results
|
||||||
|
|
||||||
# set the root path
|
# set the root path
|
||||||
|
@ -13,8 +13,6 @@ end
|
|||||||
|
|
||||||
task prepare_for_tests: TEMP_DIRS
|
task prepare_for_tests: TEMP_DIRS
|
||||||
|
|
||||||
include RakefileHelpers
|
|
||||||
|
|
||||||
# Load default configuration, for now
|
# Load default configuration, for now
|
||||||
DEFAULT_CONFIG_FILE = 'target_gcc_32.yml'.freeze
|
DEFAULT_CONFIG_FILE = 'target_gcc_32.yml'.freeze
|
||||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||||
|
@ -4,7 +4,6 @@ require_relative '../../auto/unity_test_summary'
|
|||||||
require_relative '../../auto/generate_test_runner'
|
require_relative '../../auto/generate_test_runner'
|
||||||
require_relative '../../auto/colour_reporter'
|
require_relative '../../auto/colour_reporter'
|
||||||
|
|
||||||
module RakefileHelpers
|
|
||||||
C_EXTENSION = '.c'.freeze
|
C_EXTENSION = '.c'.freeze
|
||||||
|
|
||||||
def load_configuration(config_file)
|
def load_configuration(config_file)
|
||||||
@ -118,6 +117,7 @@ module RakefileHelpers
|
|||||||
|
|
||||||
def build_simulator_fields
|
def build_simulator_fields
|
||||||
return nil if $cfg['simulator'].nil?
|
return nil if $cfg['simulator'].nil?
|
||||||
|
|
||||||
command = if $cfg['simulator']['path'].nil?
|
command = if $cfg['simulator']['path'].nil?
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
@ -141,9 +141,11 @@ module RakefileHelpers
|
|||||||
report command_string
|
report command_string
|
||||||
output = `#{command_string}`.chomp
|
output = `#{command_string}`.chomp
|
||||||
report(output) if verbose && !output.nil? && !output.empty?
|
report(output) if verbose && !output.nil? && !output.empty?
|
||||||
|
|
||||||
if !$?.nil? && !$?.exitstatus.zero? && raise_on_fail
|
if !$?.nil? && !$?.exitstatus.zero? && raise_on_fail
|
||||||
raise "Command failed. (Returned #{$?.exitstatus})"
|
raise "Command failed. (Returned #{$?.exitstatus})"
|
||||||
end
|
end
|
||||||
|
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -246,4 +248,3 @@ module RakefileHelpers
|
|||||||
# exit(-1) # Only removed to pass example_3, which has failing tests on purpose.
|
# exit(-1) # Only removed to pass example_3, which has failing tests on purpose.
|
||||||
# Still fail if the build fails for any other reason.
|
# Still fail if the build fails for any other reason.
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
@ -20,8 +20,6 @@ end
|
|||||||
|
|
||||||
task prepare_for_tests: TEMP_DIRS
|
task prepare_for_tests: TEMP_DIRS
|
||||||
|
|
||||||
include RakefileHelpers
|
|
||||||
|
|
||||||
# Load default configuration, for now
|
# Load default configuration, for now
|
||||||
DEFAULT_CONFIG_FILE = 'gcc_auto_stdint.yml'.freeze
|
DEFAULT_CONFIG_FILE = 'gcc_auto_stdint.yml'.freeze
|
||||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||||
|
@ -10,7 +10,6 @@ require_relative '../../auto/unity_test_summary'
|
|||||||
require_relative '../../auto/generate_test_runner'
|
require_relative '../../auto/generate_test_runner'
|
||||||
require_relative '../../auto/colour_reporter'
|
require_relative '../../auto/colour_reporter'
|
||||||
|
|
||||||
module RakefileHelpers
|
|
||||||
C_EXTENSION = '.c'.freeze
|
C_EXTENSION = '.c'.freeze
|
||||||
|
|
||||||
def load_configuration(config_file)
|
def load_configuration(config_file)
|
||||||
@ -100,6 +99,7 @@ module RakefileHelpers
|
|||||||
|
|
||||||
def build_simulator_fields
|
def build_simulator_fields
|
||||||
return nil if $cfg['simulator'].nil?
|
return nil if $cfg['simulator'].nil?
|
||||||
|
|
||||||
command = if $cfg['simulator']['path'].nil?
|
command = if $cfg['simulator']['path'].nil?
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
@ -122,7 +122,9 @@ module RakefileHelpers
|
|||||||
report command_string
|
report command_string
|
||||||
output = `#{command_string}`.chomp
|
output = `#{command_string}`.chomp
|
||||||
report(output) if verbose && !output.nil? && !output.empty?
|
report(output) if verbose && !output.nil? && !output.empty?
|
||||||
|
|
||||||
raise "Command failed. (Returned #{$?.exitstatus})" if $?.exitstatus != 0
|
raise "Command failed. (Returned #{$?.exitstatus})" if $?.exitstatus != 0
|
||||||
|
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -175,4 +177,3 @@ module RakefileHelpers
|
|||||||
end
|
end
|
||||||
File.open(test_results, 'w') { |f| f.print output }
|
File.open(test_results, 'w') { |f| f.print output }
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#inherit_from: .rubocop_todo.yml
|
#inherit_from: .rubocop_todo.yml
|
||||||
|
|
||||||
AllCops:
|
AllCops:
|
||||||
TargetRubyVersion: 2.1
|
TargetRubyVersion: 2.3
|
||||||
|
|
||||||
# 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:
|
||||||
@ -12,10 +12,20 @@ Style/FormatString:
|
|||||||
Enabled: false
|
Enabled: false
|
||||||
Style/GlobalVars:
|
Style/GlobalVars:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
Style/FrozenStringLiteralComment:
|
||||||
|
Enabled: false
|
||||||
Style/RegexpLiteral:
|
Style/RegexpLiteral:
|
||||||
AllowInnerSlashes: true
|
AllowInnerSlashes: true
|
||||||
Style/HashSyntax:
|
Style/HashSyntax:
|
||||||
EnforcedStyle: no_mixed_keys
|
EnforcedStyle: no_mixed_keys
|
||||||
|
Style/NumericPredicate:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
# These are also places we diverge... but we will likely comply down the road
|
||||||
|
Style/IfUnlessModifier:
|
||||||
|
Enabled: false
|
||||||
|
Style/FormatStringToken:
|
||||||
|
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/AlignHash:
|
||||||
|
Reference in New Issue
Block a user