- 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:
Mark VanderVoord
2014-07-21 14:00:53 -04:00
parent 39cc60ce56
commit 96155881ed
7 changed files with 248 additions and 132 deletions

View File

@ -2,7 +2,7 @@
# Unity Project - A Test Framework for C # Unity Project - A Test Framework for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details] # [Released under MIT License. Please refer to license.txt for details]
# ========================================== # ==========================================
UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/' UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/'
@ -33,9 +33,11 @@ task :unit => [:prepare_for_tests] do
run_tests get_unit_test_files run_tests get_unit_test_files
end end
Rake::TestTask.new(:scripts) do |t| desc "Test unity's helper scripts"
t.pattern = 'test/test_*.rb' task :scripts => [:prepare_for_tests] do
t.verbose = true Dir['test/test_*.rb'].each do |scriptfile|
require "./"+scriptfile
end
end end
desc "Generate test summary" desc "Generate test summary"

View File

@ -2,7 +2,7 @@
# Unity Project - A Test Framework for C # Unity Project - A Test Framework for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details] # [Released under MIT License. Please refer to license.txt for details]
# ========================================== # ==========================================
require 'yaml' require 'yaml'
require 'fileutils' require 'fileutils'
@ -13,7 +13,7 @@ require UNITY_ROOT + 'auto/colour_reporter'
module RakefileHelpers module RakefileHelpers
C_EXTENSION = '.c' C_EXTENSION = '.c'
def load_configuration(config_file) def load_configuration(config_file)
unless ($configured) unless ($configured)
$cfg_file = "targets/#{config_file}" unless (config_file =~ /[\\|\/]/) $cfg_file = "targets/#{config_file}" unless (config_file =~ /[\\|\/]/)
@ -22,24 +22,24 @@ module RakefileHelpers
$configured = true if (config_file != DEFAULT_CONFIG_FILE) $configured = true if (config_file != DEFAULT_CONFIG_FILE)
end end
end end
def configure_clean def configure_clean
CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil? CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil?
end end
def configure_toolchain(config_file=DEFAULT_CONFIG_FILE) def configure_toolchain(config_file=DEFAULT_CONFIG_FILE)
config_file += '.yml' unless config_file =~ /\.yml$/ config_file += '.yml' unless config_file =~ /\.yml$/
config_file = config_file unless config_file =~ /[\\|\/]/ config_file = config_file unless config_file =~ /[\\|\/]/
load_configuration(config_file) load_configuration(config_file)
configure_clean configure_clean
end end
def get_unit_test_files def get_unit_test_files
path = $cfg['compiler']['unit_tests_path'] + 'test*' + C_EXTENSION path = $cfg['compiler']['unit_tests_path'] + 'test*' + C_EXTENSION
path.gsub!(/\\/, '/') path.gsub!(/\\/, '/')
FileList.new(path) FileList.new(path)
end end
def get_local_include_dirs def get_local_include_dirs
include_dirs = $cfg['compiler']['includes']['items'].dup include_dirs = $cfg['compiler']['includes']['items'].dup
include_dirs.delete_if {|dir| dir.is_a?(Array)} include_dirs.delete_if {|dir| dir.is_a?(Array)}
@ -67,7 +67,7 @@ module RakefileHelpers
end end
return nil return nil
end end
def tackit(strings) def tackit(strings)
if strings.is_a?(Array) if strings.is_a?(Array)
result = "\"#{strings.join}\"" result = "\"#{strings.join}\""
@ -76,13 +76,22 @@ module RakefileHelpers
end end
return result return result
end end
def squash(prefix, items) def squash(prefix, items)
result = '' result = ''
items.each { |item| result += " #{prefix}#{tackit(item)}" } items.each { |item| result += " #{prefix}#{tackit(item)}" }
return result return result
end end
def should(behave, &block)
if block
puts "Should " + behave
yield block
else
puts "UNIMPLEMENTED CASE: Should #{behave}"
end
end
def build_compiler_fields def build_compiler_fields
command = tackit($cfg['compiler']['path']) command = tackit($cfg['compiler']['path'])
if $cfg['compiler']['defines']['items'].nil? if $cfg['compiler']['defines']['items'].nil?
@ -104,7 +113,7 @@ module RakefileHelpers
execute(cmd_str + obj_file) execute(cmd_str + obj_file)
return obj_file return obj_file
end end
def build_linker_fields def build_linker_fields
command = tackit($cfg['linker']['path']) command = tackit($cfg['linker']['path'])
if $cfg['linker']['options'].nil? if $cfg['linker']['options'].nil?
@ -120,7 +129,7 @@ module RakefileHelpers
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
return {:command => command, :options => options, :includes => includes} return {:command => command, :options => options, :includes => includes}
end end
def link_it(exe_name, obj_list) def link_it(exe_name, obj_list)
linker = build_linker_fields linker = build_linker_fields
cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " + cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " +
@ -130,7 +139,7 @@ module RakefileHelpers
exe_name + $cfg['linker']['bin_files']['extension'] exe_name + $cfg['linker']['bin_files']['extension']
execute(cmd_str) execute(cmd_str)
end end
def build_simulator_fields def build_simulator_fields
return nil if $cfg['simulator'].nil? return nil if $cfg['simulator'].nil?
if $cfg['simulator']['path'].nil? if $cfg['simulator']['path'].nil?
@ -150,7 +159,7 @@ module RakefileHelpers
end end
return {:command => command, :pre_support => pre_support, :post_support => post_support} return {:command => command, :pre_support => pre_support, :post_support => post_support}
end end
def execute(command_string, verbose=true) def execute(command_string, verbose=true)
report command_string report command_string
output = `#{command_string}`.chomp output = `#{command_string}`.chomp
@ -160,32 +169,32 @@ module RakefileHelpers
end end
return output return output
end end
def report_summary def report_summary
summary = UnityTestSummary.new summary = UnityTestSummary.new
summary.set_root_path(UNITY_ROOT ) summary.set_root_path(UNITY_ROOT )
results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob = "#{$cfg['compiler']['build_path']}*.test*"
results_glob.gsub!(/\\/, '/') results_glob.gsub!(/\\/, '/')
results = Dir[results_glob] results = Dir[results_glob]
summary.set_targets(results) summary.set_targets(results)
summary.run summary.run
end end
def run_tests(test_files) def run_tests(test_files)
report 'Running Unity system tests...' report 'Running Unity system tests...'
# Tack on TEST define for compiling unit tests # Tack on TEST define for compiling unit tests
load_configuration($cfg_file) load_configuration($cfg_file)
test_defines = ['TEST'] test_defines = ['TEST']
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil? $cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
$cfg['compiler']['defines']['items'] << 'TEST' $cfg['compiler']['defines']['items'] << 'TEST'
include_dirs = get_local_include_dirs include_dirs = get_local_include_dirs
# Build and execute each unit test # Build and execute each unit test
test_files.each do |test| test_files.each do |test|
obj_list = [] obj_list = []
# Detect dependencies and build required modules # Detect dependencies and build required modules
extract_headers(test).each do |header| extract_headers(test).each do |header|
# Compile corresponding source file if it exists # Compile corresponding source file if it exists
@ -194,30 +203,30 @@ module RakefileHelpers
obj_list << compile(src_file, test_defines) obj_list << compile(src_file, test_defines)
end end
end end
# Build the test runner (generate if configured to do so) # Build the test runner (generate if configured to do so)
test_base = File.basename(test, C_EXTENSION) test_base = File.basename(test, C_EXTENSION)
runner_name = test_base + '_Runner.c' runner_name = test_base + '_Runner.c'
runner_path = '' runner_path = ''
if $cfg['compiler']['runner_path'].nil? if $cfg['compiler']['runner_path'].nil?
runner_path = $cfg['compiler']['build_path'] + runner_name runner_path = $cfg['compiler']['build_path'] + runner_name
else else
runner_path = $cfg['compiler']['runner_path'] + runner_name runner_path = $cfg['compiler']['runner_path'] + runner_name
end end
options = $cfg[:unity] options = $cfg[:unity]
options[:use_param_tests] = (test =~ /parameterized/) ? true : false options[:use_param_tests] = (test =~ /parameterized/) ? true : false
UnityTestRunnerGenerator.new(options).run(test, runner_path) UnityTestRunnerGenerator.new(options).run(test, runner_path)
obj_list << compile(runner_path, test_defines) obj_list << compile(runner_path, test_defines)
# Build the test module # Build the test module
obj_list << compile(test, test_defines) obj_list << compile(test, test_defines)
# Link the test executable # Link the test executable
link_it(test_base, obj_list) link_it(test_base, obj_list)
# Execute unit test and generate results file # Execute unit test and generate results file
simulator = build_simulator_fields simulator = build_simulator_fields
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension'] executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension']
@ -234,7 +243,7 @@ module RakefileHelpers
test_results += '.testpass' test_results += '.testpass'
end end
File.open(test_results, 'w') { |f| f.print output } File.open(test_results, 'w') { |f| f.print output }
end end
end end
end end

View File

@ -28,6 +28,7 @@ const char* UnityStrDelta = " Values Not Within Delta ";
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless."; const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL"; const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
const char* UnityStrNullPointerForActual = " Actual pointer was NULL"; const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
const char* UnityStrNot = "Not ";
const char* UnityStrInf = "Infinity"; const char* UnityStrInf = "Infinity";
const char* UnityStrNegInf = "Negative Infinity"; const char* UnityStrNegInf = "Negative Infinity";
const char* UnityStrNaN = "NaN"; const char* UnityStrNaN = "NaN";
@ -614,6 +615,7 @@ void UnityAssertFloatsWithin(const _UF delta,
//----------------------------------------------- //-----------------------------------------------
void UnityAssertFloatIsInf(const _UF actual, void UnityAssertFloatIsInf(const _UF actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber) const UNITY_LINE_TYPE lineNumber)
{ {
@ -624,16 +626,21 @@ void UnityAssertFloatIsInf(const _UF actual,
// produces // produces
// error C2124: divide or mod by zero // error C2124: divide or mod by zero
// As a workaround, place 0 into a variable. // As a workaround, place 0 into a variable.
if ((1.0f / f_zero) != actual) _U_SINT is_inf = ((1.0f / f_zero) == actual) ? 1 : 0;
if (is_inf != should_be)
{ {
UnityTestResultsFailBegin(lineNumber); UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected); UnityPrint(UnityStrExpected);
if (!should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrInf); UnityPrint(UnityStrInf);
UnityPrint(UnityStrWas); UnityPrint(UnityStrWas);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrintFloat(actual); UnityPrintFloat(actual);
#else #else
UnityPrint(UnityStrDelta); if (should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrInf);
#endif #endif
UnityAddMsgIfSpecified(msg); UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL; UNITY_FAIL_AND_BAIL;
@ -642,22 +649,28 @@ void UnityAssertFloatIsInf(const _UF actual,
//----------------------------------------------- //-----------------------------------------------
void UnityAssertFloatIsNegInf(const _UF actual, void UnityAssertFloatIsNegInf(const _UF actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber) const UNITY_LINE_TYPE lineNumber)
{ {
UNITY_SKIP_EXECUTION; UNITY_SKIP_EXECUTION;
// The rationale for not using 1.0f/0.0f is given in UnityAssertFloatIsInf's body. // The rationale for not using 1.0f/0.0f is given in UnityAssertFloatIsInf's body.
if ((-1.0f / f_zero) != actual) _U_SINT is_inf = ((-1.0f / f_zero) == actual) ? 1 : 0;
if (is_inf != should_be)
{ {
UnityTestResultsFailBegin(lineNumber); UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected); UnityPrint(UnityStrExpected);
if (!should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrNegInf); UnityPrint(UnityStrNegInf);
UnityPrint(UnityStrWas); UnityPrint(UnityStrWas);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrintFloat(actual); UnityPrintFloat(actual);
#else #else
UnityPrint(UnityStrDelta); if (should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrNegInf);
#endif #endif
UnityAddMsgIfSpecified(msg); UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL; UNITY_FAIL_AND_BAIL;
@ -666,21 +679,30 @@ void UnityAssertFloatIsNegInf(const _UF actual,
//----------------------------------------------- //-----------------------------------------------
void UnityAssertFloatIsNaN(const _UF actual, void UnityAssertFloatIsNaN(const _UF actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber) const UNITY_LINE_TYPE lineNumber)
{ {
UNITY_SKIP_EXECUTION; UNITY_SKIP_EXECUTION;
if (actual == actual) //NaN is the only floating point value that does NOT
//equal itself. Therefore if Actual == Actual, then it
//is NOT NaN.
_U_SINT is_nan = (actual == actual) ? 0 : 1;
if (is_nan != should_be)
{ {
UnityTestResultsFailBegin(lineNumber); UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected); UnityPrint(UnityStrExpected);
if (!should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrNaN); UnityPrint(UnityStrNaN);
UnityPrint(UnityStrWas); UnityPrint(UnityStrWas);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrintFloat(actual); UnityPrintFloat(actual);
#else #else
UnityPrint(UnityStrDelta); if (should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrNaN);
#endif #endif
UnityAddMsgIfSpecified(msg); UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL; UNITY_FAIL_AND_BAIL;
@ -786,6 +808,7 @@ void UnityAssertDoublesWithin(const _UD delta,
//----------------------------------------------- //-----------------------------------------------
void UnityAssertDoubleIsInf(const _UD actual, void UnityAssertDoubleIsInf(const _UD actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber) const UNITY_LINE_TYPE lineNumber)
{ {
@ -810,6 +833,7 @@ void UnityAssertDoubleIsInf(const _UD actual,
//----------------------------------------------- //-----------------------------------------------
void UnityAssertDoubleIsNegInf(const _UD actual, void UnityAssertDoubleIsNegInf(const _UD actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber) const UNITY_LINE_TYPE lineNumber)
{ {
@ -834,6 +858,7 @@ void UnityAssertDoubleIsNegInf(const _UD actual,
//----------------------------------------------- //-----------------------------------------------
void UnityAssertDoubleIsNaN(const _UD actual, void UnityAssertDoubleIsNaN(const _UD actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber) const UNITY_LINE_TYPE lineNumber)
{ {
@ -1093,8 +1118,8 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
//----------------------------------------------- //-----------------------------------------------
#ifdef UNITY_SUPPORT_WEAK #ifdef UNITY_SUPPORT_WEAK
void setUp(void) { } UNITY_WEAK void setUp(void) { }
void tearDown(void) { } UNITY_WEAK void tearDown(void) { }
#else #else
void setUp(void); void setUp(void);
void tearDown(void); void tearDown(void);

View File

@ -174,6 +174,9 @@
#define TEST_ASSERT_FLOAT_IS_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_NOT_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_NOT_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN(actual, __LINE__, NULL)
//Double (If Enabled) //Double (If Enabled)
#define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, NULL)
@ -182,6 +185,9 @@
#define TEST_ASSERT_DOUBLE_IS_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_NOT_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, __LINE__, NULL)
//------------------------------------------------------- //-------------------------------------------------------
// Test Asserts (with additional messages) // Test Asserts (with additional messages)
@ -260,6 +266,9 @@
#define TEST_ASSERT_FLOAT_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, message) #define TEST_ASSERT_FLOAT_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, message)
#define TEST_ASSERT_FLOAT_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, message) #define TEST_ASSERT_FLOAT_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, message)
#define TEST_ASSERT_FLOAT_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, message) #define TEST_ASSERT_FLOAT_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, message)
#define TEST_ASSERT_FLOAT_IS_NOT_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, __LINE__, message)
#define TEST_ASSERT_FLOAT_IS_NOT_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, __LINE__, message)
#define TEST_ASSERT_FLOAT_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN(actual, __LINE__, message)
//Double (If Enabled) //Double (If Enabled)
#define TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, message)
@ -268,4 +277,7 @@
#define TEST_ASSERT_DOUBLE_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, message) #define TEST_ASSERT_DOUBLE_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, message)
#define TEST_ASSERT_DOUBLE_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, message) #define TEST_ASSERT_DOUBLE_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, message)
#define TEST_ASSERT_DOUBLE_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, message) #define TEST_ASSERT_DOUBLE_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, message)
#define TEST_ASSERT_DOUBLE_IS_NOT_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, __LINE__, message)
#define TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, __LINE__, message)
#define TEST_ASSERT_DOUBLE_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, __LINE__, message)
#endif #endif

View File

@ -274,7 +274,7 @@ extern int UNITY_OUTPUT_CHAR(int);
#ifndef UNITY_WEAK #ifndef UNITY_WEAK
#ifdef UNITY_SUPPORT_WEAK #ifdef UNITY_SUPPORT_WEAK
#define UNITY_WEAK __attribute__((weak)) #define UNITY_WEAK UNITY_SUPPORT_WEAK
#else #else
#define UNITY_WEAK #define UNITY_WEAK
#endif #endif
@ -438,14 +438,17 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
const UNITY_LINE_TYPE lineNumber); const UNITY_LINE_TYPE lineNumber);
void UnityAssertFloatIsInf(const _UF actual, void UnityAssertFloatIsInf(const _UF actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber); const UNITY_LINE_TYPE lineNumber);
void UnityAssertFloatIsNegInf(const _UF actual, void UnityAssertFloatIsNegInf(const _UF actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber); const UNITY_LINE_TYPE lineNumber);
void UnityAssertFloatIsNaN(const _UF actual, void UnityAssertFloatIsNaN(const _UF actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber); const UNITY_LINE_TYPE lineNumber);
#endif #endif
@ -464,14 +467,17 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
const UNITY_LINE_TYPE lineNumber); const UNITY_LINE_TYPE lineNumber);
void UnityAssertDoubleIsInf(const _UD actual, void UnityAssertDoubleIsInf(const _UD actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber); const UNITY_LINE_TYPE lineNumber);
void UnityAssertDoubleIsNegInf(const _UD actual, void UnityAssertDoubleIsNegInf(const _UD actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber); const UNITY_LINE_TYPE lineNumber);
void UnityAssertDoubleIsNaN(const _UD actual, void UnityAssertDoubleIsNaN(const _UD actual,
const _U_SINT should_be,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber); const UNITY_LINE_TYPE lineNumber);
#endif #endif
@ -550,9 +556,12 @@ void UnityAssertDoubleIsNaN(const _UD actual,
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#endif #endif
#ifdef UNITY_EXCLUDE_DOUBLE #ifdef UNITY_EXCLUDE_DOUBLE
@ -566,9 +575,12 @@ void UnityAssertDoubleIsNaN(const _UD actual,
#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((_UD)(delta), (_UD)(expected), (_UD)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((_UD)(delta), (_UD)(expected), (_UD)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((_UD)(expected) * (_UD)UNITY_DOUBLE_PRECISION, (_UD)expected, (_UD)actual, (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((_UD)(expected) * (_UD)UNITY_DOUBLE_PRECISION, (_UD)expected, (_UD)actual, (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((_UD*)(expected), (_UD*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((_UD*)(expected), (_UD*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleIsInf((_UD)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleIsInf((_UD)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleIsNegInf((_UD)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleIsNegInf((_UD)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleIsNaN((_UD)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleIsNaN((_UD)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, line, message) UnityAssertDoubleIsInf((_UD)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, line, message) UnityAssertDoubleIsNegInf((_UD)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, line, message) UnityAssertDoubleIsNaN((_UD)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#endif #endif
#endif #endif

View File

@ -2,14 +2,8 @@
# CMock Project - Automatic Mock Generation for C # CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details] # [Released under MIT License. Please refer to license.txt for details]
# ========================================== # ==========================================
ruby_version = RUBY_VERSION.split('.')
if (ruby_version[1].to_i == 9) and (ruby_version[2].to_i > 1)
require 'rubygems'
gem 'test-unit'
end
require 'test/unit'
require './auto/generate_test_runner.rb' require './auto/generate_test_runner.rb'
TEST_FILE = 'test/testdata/testsample.c' TEST_FILE = 'test/testdata/testsample.c'
@ -17,78 +11,78 @@ TEST_MOCK = 'test/testdata/mocksample.c'
OUT_FILE = 'build/testsample_' OUT_FILE = 'build/testsample_'
EXP_FILE = 'test/expectdata/testsample_' EXP_FILE = 'test/expectdata/testsample_'
class TestGenerateTestRunner < Test::Unit::TestCase $generate_test_runner_failures = 0
def setup
end
def teardown def verify_output_equal(subtest)
expected = File.read(EXP_FILE + subtest + '.c').gsub(/\r\n/,"\n")
actual = File.read(OUT_FILE + subtest + '.c').gsub(/\r\n/,"\n")
if (expected != actual)
report(" #{subtest}:FAIL")
$generate_test_runner_failures += 1
else
report(" #{subtest}:PASS")
end end
def verify_output_equal(subtest)
expected = File.read(EXP_FILE + subtest + '.c').gsub(/\r\n/,"\n")
actual = File.read(OUT_FILE + subtest + '.c').gsub(/\r\n/,"\n")
assert_equal(expected, actual, "Generated File Sub-Test '#{subtest}' Failed")
end
def test_ShouldGenerateARunnerByCreatingRunnerWithOptions
sets = { 'def' => nil,
'new1' => { :plugins => [:cexception], :includes => ['one.h', 'two.h'], :enforce_strict_ordering => true },
'new2' => { :plugins => [:ignore], :suite_setup => "a_custom_setup();", :suite_teardown => "a_custom_teardown();" }
}
sets.each_pair do |subtest, options|
UnityTestRunnerGenerator.new(options).run(TEST_FILE, OUT_FILE + subtest + '.c')
verify_output_equal(subtest)
UnityTestRunnerGenerator.new(options).run(TEST_MOCK, OUT_FILE + 'mock_' + subtest + '.c')
verify_output_equal('mock_' + subtest)
end
end
def test_ShouldGenerateARunnerByRunningRunnerWithOptions
sets = { 'run1' => { :plugins => [:cexception], :includes => ['one.h', 'two.h'], :enforce_strict_ordering => true },
'run2' => { :plugins => [:ignore], :suite_setup => "a_custom_setup();", :suite_teardown => "a_custom_teardown();" }
}
sets.each_pair do |subtest, options|
UnityTestRunnerGenerator.new.run(TEST_FILE, OUT_FILE + subtest + '.c', options)
verify_output_equal(subtest)
UnityTestRunnerGenerator.new.run(TEST_MOCK, OUT_FILE + 'mock_' + subtest + '.c', options)
verify_output_equal('mock_' + subtest)
end
end
def test_ShouldGenerateARunnerByPullingYamlOptions
subtest = 'yaml'
cmdstr = "ruby auto/generate_test_runner.rb test/testdata/sample.yml \"#{TEST_FILE}\" \"#{OUT_FILE + subtest + '.c'}\""
`#{cmdstr}`
verify_output_equal(subtest)
cmdstr = "ruby auto/generate_test_runner.rb test/testdata/sample.yml \"#{TEST_MOCK}\" \"#{OUT_FILE + 'mock_' + subtest + '.c'}\""
`#{cmdstr}`
verify_output_equal('mock_' + subtest)
end
def test_ShouldGenerateARunnerByPullingCommandlineOptions
subtest = 'cmd'
cmdstr = "ruby auto/generate_test_runner.rb -cexception \"#{TEST_FILE}\" \"#{OUT_FILE + subtest + '.c'}\""
`#{cmdstr}`
verify_output_equal(subtest)
cmdstr = "ruby auto/generate_test_runner.rb -cexception \"#{TEST_MOCK}\" \"#{OUT_FILE + 'mock_' + subtest + '.c'}\""
`#{cmdstr}`
verify_output_equal('mock_' + subtest)
end
def test_ShouldGenerateARunnerThatUsesParameterizedTests
sets = { 'param' => { :plugins => [:ignore], :use_param_tests => true }
}
sets.each_pair do |subtest, options|
UnityTestRunnerGenerator.new(options).run(TEST_FILE, OUT_FILE + subtest + '.c')
verify_output_equal(subtest)
UnityTestRunnerGenerator.new(options).run(TEST_MOCK, OUT_FILE + 'mock_' + subtest + '.c')
verify_output_equal('mock_' + subtest)
end
end
end end
should "GenerateARunnerByCreatingRunnerWithOptions" do
sets = { 'def' => nil,
'new1' => { :plugins => [:cexception], :includes => ['one.h', 'two.h'], :enforce_strict_ordering => true },
'new2' => { :plugins => [:ignore], :suite_setup => "a_custom_setup();", :suite_teardown => "a_custom_teardown();" }
}
sets.each_pair do |subtest, options|
UnityTestRunnerGenerator.new(options).run(TEST_FILE, OUT_FILE + subtest + '.c')
verify_output_equal(subtest)
UnityTestRunnerGenerator.new(options).run(TEST_MOCK, OUT_FILE + 'mock_' + subtest + '.c')
verify_output_equal('mock_' + subtest)
end
end
should "GenerateARunnerByRunningRunnerWithOptions" do
sets = { 'run1' => { :plugins => [:cexception], :includes => ['one.h', 'two.h'], :enforce_strict_ordering => true },
'run2' => { :plugins => [:ignore], :suite_setup => "a_custom_setup();", :suite_teardown => "a_custom_teardown();" }
}
sets.each_pair do |subtest, options|
UnityTestRunnerGenerator.new.run(TEST_FILE, OUT_FILE + subtest + '.c', options)
verify_output_equal(subtest)
UnityTestRunnerGenerator.new.run(TEST_MOCK, OUT_FILE + 'mock_' + subtest + '.c', options)
verify_output_equal('mock_' + subtest)
end
end
should "GenerateARunnerByPullingYamlOptions" do
subtest = 'yaml'
cmdstr = "ruby auto/generate_test_runner.rb test/testdata/sample.yml \"#{TEST_FILE}\" \"#{OUT_FILE + subtest + '.c'}\""
`#{cmdstr}`
verify_output_equal(subtest)
cmdstr = "ruby auto/generate_test_runner.rb test/testdata/sample.yml \"#{TEST_MOCK}\" \"#{OUT_FILE + 'mock_' + subtest + '.c'}\""
`#{cmdstr}`
verify_output_equal('mock_' + subtest)
end
should "GenerateARunnerByPullingCommandlineOptions" do
subtest = 'cmd'
cmdstr = "ruby auto/generate_test_runner.rb -cexception \"#{TEST_FILE}\" \"#{OUT_FILE + subtest + '.c'}\""
`#{cmdstr}`
verify_output_equal(subtest)
cmdstr = "ruby auto/generate_test_runner.rb -cexception \"#{TEST_MOCK}\" \"#{OUT_FILE + 'mock_' + subtest + '.c'}\""
`#{cmdstr}`
verify_output_equal('mock_' + subtest)
end
should "GenerateARunnerThatUsesParameterizedTests" do
sets = { 'param' => { :plugins => [:ignore], :use_param_tests => true }
}
sets.each_pair do |subtest, options|
UnityTestRunnerGenerator.new(options).run(TEST_FILE, OUT_FILE + subtest + '.c')
verify_output_equal(subtest)
UnityTestRunnerGenerator.new(options).run(TEST_MOCK, OUT_FILE + 'mock_' + subtest + '.c')
verify_output_equal('mock_' + subtest)
end
end
raise "There were #{$generate_test_runner_failures.to_s} failures while testing generate_test_runner.rb" if ($generate_test_runner_failures > 0)

View File

@ -9,7 +9,10 @@
// Dividing by these constants produces +/- infinity. // Dividing by these constants produces +/- infinity.
// The rationale is given in UnityAssertFloatIsInf's body. // The rationale is given in UnityAssertFloatIsInf's body.
#ifndef UNITY_EXCLUDE_FLOAT
static const _UF f_zero = 0.0f; static const _UF f_zero = 0.0f;
#endif
#ifndef UNITY_EXCLUDE_DOUBLE #ifndef UNITY_EXCLUDE_DOUBLE
static const _UD d_zero = 0.0; static const _UD d_zero = 0.0;
#endif #endif
@ -2332,17 +2335,47 @@ void testFloatsNotEqualPlusMinusInf(void)
#endif #endif
} }
void testFloatIsInf(void) void testFloatIsPosInf1(void)
{ {
#ifdef UNITY_EXCLUDE_FLOAT #ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE(); TEST_IGNORE();
#else #else
TEST_ASSERT_FLOAT_IS_INF(2.0f / f_zero); TEST_ASSERT_FLOAT_IS_INF(2.0f / f_zero);
#endif
}
void testFloatIsPosInf2(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_NOT_INF(2.0f / f_zero);
VERIFY_FAILS_END
#endif
}
void testFloatIsNegInf1(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
TEST_ASSERT_FLOAT_IS_NEG_INF(-3.0f / f_zero); TEST_ASSERT_FLOAT_IS_NEG_INF(-3.0f / f_zero);
#endif #endif
} }
void testFloatIsNotInf(void) void testFloatIsNegInf2(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(-3.0f / f_zero);
VERIFY_FAILS_END
#endif
}
void testFloatIsNotPosInf1(void)
{ {
#ifdef UNITY_EXCLUDE_FLOAT #ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE(); TEST_IGNORE();
@ -2353,6 +2386,15 @@ void testFloatIsNotInf(void)
#endif #endif
} }
void testFloatIsNotPosInf2(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
TEST_ASSERT_FLOAT_IS_NOT_INF(2.0f);
#endif
}
void testFloatIsNotNegInf(void) void testFloatIsNotNegInf(void)
{ {
#ifdef UNITY_EXCLUDE_FLOAT #ifdef UNITY_EXCLUDE_FLOAT
@ -2364,7 +2406,7 @@ void testFloatIsNotNegInf(void)
#endif #endif
} }
void testFloatIsNan(void) void testFloatIsNan1(void)
{ {
#ifdef UNITY_EXCLUDE_FLOAT #ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE(); TEST_IGNORE();
@ -2373,7 +2415,18 @@ void testFloatIsNan(void)
#endif #endif
} }
void testFloatIsNotNan(void) void testFloatIsNan2(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_NOT_NAN(0.0f / f_zero);
VERIFY_FAILS_END
#endif
}
void testFloatIsNotNan1(void)
{ {
#ifdef UNITY_EXCLUDE_FLOAT #ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE(); TEST_IGNORE();
@ -2384,6 +2437,15 @@ void testFloatIsNotNan(void)
#endif #endif
} }
void testFloatIsNotNan2(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
TEST_ASSERT_FLOAT_IS_NOT_NAN(234.9f);
#endif
}
void testFloatInfIsNotNan(void) void testFloatInfIsNotNan(void)
{ {
#ifdef UNITY_EXCLUDE_FLOAT #ifdef UNITY_EXCLUDE_FLOAT