mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-06-03 02:57:19 +08:00
- cleaned up interface to generate_test_runner.rb
- fixed a couple minor warnings in unity.c git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@39 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
@ -1,38 +1,50 @@
|
||||
|
||||
class UnityTestRunnerGenerator
|
||||
|
||||
def initialize(options = nil)
|
||||
@options = { :includes => [] }
|
||||
case(options)
|
||||
when NilClass then @options
|
||||
when String then @options = UnityTestRunnerGenerator.grab_config(options)
|
||||
when Hash then @options = options
|
||||
else raise "If you specify arguments, it should be a filename or a hash of options"
|
||||
end
|
||||
end
|
||||
|
||||
def self.grab_config(config_file)
|
||||
includes = []
|
||||
options = {}
|
||||
options = { :includes => [] }
|
||||
unless (config_file.nil? or config_file.empty?)
|
||||
require 'yaml'
|
||||
yaml_goodness = YAML.load_file(config_file)[:cmock]
|
||||
yaml_guts = YAML.load_file(config_file)
|
||||
yaml_goodness = yaml_guts[:unity] ? yaml_guts[:unity] : yaml_guts[:cmock]
|
||||
options[:cexception] = 1 if (yaml_goodness[:plugins].include? 'cexception')
|
||||
options[:coverage ] = 1 if (yaml_goodness[:coverage])
|
||||
options[:order] = 1 if (yaml_goodness[:enforce_strict_ordering])
|
||||
includes << yaml_goodness[:includes]
|
||||
options[:includes] << (yaml_goodness[:includes])
|
||||
end
|
||||
return([includes, options])
|
||||
return(options)
|
||||
end
|
||||
|
||||
def run(input_file, output_file, additional_includes=[], options={})
|
||||
@options = options
|
||||
def run(input_file, output_file, options=nil)
|
||||
tests = []
|
||||
includes = []
|
||||
used_mocks = []
|
||||
|
||||
@options = options unless options.nil?
|
||||
module_name = File.basename(input_file)
|
||||
|
||||
#pull required data from source file
|
||||
File.open(input_file, 'r') do |input|
|
||||
tests = find_tests(input)
|
||||
includes = find_includes(input)
|
||||
tests = find_tests(input)
|
||||
includes = find_includes(input)
|
||||
used_mocks = find_mocks(includes)
|
||||
end
|
||||
|
||||
puts "Creating test runner for #{File.basename(input_file)}..."
|
||||
|
||||
#build runner file
|
||||
File.open(output_file, 'w') do |output|
|
||||
create_header(output, used_mocks, additional_includes)
|
||||
create_header(output, used_mocks)
|
||||
create_externs(output, tests, used_mocks)
|
||||
create_mock_management(output, used_mocks)
|
||||
create_runtest(output, used_mocks)
|
||||
@ -42,7 +54,7 @@ class UnityTestRunnerGenerator
|
||||
|
||||
all_files_used = [input_file, output_file]
|
||||
all_files_used += includes.map {|filename| filename + '.c'} unless includes.empty?
|
||||
all_files_used += additional_includes unless additional_includes.empty?
|
||||
all_files_used += @options[:includes] unless @options[:includes].empty?
|
||||
return all_files_used.uniq
|
||||
end
|
||||
|
||||
@ -80,19 +92,19 @@ class UnityTestRunnerGenerator
|
||||
return mock_headers
|
||||
end
|
||||
|
||||
def create_header(output, mocks, additional_includes=[])
|
||||
def create_header(output, mocks)
|
||||
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
|
||||
output.puts('#include "unity.h"')
|
||||
additional_includes.flatten.each do |includes|
|
||||
@options[:includes].flatten.each do |includes|
|
||||
output.puts("#include \"#{includes.gsub('.h','')}.h\"")
|
||||
end
|
||||
mocks.each do |mock|
|
||||
output.puts("#include \"#{mock.gsub('.h','')}.h\"")
|
||||
end
|
||||
output.puts('#include <setjmp.h>')
|
||||
output.puts('#include <stdio.h>')
|
||||
output.puts('#include "Exception.h"') if @options[:cexception]
|
||||
output.puts('#include "BullseyeCoverage.h"') if @options[:coverage]
|
||||
mocks.each do |mock|
|
||||
output.puts("#include \"#{mock.gsub('.h','')}.h\"")
|
||||
end
|
||||
output.puts('')
|
||||
output.puts('char MessageBuffer[50];')
|
||||
if @options[:order]
|
||||
@ -105,16 +117,12 @@ class UnityTestRunnerGenerator
|
||||
|
||||
def create_externs(output, tests, mocks)
|
||||
output.puts('')
|
||||
|
||||
output.puts("extern void setUp(void);")
|
||||
output.puts("extern void tearDown(void);")
|
||||
|
||||
output.puts('')
|
||||
|
||||
tests.each do |test|
|
||||
output.puts("extern void #{test}(void);")
|
||||
end
|
||||
|
||||
output.puts('')
|
||||
end
|
||||
|
||||
@ -212,8 +220,8 @@ if ($0 == __FILE__)
|
||||
" -coverage - include bullseye coverage support",
|
||||
" -order - include cmock order-enforcement support" ]
|
||||
|
||||
includes = []
|
||||
options = {}
|
||||
options = { :includes => [] }
|
||||
yaml_file = nil
|
||||
|
||||
#parse out all the options first
|
||||
ARGV.reject! do |arg|
|
||||
@ -221,7 +229,7 @@ if ($0 == __FILE__)
|
||||
options[$1.to_sym] = 1
|
||||
true
|
||||
elsif (arg =~ /(\w+\.yml)/)
|
||||
includes, options = UnityTestRunnerGenerator::grab_config($1)
|
||||
options = UnityTestRunnerGenerator.grab_config(arg)
|
||||
true
|
||||
else
|
||||
false
|
||||
@ -238,7 +246,7 @@ if ($0 == __FILE__)
|
||||
ARGV[1] = ARGV[0].gsub(".c","_Runner.c") if (!ARGV[1])
|
||||
|
||||
#everything else is an include file
|
||||
includes << ARGV.slice(2..-1) if (ARGV.size > 2)
|
||||
options[:includes] = (ARGV.slice(2..-1).flatten.compact) if (ARGV.size > 2)
|
||||
|
||||
UnityTestRunnerGenerator.new.run(ARGV[0], ARGV[1], includes.flatten.compact, options)
|
||||
UnityTestRunnerGenerator.new(options).run(ARGV[0], ARGV[1])
|
||||
end
|
||||
|
Reference in New Issue
Block a user