mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-23 08:25:58 +01:00
- moved unity helper into the example directory, because it's not really core.
- made generate_test_runner more flexible in how data comes in. git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@28 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
@@ -1,6 +1,20 @@
|
||||
|
||||
class UnityTestRunnerGenerator
|
||||
|
||||
def grab_config(config_file)
|
||||
includes = []
|
||||
options = {}
|
||||
unless (config_file.nil? or config_file.empty?)
|
||||
require 'yaml'
|
||||
yaml_goodness = YAML.load_file(config_file)[: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]
|
||||
end
|
||||
return([includes, options])
|
||||
end
|
||||
|
||||
def run(input_file, output_file, additional_includes=[], tab=' ', options={})
|
||||
@tab = tab
|
||||
@options = options
|
||||
@@ -67,11 +81,11 @@ class UnityTestRunnerGenerator
|
||||
def create_header(output, mocks, additional_includes=[])
|
||||
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
|
||||
output.puts('#include "unity.h"')
|
||||
additional_includes.each do |includes|
|
||||
output.puts("#include \"#{includes}.h\"")
|
||||
additional_includes.flatten.each do |includes|
|
||||
output.puts("#include \"#{includes.gsub('.h','')}.h\"")
|
||||
end
|
||||
mocks.each do |mock|
|
||||
output.puts("#include \"#{mock}.h\"")
|
||||
output.puts("#include \"#{mock.gsub('.h','')}.h\"")
|
||||
end
|
||||
output.puts('#include <setjmp.h>')
|
||||
output.puts('#include <stdio.h>')
|
||||
@@ -170,16 +184,15 @@ class UnityTestRunnerGenerator
|
||||
output.puts("#{@tab}return 0;")
|
||||
output.puts("}")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
if ($0 == __FILE__)
|
||||
usage = ["usage: ruby #{__FILE__} ( options ) input_test_file output_test_runner (includes)",
|
||||
usage = ["usage: ruby #{__FILE__} (yaml) (options) input_test_file output_test_runner (includes)",
|
||||
" blah.yml - will use config options in the yml file (see CMock docs)",
|
||||
" -cexception - include cexception support",
|
||||
" -coverage - include bullseye coverage support",
|
||||
" -order - include cmock order-enforcement support",
|
||||
" blah.yml - will use config options in the yml file (see CMock docs)" ]
|
||||
" -order - include cmock order-enforcement support" ]
|
||||
|
||||
includes = []
|
||||
options = {}
|
||||
@@ -190,12 +203,7 @@ if ($0 == __FILE__)
|
||||
options[$1.to_sym] = 1
|
||||
true
|
||||
elsif (arg =~ /(\w+\.yml)/)
|
||||
require 'yaml'
|
||||
yaml_goodness = YAML.load_file($1)[: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]
|
||||
includes, options = grab_config($1)
|
||||
true
|
||||
else
|
||||
false
|
||||
@@ -214,5 +222,5 @@ if ($0 == __FILE__)
|
||||
#everything else is an include file
|
||||
includes << ARGV.slice(2..-1) if (ARGV.size > 2)
|
||||
|
||||
UnityTestRunnerGenerator.new.run(ARGV[0], ARGV[1], includes.flatten.compact)
|
||||
UnityTestRunnerGenerator.new.run(ARGV[0], ARGV[1], includes.flatten.compact, ' ', options)
|
||||
end
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
#include "unity.h"
|
||||
#include "UnityHelper.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static char message[1024];
|
||||
|
||||
void AssertEqualUintArray(const unsigned int* expected, const unsigned int* actual, const unsigned int length)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
sprintf(message, "Array comparison failed at index %u.", i);
|
||||
TEST_ASSERT_EQUAL_UINT_MESSAGE(expected[i], actual[i], message);
|
||||
}
|
||||
}
|
||||
|
||||
void AssertEqualIntArray(const int* expected, const int* actual, const unsigned int length)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
sprintf(message, "Array comparison failed at index %u.", i);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected[i], actual[i], message);
|
||||
}
|
||||
}
|
||||
|
||||
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
sprintf(message, "Array mismatch at index %u, Expected %f, Actual %f, Tolerance %f, Delta %f", i, expected[i], actual[i], tolerance, (expected[i]-actual[i]));
|
||||
TEST_ASSERT_FLOAT_WITHIN_MESSAGE(tolerance, expected[i], actual[i], message);
|
||||
}
|
||||
}
|
||||
|
||||
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.x, actual.x, "Example Struct Failed For Field x");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.y, actual.y, "Example Struct Failed For Field y");
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef _TESTHELPER_H
|
||||
#define _TESTHELPER_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void AssertEqualUintArray(const unsigned int* expected, const unsigned int* actual, const unsigned int length);
|
||||
void AssertEqualIntArray(const int* expected, const int* actual, const unsigned int length);
|
||||
void AssertEqualCharArray(const char expected[], const char actual[], const int length);
|
||||
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length);
|
||||
void AssertEqualExampleStruct(const EXAMPLE_STRUCT_T expected, const EXAMPLE_STRUCT_T actual);
|
||||
|
||||
#define TEST_ASSERT_EQUAL_uint32_ARRAY(expected, actual, length) {AssertEqualUintArray(expected, actual, length);}
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, length) {AssertEqualIntArray(expected, actual, length);}
|
||||
#define TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length) {AssertFloatArrayWithin(tolerance, expected, actual, length);}
|
||||
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) {AssertEqualExampleStruct(expected, actual);}
|
||||
|
||||
#endif // _TESTHELPER_H
|
||||
Reference in New Issue
Block a user