mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-27 18:24:27 +01:00
- rework to not bother with any of the ever-changing test frameworks in Ruby (sigh) for self-testing
- started working on cleaner floating point support. more coming.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# Unity Project - A Test Framework for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
# ==========================================
|
||||
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
@@ -13,7 +13,7 @@ require UNITY_ROOT + 'auto/colour_reporter'
|
||||
module RakefileHelpers
|
||||
|
||||
C_EXTENSION = '.c'
|
||||
|
||||
|
||||
def load_configuration(config_file)
|
||||
unless ($configured)
|
||||
$cfg_file = "targets/#{config_file}" unless (config_file =~ /[\\|\/]/)
|
||||
@@ -22,24 +22,24 @@ module RakefileHelpers
|
||||
$configured = true if (config_file != DEFAULT_CONFIG_FILE)
|
||||
end
|
||||
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)
|
||||
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
|
||||
path = $cfg['compiler']['unit_tests_path'] + 'test*' + C_EXTENSION
|
||||
path.gsub!(/\\/, '/')
|
||||
FileList.new(path)
|
||||
end
|
||||
|
||||
|
||||
def get_local_include_dirs
|
||||
include_dirs = $cfg['compiler']['includes']['items'].dup
|
||||
include_dirs.delete_if {|dir| dir.is_a?(Array)}
|
||||
@@ -67,7 +67,7 @@ module RakefileHelpers
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
def tackit(strings)
|
||||
if strings.is_a?(Array)
|
||||
result = "\"#{strings.join}\""
|
||||
@@ -76,13 +76,22 @@ module RakefileHelpers
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
def squash(prefix, items)
|
||||
result = ''
|
||||
items.each { |item| result += " #{prefix}#{tackit(item)}" }
|
||||
return result
|
||||
end
|
||||
|
||||
def should(behave, &block)
|
||||
if block
|
||||
puts "Should " + behave
|
||||
yield block
|
||||
else
|
||||
puts "UNIMPLEMENTED CASE: Should #{behave}"
|
||||
end
|
||||
end
|
||||
|
||||
def build_compiler_fields
|
||||
command = tackit($cfg['compiler']['path'])
|
||||
if $cfg['compiler']['defines']['items'].nil?
|
||||
@@ -104,7 +113,7 @@ module RakefileHelpers
|
||||
execute(cmd_str + obj_file)
|
||||
return obj_file
|
||||
end
|
||||
|
||||
|
||||
def build_linker_fields
|
||||
command = tackit($cfg['linker']['path'])
|
||||
if $cfg['linker']['options'].nil?
|
||||
@@ -120,7 +129,7 @@ module RakefileHelpers
|
||||
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
||||
return {: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]} " +
|
||||
@@ -130,7 +139,7 @@ module RakefileHelpers
|
||||
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?
|
||||
@@ -150,7 +159,7 @@ module RakefileHelpers
|
||||
end
|
||||
return {:command => command, :pre_support => pre_support, :post_support => post_support}
|
||||
end
|
||||
|
||||
|
||||
def execute(command_string, verbose=true)
|
||||
report command_string
|
||||
output = `#{command_string}`.chomp
|
||||
@@ -160,32 +169,32 @@ module RakefileHelpers
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
|
||||
def report_summary
|
||||
summary = UnityTestSummary.new
|
||||
summary.set_root_path(UNITY_ROOT )
|
||||
summary.set_root_path(UNITY_ROOT )
|
||||
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
||||
results_glob.gsub!(/\\/, '/')
|
||||
results = Dir[results_glob]
|
||||
summary.set_targets(results)
|
||||
summary.run
|
||||
end
|
||||
|
||||
|
||||
def run_tests(test_files)
|
||||
report 'Running Unity system tests...'
|
||||
|
||||
|
||||
# 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'] << 'TEST'
|
||||
|
||||
|
||||
include_dirs = get_local_include_dirs
|
||||
|
||||
|
||||
# Build and execute each unit test
|
||||
test_files.each do |test|
|
||||
obj_list = []
|
||||
|
||||
|
||||
# Detect dependencies and build required modules
|
||||
extract_headers(test).each do |header|
|
||||
# Compile corresponding source file if it exists
|
||||
@@ -194,30 +203,30 @@ module RakefileHelpers
|
||||
obj_list << compile(src_file, test_defines)
|
||||
end
|
||||
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
|
||||
|
||||
|
||||
options = $cfg[:unity]
|
||||
options[:use_param_tests] = (test =~ /parameterized/) ? true : false
|
||||
UnityTestRunnerGenerator.new(options).run(test, runner_path)
|
||||
obj_list << compile(runner_path, test_defines)
|
||||
|
||||
|
||||
# Build the test module
|
||||
obj_list << compile(test, test_defines)
|
||||
|
||||
|
||||
# Link the test executable
|
||||
link_it(test_base, obj_list)
|
||||
|
||||
|
||||
# Execute unit test and generate results file
|
||||
simulator = build_simulator_fields
|
||||
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension']
|
||||
@@ -234,7 +243,7 @@ module RakefileHelpers
|
||||
test_results += '.testpass'
|
||||
end
|
||||
File.open(test_results, 'w') { |f| f.print output }
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user