diff --git a/rakefile.rb b/rakefile.rb index f86dea5..bdb4931 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -2,7 +2,7 @@ # Unity Project - A Test Framework for C # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # [Released under MIT License. Please refer to license.txt for details] -# ========================================== +# ========================================== UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/' @@ -33,9 +33,11 @@ task :unit => [:prepare_for_tests] do run_tests get_unit_test_files end -Rake::TestTask.new(:scripts) do |t| - t.pattern = 'test/test_*.rb' - t.verbose = true +desc "Test unity's helper scripts" +task :scripts => [:prepare_for_tests] do + Dir['test/test_*.rb'].each do |scriptfile| + require "./"+scriptfile + end end desc "Generate test summary" diff --git a/rakefile_helper.rb b/rakefile_helper.rb index 8ef0d5b..0b25233 100644 --- a/rakefile_helper.rb +++ b/rakefile_helper.rb @@ -2,7 +2,7 @@ # Unity Project - A Test Framework for C # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # [Released under MIT License. Please refer to license.txt for details] -# ========================================== +# ========================================== require 'yaml' require 'fileutils' @@ -13,7 +13,7 @@ require UNITY_ROOT + 'auto/colour_reporter' module RakefileHelpers C_EXTENSION = '.c' - + def load_configuration(config_file) unless ($configured) $cfg_file = "targets/#{config_file}" unless (config_file =~ /[\\|\/]/) @@ -22,24 +22,24 @@ module RakefileHelpers $configured = true if (config_file != DEFAULT_CONFIG_FILE) end end - + def configure_clean CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil? end - + def configure_toolchain(config_file=DEFAULT_CONFIG_FILE) config_file += '.yml' unless config_file =~ /\.yml$/ config_file = config_file unless config_file =~ /[\\|\/]/ load_configuration(config_file) configure_clean end - + def get_unit_test_files path = $cfg['compiler']['unit_tests_path'] + 'test*' + C_EXTENSION path.gsub!(/\\/, '/') FileList.new(path) end - + def get_local_include_dirs include_dirs = $cfg['compiler']['includes']['items'].dup include_dirs.delete_if {|dir| dir.is_a?(Array)} @@ -67,7 +67,7 @@ module RakefileHelpers end return nil end - + def tackit(strings) if strings.is_a?(Array) result = "\"#{strings.join}\"" @@ -76,13 +76,22 @@ module RakefileHelpers end return result end - + def squash(prefix, items) result = '' items.each { |item| result += " #{prefix}#{tackit(item)}" } return result end + def should(behave, &block) + if block + puts "Should " + behave + yield block + else + puts "UNIMPLEMENTED CASE: Should #{behave}" + end + end + def build_compiler_fields command = tackit($cfg['compiler']['path']) if $cfg['compiler']['defines']['items'].nil? @@ -104,7 +113,7 @@ module RakefileHelpers execute(cmd_str + obj_file) return obj_file end - + def build_linker_fields command = tackit($cfg['linker']['path']) if $cfg['linker']['options'].nil? @@ -120,7 +129,7 @@ module RakefileHelpers includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) return {:command => command, :options => options, :includes => includes} end - + def link_it(exe_name, obj_list) linker = build_linker_fields cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " + @@ -130,7 +139,7 @@ module RakefileHelpers exe_name + $cfg['linker']['bin_files']['extension'] execute(cmd_str) end - + def build_simulator_fields return nil if $cfg['simulator'].nil? if $cfg['simulator']['path'].nil? @@ -150,7 +159,7 @@ module RakefileHelpers end return {:command => command, :pre_support => pre_support, :post_support => post_support} end - + def execute(command_string, verbose=true) report command_string output = `#{command_string}`.chomp @@ -160,32 +169,32 @@ module RakefileHelpers end return output end - + def report_summary summary = UnityTestSummary.new - summary.set_root_path(UNITY_ROOT ) + summary.set_root_path(UNITY_ROOT ) results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob.gsub!(/\\/, '/') results = Dir[results_glob] summary.set_targets(results) summary.run end - + def run_tests(test_files) report 'Running Unity system tests...' - + # Tack on TEST define for compiling unit tests load_configuration($cfg_file) test_defines = ['TEST'] $cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil? $cfg['compiler']['defines']['items'] << 'TEST' - + include_dirs = get_local_include_dirs - + # Build and execute each unit test test_files.each do |test| obj_list = [] - + # Detect dependencies and build required modules extract_headers(test).each do |header| # Compile corresponding source file if it exists @@ -194,30 +203,30 @@ module RakefileHelpers obj_list << compile(src_file, test_defines) end end - + # Build the test runner (generate if configured to do so) test_base = File.basename(test, C_EXTENSION) - + runner_name = test_base + '_Runner.c' runner_path = '' - + if $cfg['compiler']['runner_path'].nil? runner_path = $cfg['compiler']['build_path'] + runner_name else runner_path = $cfg['compiler']['runner_path'] + runner_name end - + options = $cfg[:unity] options[:use_param_tests] = (test =~ /parameterized/) ? true : false UnityTestRunnerGenerator.new(options).run(test, runner_path) obj_list << compile(runner_path, test_defines) - + # Build the test module obj_list << compile(test, test_defines) - + # Link the test executable link_it(test_base, obj_list) - + # Execute unit test and generate results file simulator = build_simulator_fields executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension'] @@ -234,7 +243,7 @@ module RakefileHelpers test_results += '.testpass' end File.open(test_results, 'w') { |f| f.print output } - + end end end diff --git a/src/unity.c b/src/unity.c index 919dafa..b0e409a 100644 --- a/src/unity.c +++ b/src/unity.c @@ -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* UnityStrNullPointerForExpected= " Expected pointer to be NULL"; const char* UnityStrNullPointerForActual = " Actual pointer was NULL"; +const char* UnityStrNot = "Not "; const char* UnityStrInf = "Infinity"; const char* UnityStrNegInf = "Negative Infinity"; const char* UnityStrNaN = "NaN"; @@ -614,6 +615,7 @@ void UnityAssertFloatsWithin(const _UF delta, //----------------------------------------------- void UnityAssertFloatIsInf(const _UF actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber) { @@ -624,16 +626,21 @@ void UnityAssertFloatIsInf(const _UF actual, // produces // error C2124: divide or mod by zero // 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); -#ifdef UNITY_FLOAT_VERBOSE UnityPrint(UnityStrExpected); + if (!should_be) + UnityPrint(UnityStrNot); UnityPrint(UnityStrInf); UnityPrint(UnityStrWas); +#ifdef UNITY_FLOAT_VERBOSE UnityPrintFloat(actual); #else - UnityPrint(UnityStrDelta); + if (should_be) + UnityPrint(UnityStrNot); + UnityPrint(UnityStrInf); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; @@ -642,22 +649,28 @@ void UnityAssertFloatIsInf(const _UF actual, //----------------------------------------------- void UnityAssertFloatIsNegInf(const _UF actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber) { UNITY_SKIP_EXECUTION; // 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); -#ifdef UNITY_FLOAT_VERBOSE UnityPrint(UnityStrExpected); + if (!should_be) + UnityPrint(UnityStrNot); UnityPrint(UnityStrNegInf); UnityPrint(UnityStrWas); +#ifdef UNITY_FLOAT_VERBOSE UnityPrintFloat(actual); #else - UnityPrint(UnityStrDelta); + if (should_be) + UnityPrint(UnityStrNot); + UnityPrint(UnityStrNegInf); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; @@ -666,21 +679,30 @@ void UnityAssertFloatIsNegInf(const _UF actual, //----------------------------------------------- void UnityAssertFloatIsNaN(const _UF actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber) { 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); -#ifdef UNITY_FLOAT_VERBOSE UnityPrint(UnityStrExpected); + if (!should_be) + UnityPrint(UnityStrNot); UnityPrint(UnityStrNaN); UnityPrint(UnityStrWas); +#ifdef UNITY_FLOAT_VERBOSE UnityPrintFloat(actual); #else - UnityPrint(UnityStrDelta); + if (should_be) + UnityPrint(UnityStrNot); + UnityPrint(UnityStrNaN); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; @@ -786,6 +808,7 @@ void UnityAssertDoublesWithin(const _UD delta, //----------------------------------------------- void UnityAssertDoubleIsInf(const _UD actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber) { @@ -810,6 +833,7 @@ void UnityAssertDoubleIsInf(const _UD actual, //----------------------------------------------- void UnityAssertDoubleIsNegInf(const _UD actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber) { @@ -834,6 +858,7 @@ void UnityAssertDoubleIsNegInf(const _UD actual, //----------------------------------------------- void UnityAssertDoubleIsNaN(const _UD actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber) { @@ -1093,8 +1118,8 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) //----------------------------------------------- #ifdef UNITY_SUPPORT_WEAK -void setUp(void) { } -void tearDown(void) { } +UNITY_WEAK void setUp(void) { } +UNITY_WEAK void tearDown(void) { } #else void setUp(void); void tearDown(void); diff --git a/src/unity.h b/src/unity.h index d48b5a2..b7b7c82 100644 --- a/src/unity.h +++ b/src/unity.h @@ -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_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_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) #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_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_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) @@ -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_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_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) #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_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_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 diff --git a/src/unity_internals.h b/src/unity_internals.h index 18a8777..7224ce8 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -274,7 +274,7 @@ extern int UNITY_OUTPUT_CHAR(int); #ifndef UNITY_WEAK #ifdef UNITY_SUPPORT_WEAK -#define UNITY_WEAK __attribute__((weak)) +#define UNITY_WEAK UNITY_SUPPORT_WEAK #else #define UNITY_WEAK #endif @@ -438,14 +438,17 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected, const UNITY_LINE_TYPE lineNumber); void UnityAssertFloatIsInf(const _UF actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertFloatIsNegInf(const _UF actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertFloatIsNaN(const _UF actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber); #endif @@ -464,14 +467,17 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected, const UNITY_LINE_TYPE lineNumber); void UnityAssertDoubleIsInf(const _UD actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertDoubleIsNegInf(const _UD actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertDoubleIsNaN(const _UD actual, + const _U_SINT should_be, const char* msg, const UNITY_LINE_TYPE lineNumber); #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_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_FLOAT_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (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_NAN(actual, line, message) UnityAssertFloatIsNaN((_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), 1, (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 #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_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_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleIsInf((_UD)(actual), (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_NAN(actual, line, message) UnityAssertDoubleIsNaN((_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), 1, (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 diff --git a/test/test_generate_test_runner.rb b/test/test_generate_test_runner.rb index 953552f..8e0ace2 100644 --- a/test/test_generate_test_runner.rb +++ b/test/test_generate_test_runner.rb @@ -2,14 +2,8 @@ # CMock Project - Automatic Mock Generation for C # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # [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' TEST_FILE = 'test/testdata/testsample.c' @@ -17,78 +11,78 @@ TEST_MOCK = 'test/testdata/mocksample.c' OUT_FILE = 'build/testsample_' EXP_FILE = 'test/expectdata/testsample_' -class TestGenerateTestRunner < Test::Unit::TestCase - def setup - end +$generate_test_runner_failures = 0 - 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 - - 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 + +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) diff --git a/test/testunity.c b/test/testunity.c index 46bafd6..494b2d8 100755 --- a/test/testunity.c +++ b/test/testunity.c @@ -9,7 +9,10 @@ // Dividing by these constants produces +/- infinity. // The rationale is given in UnityAssertFloatIsInf's body. +#ifndef UNITY_EXCLUDE_FLOAT static const _UF f_zero = 0.0f; +#endif + #ifndef UNITY_EXCLUDE_DOUBLE static const _UD d_zero = 0.0; #endif @@ -2332,17 +2335,47 @@ void testFloatsNotEqualPlusMinusInf(void) #endif } -void testFloatIsInf(void) +void testFloatIsPosInf1(void) { #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else 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); #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 TEST_IGNORE(); @@ -2353,6 +2386,15 @@ void testFloatIsNotInf(void) #endif } +void testFloatIsNotPosInf2(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + TEST_ASSERT_FLOAT_IS_NOT_INF(2.0f); +#endif +} + void testFloatIsNotNegInf(void) { #ifdef UNITY_EXCLUDE_FLOAT @@ -2364,7 +2406,7 @@ void testFloatIsNotNegInf(void) #endif } -void testFloatIsNan(void) +void testFloatIsNan1(void) { #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); @@ -2373,7 +2415,18 @@ void testFloatIsNan(void) #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 TEST_IGNORE(); @@ -2384,6 +2437,15 @@ void testFloatIsNotNan(void) #endif } +void testFloatIsNotNan2(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + TEST_ASSERT_FLOAT_IS_NOT_NAN(234.9f); +#endif +} + void testFloatInfIsNotNan(void) { #ifdef UNITY_EXCLUDE_FLOAT