mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-30 11:44:27 +01: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
|
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)
|
def self.grab_config(config_file)
|
||||||
includes = []
|
options = { :includes => [] }
|
||||||
options = {}
|
|
||||||
unless (config_file.nil? or config_file.empty?)
|
unless (config_file.nil? or config_file.empty?)
|
||||||
require 'yaml'
|
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[:cexception] = 1 if (yaml_goodness[:plugins].include? 'cexception')
|
||||||
options[:coverage ] = 1 if (yaml_goodness[:coverage])
|
options[:coverage ] = 1 if (yaml_goodness[:coverage])
|
||||||
options[:order] = 1 if (yaml_goodness[:enforce_strict_ordering])
|
options[:order] = 1 if (yaml_goodness[:enforce_strict_ordering])
|
||||||
includes << yaml_goodness[:includes]
|
options[:includes] << (yaml_goodness[:includes])
|
||||||
end
|
end
|
||||||
return([includes, options])
|
return(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(input_file, output_file, additional_includes=[], options={})
|
def run(input_file, output_file, options=nil)
|
||||||
@options = options
|
|
||||||
tests = []
|
tests = []
|
||||||
includes = []
|
includes = []
|
||||||
used_mocks = []
|
used_mocks = []
|
||||||
|
|
||||||
|
@options = options unless options.nil?
|
||||||
module_name = File.basename(input_file)
|
module_name = File.basename(input_file)
|
||||||
|
|
||||||
|
#pull required data from source file
|
||||||
File.open(input_file, 'r') do |input|
|
File.open(input_file, 'r') do |input|
|
||||||
tests = find_tests(input)
|
tests = find_tests(input)
|
||||||
includes = find_includes(input)
|
includes = find_includes(input)
|
||||||
used_mocks = find_mocks(includes)
|
used_mocks = find_mocks(includes)
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Creating test runner for #{File.basename(input_file)}..."
|
puts "Creating test runner for #{File.basename(input_file)}..."
|
||||||
|
|
||||||
|
#build runner file
|
||||||
File.open(output_file, 'w') do |output|
|
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_externs(output, tests, used_mocks)
|
||||||
create_mock_management(output, used_mocks)
|
create_mock_management(output, used_mocks)
|
||||||
create_runtest(output, used_mocks)
|
create_runtest(output, used_mocks)
|
||||||
@@ -42,7 +54,7 @@ class UnityTestRunnerGenerator
|
|||||||
|
|
||||||
all_files_used = [input_file, output_file]
|
all_files_used = [input_file, output_file]
|
||||||
all_files_used += includes.map {|filename| filename + '.c'} unless includes.empty?
|
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
|
return all_files_used.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -80,19 +92,19 @@ class UnityTestRunnerGenerator
|
|||||||
return mock_headers
|
return mock_headers
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_header(output, mocks, additional_includes=[])
|
def create_header(output, mocks)
|
||||||
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
|
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
|
||||||
output.puts('#include "unity.h"')
|
output.puts('#include "unity.h"')
|
||||||
additional_includes.flatten.each do |includes|
|
@options[:includes].flatten.each do |includes|
|
||||||
output.puts("#include \"#{includes.gsub('.h','')}.h\"")
|
output.puts("#include \"#{includes.gsub('.h','')}.h\"")
|
||||||
end
|
end
|
||||||
mocks.each do |mock|
|
|
||||||
output.puts("#include \"#{mock.gsub('.h','')}.h\"")
|
|
||||||
end
|
|
||||||
output.puts('#include <setjmp.h>')
|
output.puts('#include <setjmp.h>')
|
||||||
output.puts('#include <stdio.h>')
|
output.puts('#include <stdio.h>')
|
||||||
output.puts('#include "Exception.h"') if @options[:cexception]
|
output.puts('#include "Exception.h"') if @options[:cexception]
|
||||||
output.puts('#include "BullseyeCoverage.h"') if @options[:coverage]
|
output.puts('#include "BullseyeCoverage.h"') if @options[:coverage]
|
||||||
|
mocks.each do |mock|
|
||||||
|
output.puts("#include \"#{mock.gsub('.h','')}.h\"")
|
||||||
|
end
|
||||||
output.puts('')
|
output.puts('')
|
||||||
output.puts('char MessageBuffer[50];')
|
output.puts('char MessageBuffer[50];')
|
||||||
if @options[:order]
|
if @options[:order]
|
||||||
@@ -105,16 +117,12 @@ class UnityTestRunnerGenerator
|
|||||||
|
|
||||||
def create_externs(output, tests, mocks)
|
def create_externs(output, tests, mocks)
|
||||||
output.puts('')
|
output.puts('')
|
||||||
|
|
||||||
output.puts("extern void setUp(void);")
|
output.puts("extern void setUp(void);")
|
||||||
output.puts("extern void tearDown(void);")
|
output.puts("extern void tearDown(void);")
|
||||||
|
|
||||||
output.puts('')
|
output.puts('')
|
||||||
|
|
||||||
tests.each do |test|
|
tests.each do |test|
|
||||||
output.puts("extern void #{test}(void);")
|
output.puts("extern void #{test}(void);")
|
||||||
end
|
end
|
||||||
|
|
||||||
output.puts('')
|
output.puts('')
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -212,8 +220,8 @@ if ($0 == __FILE__)
|
|||||||
" -coverage - include bullseye coverage support",
|
" -coverage - include bullseye coverage support",
|
||||||
" -order - include cmock order-enforcement support" ]
|
" -order - include cmock order-enforcement support" ]
|
||||||
|
|
||||||
includes = []
|
options = { :includes => [] }
|
||||||
options = {}
|
yaml_file = nil
|
||||||
|
|
||||||
#parse out all the options first
|
#parse out all the options first
|
||||||
ARGV.reject! do |arg|
|
ARGV.reject! do |arg|
|
||||||
@@ -221,7 +229,7 @@ if ($0 == __FILE__)
|
|||||||
options[$1.to_sym] = 1
|
options[$1.to_sym] = 1
|
||||||
true
|
true
|
||||||
elsif (arg =~ /(\w+\.yml)/)
|
elsif (arg =~ /(\w+\.yml)/)
|
||||||
includes, options = UnityTestRunnerGenerator::grab_config($1)
|
options = UnityTestRunnerGenerator.grab_config(arg)
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
@@ -238,7 +246,7 @@ if ($0 == __FILE__)
|
|||||||
ARGV[1] = ARGV[0].gsub(".c","_Runner.c") if (!ARGV[1])
|
ARGV[1] = ARGV[0].gsub(".c","_Runner.c") if (!ARGV[1])
|
||||||
|
|
||||||
#everything else is an include file
|
#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
|
end
|
||||||
|
|||||||
18
src/unity.c
18
src/unity.c
@@ -2,8 +2,18 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
//rely on how C will fill the rest of the structure with 0's
|
struct _Unity Unity =
|
||||||
struct _Unity Unity = { 0 };
|
{
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1e-4f,
|
||||||
|
{0},
|
||||||
|
};
|
||||||
|
|
||||||
void UnityPrintChar(const char ch)
|
void UnityPrintChar(const char ch)
|
||||||
{
|
{
|
||||||
@@ -327,7 +337,7 @@ void UnityAssertIntsWithin(const long delta,
|
|||||||
void UnityAssertEqualString(const char* expected,
|
void UnityAssertEqualString(const char* expected,
|
||||||
const char* actual,
|
const char* actual,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
unsigned short lineNumber)
|
const unsigned short lineNumber)
|
||||||
{
|
{
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
|
|
||||||
@@ -373,7 +383,7 @@ void UnityAssertEqualMemory(const void* expected,
|
|||||||
const void* actual,
|
const void* actual,
|
||||||
unsigned long length,
|
unsigned long length,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
unsigned short lineNumber)
|
const unsigned short lineNumber)
|
||||||
{
|
{
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user