Update Unity to release 2.4.1

This commit is contained in:
Max Bruckner
2017-04-27 02:54:33 +02:00
38 changed files with 4251 additions and 1278 deletions

View File

@@ -0,0 +1,58 @@
# This is the configuration used to check the rubocop source code.
#inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.1
# These are areas where ThrowTheSwitch's coding style diverges from the Ruby standard
Style/SpecialGlobalVars:
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:
Enabled: false
EnforcedHashRocketStyle: table
EnforcedColonStyle: table
# We purposefully use these insecure features because they're what makes Ruby awesome
Security/Eval:
Enabled: false
Security/YAMLLoad:
Enabled: false
# At this point, we're not ready to enforce inline documentation requirements
Style/Documentation:
Enabled: false
Style/DocumentationMethod:
Enabled: false
# At this point, we're not ready to enforce any metrics
Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/BlockNesting:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/ModuleLength:
Enabled: false
Metrics/ParameterLists:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false

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"
@@ -53,7 +53,7 @@ task :summary do
end
desc "Build and test Unity"
task :all => [:clean, :prepare_for_tests, :scripts, :unit, :summary]
task :all => [:clean, :prepare_for_tests, :scripts, :unit, :style, :summary]
task :default => [:clobber, :all]
task :ci => [:no_color, :default]
task :cruise => [:no_color, :default]
@@ -70,3 +70,56 @@ end
task :verbose do
$verbose = true
end
namespace :style do
desc "Check style"
task :check do
report "\nVERIFYING RUBY STYLE"
report execute("rubocop ../auto ../examples ../extras --config .rubocop.yml", true)
report "Styling Ruby:PASS"
end
namespace :check do
Dir['../**/*.rb'].each do |f|
filename = File.basename(f, '.rb')
desc "Check Style of #{filename}"
task filename.to_sym => ['style:clean'] do
report execute("rubocop #{f} --color --config .rubocop.yml", true)
report "Style Checked for #{f}"
end
end
end
desc "Fix Style of all C Code"
task :c do
run_astyle("../src/*.* ../extras/fixture/src/*.*")
end
namespace :c do
Dir['../{src,extras/**}/*.{c,h}'].each do |f|
filename = File.basename(f)[0..-3]
desc "Check Style of #{filename}"
task filename.to_sym do
run_astyle f
end
end
end
desc "Attempt to Autocorrect style"
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 => ['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,103 @@ 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 run_astyle(style_what)
report "Styling C Code..."
command = "AStyle " \
"--style=allman --indent=spaces=4 --indent-switches --indent-preproc-define --indent-preproc-block " \
"--pad-oper --pad-comma --unpad-paren --pad-header " \
"--align-pointer=type --align-reference=name " \
"--add-brackets --mode=c --suffix=none " \
"#{style_what}"
execute(command, false)
report "Styling C:PASS"
end
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 +193,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 +212,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 +241,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

View File

@@ -36,7 +36,7 @@ compiler:
- '-Wbad-function-cast'
- '-fms-extensions'
- '-fno-omit-frame-pointer'
- '-ffloat-store'
#- '-ffloat-store'
- '-fno-common'
- '-fstrict-aliasing'
- '-std=gnu99'
@@ -55,8 +55,6 @@ compiler:
- UNITY_INCLUDE_DOUBLE
- UNITY_SUPPORT_TEST_CASES
- UNITY_SUPPORT_64
- UNITY_OUTPUT_FLUSH
- UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION
object_files:
prefix: '-o'
extension: '.o'

View File

@@ -4,6 +4,8 @@
#include "unity.h"
#include "Defs.h"
TEST_FILE("some_file.c")
/* Notes about prefixes:
test - normal default prefix. these are "always run" tests for this procedure
spec - normal default prefix. required to run default setup/teardown calls.

View File

@@ -1170,11 +1170,11 @@ def runner_test(test, runner, expected, test_defines, cmdline_args)
simulator = build_simulator_fields
cmdline_args ||= ""
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension'] + " #{cmdline_args}"
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, true)
#compare to the expected pass/fail

File diff suppressed because it is too large Load Diff