1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-23 00:15:58 +01:00

Finished updating all Ruby scripts to match our coding standard. Woo!

This commit is contained in:
Mark VanderVoord
2017-03-28 20:02:53 -04:00
parent 3e0a7121fb
commit 2a5b24f7bf
15 changed files with 546 additions and 1007 deletions

View File

@@ -1,19 +1,21 @@
# This is the configuration used to check the rubocop source code.
inherit_from: .rubocop_todo.yml
#inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.1
# These are areas where ThrowTheSwitch's coding style diverges from the Ruby standard
# (Maybe we will make these conform over time)
Style/SpecialGlobalVars:
SupportedStyles:
- use_perl_names
- use_english_names
EnforcedStyle: use_perl_names
Style/FormatString:
Enabled: false
Style/GlobalVars:
Enabled: false
Style/RegexpLiteral:
AllowInnerSlashes: true
Style/HashSyntax:
EnforcedStyle: no_mixed_keys
# This is disabled because it seems to get confused over nested hashes
Style/AlignHash:
@@ -48,6 +50,8 @@ Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/ModuleLength:
Enabled: false
Metrics/ParameterLists:
Enabled: false
Metrics/PerceivedComplexity:

View File

@@ -1,443 +0,0 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-03-28 15:45:51 -0400 using RuboCop version 0.48.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
# Cop supports --auto-correct.
Lint/DeprecatedClassMethods:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect.
# SupportedStylesAlignWith: keyword, variable, start_of_line
Lint/EndAlignment:
Exclude:
- '../auto/colour_prompt.rb'
- '../auto/colour_reporter.rb'
- '../auto/parseOutput.rb'
- '../auto/stylize_as_junit.rb'
# Offense count: 2
Lint/RescueException:
Exclude:
- '../auto/stylize_as_junit.rb'
- '../auto/unity_test_summary.rb'
# Offense count: 1
Lint/ShadowingOuterLocalVariable:
Exclude:
- '../auto/stylize_as_junit.rb'
# Offense count: 3
# Cop supports --auto-correct.
Lint/StringConversionInInterpolation:
Exclude:
- 'tests/test_generate_test_runner.rb'
# Offense count: 13
Lint/UselessAssignment:
Exclude:
- '../auto/generate_test_runner.rb'
- '../auto/stylize_as_junit.rb'
- '../auto/unity_test_summary.rb'
- 'rakefile_helper.rb'
# Offense count: 5
Lint/Void:
Exclude:
- '../auto/parseOutput.rb'
# Offense count: 3
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 204
# Offense count: 2
# Cop supports --auto-correct.
Performance/StringReplacement:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 10
Style/AccessorMethodName:
Exclude:
- '../auto/stylize_as_junit.rb'
- '../auto/unity_test_summary.rb'
- '../examples/example_3/rakefile_helper.rb'
- 'rakefile_helper.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'spec/generate_module_existing_file_spec.rb'
# Offense count: 17
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment:
Exclude:
- '../examples/example_3/rakefile_helper.rb'
- '../extras/fixture/rakefile_helper.rb'
- 'rakefile_helper.rb'
# Offense count: 2
# Cop supports --auto-correct.
Style/ElseAlignment:
Exclude:
- '../auto/generate_test_runner.rb'
# Offense count: 3
# Cop supports --auto-correct.
Style/EmptyLines:
Exclude:
- 'tests/test_generate_test_runner.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, no_empty_lines
Style/EmptyLinesAroundBlockBody:
Exclude:
- 'rakefile_helper.rb'
- 'spec/generate_module_existing_file_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Style/EmptyLinesAroundModuleBody:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 14
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Style/ExtraSpacing:
Exclude:
- '../auto/generate_test_runner.rb'
- 'rakefile_helper.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Style/FileName:
Exclude:
- '../auto/parseOutput.rb'
# Offense count: 164
# Configuration parameters: AllowedVariables.
Style/GlobalVars:
Exclude:
- '../auto/colour_reporter.rb'
- '../examples/example_3/rakefile_helper.rb'
- '../extras/fixture/rakefile.rb'
- '../extras/fixture/rakefile_helper.rb'
- 'rakefile_helper.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 20
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- '../auto/colour_prompt.rb'
- '../auto/generate_test_runner.rb'
- '../auto/parseOutput.rb'
- '../auto/stylize_as_junit.rb'
- '../auto/test_file_filter.rb'
- '../auto/unity_test_summary.rb'
- '../extras/fixture/rakefile_helper.rb'
- 'rakefile_helper.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 630
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Exclude:
- 'rakefile_helper.rb'
- 'spec/generate_module_existing_file_spec.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IndentationWidth.
Style/IndentAssignment:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: Width, IgnoredPatterns.
Style/IndentationWidth:
Exclude:
- '../auto/generate_test_runner.rb'
- 'spec/generate_module_existing_file_spec.rb'
# Offense count: 17
# Cop supports --auto-correct.
Style/LeadingCommentSpace:
Exclude:
- 'rakefile_helper.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/LineEndConcatenation:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 8
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: snake_case, camelCase
Style/MethodName:
Exclude:
- '../auto/parseOutput.rb'
# Offense count: 40
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: symmetrical, new_line, same_line
Style/MultilineArrayBraceLayout:
Exclude:
- 'tests/test_generate_test_runner.rb'
# Offense count: 63
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: symmetrical, new_line, same_line
Style/MultilineHashBraceLayout:
Exclude:
- 'tests/test_generate_test_runner.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: aligned, indented
Style/MultilineOperationIndentation:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 3
# Cop supports --auto-correct.
Style/MutableConstant:
Exclude:
- 'rakefile_helper.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: both, prefix, postfix
Style/NegatedIf:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/Not:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- '../auto/colour_reporter.rb'
# Offense count: 17
# Cop supports --auto-correct.
# Configuration parameters: AllowSafeAssignment.
Style/ParenthesesAroundCondition:
Exclude:
- '../auto/generate_test_runner.rb'
- 'rakefile_helper.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 7
# Cop supports --auto-correct.
Style/RedundantParentheses:
Exclude:
- '../auto/generate_test_runner.rb'
- 'rakefile_helper.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Exclude:
- 'rakefile_helper.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- '../auto/generate_test_runner.rb'
- '../auto/stylize_as_junit.rb'
- '../auto/type_sanitizer.rb'
- '../auto/unity_test_summary.rb'
- '../extras/fixture/rakefile_helper.rb'
- 'rakefile_helper.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon:
Exclude:
- '../auto/generate_test_runner.rb'
# Offense count: 5
# Cop supports --auto-correct.
Style/SpaceAfterComma:
Exclude:
- 'tests/test_generate_test_runner.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleInsidePipes, SupportedStylesInsidePipes.
# SupportedStylesInsidePipes: space, no_space
Style/SpaceAroundBlockParameters:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Style/SpaceAroundEqualsInParameterDefault:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Style/SpaceAroundOperators:
Exclude:
- 'rakefile_helper.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Style/SpaceBeforeBlockBraces:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Style/SpaceInsideBlockBraces:
Exclude:
- 'rakefile_helper.rb'
- 'spec/generate_module_existing_file_spec.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 295
# Cop supports --auto-correct.
Style/SpaceInsideBrackets:
Exclude:
- 'tests/test_generate_test_runner.rb'
# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBraces: space, no_space
Style/SpaceInsideHashLiteralBraces:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 5
# Cop supports --auto-correct.
Style/SpaceInsideParens:
Exclude:
- 'tests/test_generate_test_runner.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: use_perl_names, use_english_names
Style/SpecialGlobalVars:
Exclude:
- '../auto/generate_test_runner.rb'
- '../auto/stylize_as_junit.rb'
- '../auto/unity_test_summary.rb'
# Offense count: 167
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'rakefile_helper.rb'
- 'spec/generate_module_existing_file_spec.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment.
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
Style/TernaryParentheses:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 152
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInLiteral:
Exclude:
- 'spec/generate_module_existing_file_spec.rb'
- 'tests/test_generate_test_runner.rb'
# Offense count: 39
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: snake_case, camelCase
Style/VariableName:
Exclude:
- '../auto/parseOutput.rb'
# Offense count: 69
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
EnforcedStyle: percent
MinSize: 12
# Offense count: 1
# Cop supports --auto-correct.
Style/ZeroLengthPredicate:
Exclude:
- 'rakefile_helper.rb'

View File

@@ -32,7 +32,7 @@ configure_toolchain(DEFAULT_CONFIG_FILE)
desc "Test unity with its own unit tests"
task :unit => [:prepare_for_tests] do
run_tests get_unit_test_files
run_tests unit_test_files
end
desc "Test unity's helper scripts"
@@ -74,32 +74,35 @@ end
namespace :style do
desc "Check style"
task :check do
report execute("rubocop ../ --config .rubocop.yml", true)
report "Style Checked."
report "\nVERIFYING RUBY STYLE"
report execute("rubocop ../auto ../examples ../extras --config .rubocop.yml", true)
report "Style PASSED."
end
namespace :check do
Dir['../**/*.rb'].each do |f|
task File.basename(f, '.rb').to_sym do
task File.basename(f, '.rb').to_sym => ['style:clean'] do
report execute("rubocop #{f} --color --config .rubocop.yml", true)
report "Style Checked."
report "Style Checked for #{f}"
end
end
end
desc "Attempt to Autocorrect style"
task :auto do
File.delete(".rubocop_todo.yml")
execute("rubocop ../ --auto-correct --config .rubocop.yml")
task :auto => ['style:clean'] do
execute("rubocop ../auto ../examples ../extras --auto-correct --config .rubocop.yml")
report "Autocorrected What We Could."
end
desc "Update style todo list"
task :todo do
File.delete(".rubocop_todo.yml")
execute("rubocop ../ --auto-gen-config --config .rubocop.yml")
task :todo => ['style:clean'] do
execute("rubocop ../auto ../examples ../extras --auto-gen-config --config .rubocop.yml")
report "Updated Style TODO List."
end
task :clean do
File.delete(".rubocop_todo.yml") if File.exists?(".rubocop_todo.yml")
end
end
task :style => ['style:check']

View File

@@ -11,39 +11,37 @@ require UNITY_ROOT + '../auto/generate_test_runner'
require UNITY_ROOT + '../auto/colour_reporter'
module RakefileHelpers
C_EXTENSION = '.c'
C_EXTENSION = '.c'.freeze
def load_configuration(config_file)
unless ($configured)
$cfg_file = "targets/#{config_file}" unless (config_file =~ /[\\|\/]/)
$cfg = YAML.load(File.read($cfg_file))
$colour_output = false unless $cfg['colour']
$configured = true if (config_file != DEFAULT_CONFIG_FILE)
end
return if $configured
$cfg_file = "targets/#{config_file}" unless config_file =~ /[\\|\/]/
$cfg = YAML.load(File.read($cfg_file))
$colour_output = false unless $cfg['colour']
$configured = true if config_file != DEFAULT_CONFIG_FILE
end
def configure_clean
CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil?
end
def configure_toolchain(config_file=DEFAULT_CONFIG_FILE)
def configure_toolchain(config_file = DEFAULT_CONFIG_FILE)
config_file += '.yml' unless config_file =~ /\.yml$/
config_file = config_file unless config_file =~ /[\\|\/]/
load_configuration(config_file)
configure_clean
end
def get_unit_test_files
def unit_test_files
path = $cfg['compiler']['unit_tests_path'] + 'test*' + C_EXTENSION
path.gsub!(/\\/, '/')
path.tr!('\\', '/')
FileList.new(path)
end
def get_local_include_dirs
def local_include_dirs
include_dirs = $cfg['compiler']['includes']['items'].dup
include_dirs.delete_if {|dir| dir.is_a?(Array)}
return include_dirs
include_dirs.delete_if { |dir| dir.is_a?(Array) }
include_dirs
end
def extract_headers(filename)
@@ -51,41 +49,37 @@ module RakefileHelpers
lines = File.readlines(filename)
lines.each do |line|
m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/)
if not m.nil?
includes << m[1]
end
includes << m[1] unless m.nil?
end
return includes
includes
end
def find_source_file(header, paths)
paths.each do |dir|
src_file = dir + header.ext(C_EXTENSION)
if (File.exists?(src_file))
return src_file
end
return src_file if File.exist?(src_file)
end
return nil
nil
end
def tackit(strings)
if strings.is_a?(Array)
result = "\"#{strings.join}\""
else
result = strings
end
return result
result = if strings.is_a?(Array)
"\"#{strings.join}\""
else
strings
end
result
end
def squash(prefix, items)
result = ''
items.each { |item| result += " #{prefix}#{tackit(item)}" }
return result
result
end
def should(behave, &block)
if block
puts "Should " + behave
puts 'Should ' + behave
yield block
else
puts "UNIMPLEMENTED CASE: Should #{behave}"
@@ -93,91 +87,91 @@ module RakefileHelpers
end
def build_compiler_fields(inject_defines)
command = tackit($cfg['compiler']['path'])
if $cfg['compiler']['defines']['items'].nil?
defines = ''
else
defines = squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=putcharSpy'] + inject_defines)
end
options = squash('', $cfg['compiler']['options'])
command = tackit($cfg['compiler']['path'])
defines = if $cfg['compiler']['defines']['items'].nil?
''
else
squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=putcharSpy'] + inject_defines)
end
options = squash('', $cfg['compiler']['options'])
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
return {:command => command, :defines => defines, :options => options, :includes => includes}
{ :command => command, :defines => defines, :options => options, :includes => includes }
end
def compile(file, defines=[])
def compile(file, defines = [])
compiler = build_compiler_fields(defines)
defines =
cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{compiler[:options]}#{compiler[:includes]} #{file} " +
cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{compiler[:options]}#{compiler[:includes]} #{file} " \
"#{$cfg['compiler']['object_files']['prefix']}#{$cfg['compiler']['object_files']['destination']}"
obj_file = "#{File.basename(file, C_EXTENSION)}#{$cfg['compiler']['object_files']['extension']}"
execute(cmd_str + obj_file)
return obj_file
obj_file
end
def build_linker_fields
command = tackit($cfg['linker']['path'])
if $cfg['linker']['options'].nil?
options = ''
else
options = squash('', $cfg['linker']['options'])
end
if ($cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil?)
includes = ''
else
includes = squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
end
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
return {:command => command, :options => options, :includes => includes}
command = tackit($cfg['linker']['path'])
options = if $cfg['linker']['options'].nil?
''
else
squash('', $cfg['linker']['options'])
end
includes = if $cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil?
''
else
squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
end.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
{ :command => command, :options => options, :includes => includes }
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']
(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']
execute(cmd_str)
end
def build_simulator_fields
return nil if $cfg['simulator'].nil?
if $cfg['simulator']['path'].nil?
command = ''
else
command = (tackit($cfg['simulator']['path']) + ' ')
end
if $cfg['simulator']['pre_support'].nil?
pre_support = ''
else
pre_support = squash('', $cfg['simulator']['pre_support'])
end
if $cfg['simulator']['post_support'].nil?
post_support = ''
else
post_support = squash('', $cfg['simulator']['post_support'])
end
return {:command => command, :pre_support => pre_support, :post_support => post_support}
command = if $cfg['simulator']['path'].nil?
''
else
(tackit($cfg['simulator']['path']) + ' ')
end
pre_support = if $cfg['simulator']['pre_support'].nil?
''
else
squash('', $cfg['simulator']['pre_support'])
end
post_support = if $cfg['simulator']['post_support'].nil?
''
else
squash('', $cfg['simulator']['post_support'])
end
{ :command => command, :pre_support => pre_support, :post_support => post_support }
end
def execute(command_string, ok_to_fail=false)
def execute(command_string, ok_to_fail = false)
report command_string if $verbose
output = `#{command_string}`.chomp
report(output) if ($verbose && !output.nil? && (output.length > 0))
if (($?.exitstatus != 0) && !ok_to_fail)
raise "Command failed. (Returned #{$?.exitstatus})"
end
return output
report(output) if $verbose && !output.nil? && !output.empty?
raise "Command failed. (Returned #{$?.exitstatus})" if !$?.exitstatus.zero? && !ok_to_fail
output
end
def report_summary
summary = UnityTestSummary.new
summary.set_root_path(UNITY_ROOT)
summary.root = UNITY_ROOT
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
results_glob.gsub!(/\\/, '/')
results_glob.tr!('\\', '/')
results = Dir[results_glob]
summary.set_targets(results)
summary.targets = results
report summary.run
end
@@ -187,16 +181,16 @@ module RakefileHelpers
# Tack on TEST define for compiling unit tests
load_configuration($cfg_file)
test_defines = ['TEST']
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
$cfg['compiler']['defines']['items'] ||= []
$cfg['compiler']['defines']['items'] << 'TEST'
include_dirs = get_local_include_dirs
include_dirs = local_include_dirs
# Build and execute each unit test
test_files.each do |test|
obj_list = []
if !$cfg['compiler']['aux_sources'].nil?
unless $cfg['compiler']['aux_sources'].nil?
$cfg['compiler']['aux_sources'].each do |aux|
obj_list << compile(aux, test_defines)
end
@@ -206,25 +200,23 @@ module RakefileHelpers
extract_headers(test).each do |header|
# Compile corresponding source file if it exists
src_file = find_source_file(header, include_dirs)
if !src_file.nil?
obj_list << compile(src_file, test_defines)
end
obj_list << compile(src_file, test_defines) unless src_file.nil?
end
# Build the test runner (generate if configured to do so)
test_base = File.basename(test, C_EXTENSION)
runner_name = test_base + '_Runner.c'
runner_path = ''
if $cfg['compiler']['runner_path'].nil?
runner_path = $cfg['compiler']['build_path'] + runner_name
else
runner_path = $cfg['compiler']['runner_path'] + runner_name
end
runner_path = if $cfg['compiler']['runner_path'].nil?
$cfg['compiler']['build_path'] + runner_name
else
$cfg['compiler']['runner_path'] + runner_name
end
options = $cfg[:unity]
options[:use_param_tests] = (test =~ /parameterized/) ? true : false
options[:use_param_tests] = test =~ /parameterized/ ? true : false
UnityTestRunnerGenerator.new(options).run(test, runner_path)
obj_list << compile(runner_path, test_defines)
@@ -237,21 +229,20 @@ module RakefileHelpers
# Execute unit test and generate results file
simulator = build_simulator_fields
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension']
if simulator.nil?
cmd_str = executable
else
cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
end
cmd_str = if simulator.nil?
executable
else
"#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
end
output = execute(cmd_str)
test_results = $cfg['compiler']['build_path'] + test_base
if output.match(/OK$/m).nil?
test_results += '.testfail'
else
report output if (!$verbose) #verbose already prints this line, as does a failure
report output unless $verbose # Verbose already prints this line, as does a failure
test_results += '.testpass'
end
File.open(test_results, 'w') { |f| f.print output }
end
end
end