提交 8117581f 编写于 作者: M mvandervoord

- 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
上级 d96d84f5
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
......@@ -2,8 +2,18 @@
#include <stdio.h>
#include <string.h>
//rely on how C will fill the rest of the structure with 0's
struct _Unity Unity = { 0 };
struct _Unity Unity =
{
NULL,
NULL,
0,
0,
0,
0,
0,
1e-4f,
{0},
};
void UnityPrintChar(const char ch)
{
......@@ -327,7 +337,7 @@ void UnityAssertIntsWithin(const long delta,
void UnityAssertEqualString(const char* expected,
const char* actual,
const char* msg,
unsigned short lineNumber)
const unsigned short lineNumber)
{
unsigned long i;
......@@ -373,7 +383,7 @@ void UnityAssertEqualMemory(const void* expected,
const void* actual,
unsigned long length,
const char* msg,
unsigned short lineNumber)
const unsigned short lineNumber)
{
if (length == 0)
return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册