From 4a0df269940a4bafe408c51c1324954a8f0e6182 Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Sun, 27 Jun 2010 19:02:07 +0000 Subject: [PATCH] - drop cexception_include which is no longer needed - correct which define needed to be long in cmock.c - beefed up testing of unity TEST_IGNORE in relation to mocking git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@174 bf332499-1b4d-0410-844d-d2d48d5cc64c --- lib/cmock_config.rb | 1 - lib/cmock_generator_plugin_cexception.rb | 4 +- rakefile_helper.rb | 14 +- src/cmock.c | 4 +- .../test_interactions/unity_ignores.yml | 139 ++++++++++++++++++ test/unit/cmock_config_test.rb | 7 +- test/unit/cmock_config_test.yml | 2 +- .../cmock_generator_plugin_cexception_test.rb | 9 -- 8 files changed, 158 insertions(+), 22 deletions(-) create mode 100644 test/system/test_interactions/unity_ignores.yml diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index b9bf444..9332e05 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -15,7 +15,6 @@ class CMockConfig :includes => [], :attributes => ['__ramfunc', '__irq', '__fiq', 'register', 'extern'], :enforce_strict_ordering => false, - :cexception_include => nil, :unity_helper => false, :treat_as => {}, :treat_as_void => [], diff --git a/lib/cmock_generator_plugin_cexception.rb b/lib/cmock_generator_plugin_cexception.rb index b490bed..c9e7e2f 100644 --- a/lib/cmock_generator_plugin_cexception.rb +++ b/lib/cmock_generator_plugin_cexception.rb @@ -13,12 +13,10 @@ class CMockGeneratorPluginCexception @config = config @utils = utils @priority = 7 - - raise "'cexception_include' needs to be defined in config" unless @config.respond_to?(:cexception_include) end def include_files - return "#include \"#{@config.cexception_include || 'CException.h'}\"\n" + return "#include \"CException.h\"\n" end def instance_typedefs(function) diff --git a/rakefile_helper.rb b/rakefile_helper.rb index 0349059..05d35ac 100644 --- a/rakefile_helper.rb +++ b/rakefile_helper.rb @@ -256,11 +256,21 @@ module RakefileHelpers tests.each_with_index do |test, index| # compare test's intended pass/fail state with pass/fail state in actual results; # if they don't match, the system test has failed - if ((test[:pass] and (test_results[index] =~ /:PASS/).nil?) or (!test[:pass] and (test_results[index] =~ /:FAIL/).nil?)) + this_failed = case(test[:pass]) + when :ignore + (test_results[index] =~ /:IGNORE/).nil? + when true + (test_results[index] =~ /:PASS/).nil? + when false + (test_results[index] =~ /:FAIL/).nil? + end + if (this_failed) total_failures += 1 test_results[index] =~ /test#{index+1}:(.+)/ failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:#{$1}" - elsif (test[:verify_error]) and not (test_results[index] =~ /test#{index+1}:.*#{test[:verify_error]}/) + end + # some tests have additional requirements to check for (checking the actual output message) + if (test[:verify_error]) and not (test_results[index] =~ /test#{index+1}:.*#{test[:verify_error]}/) total_failures += 1 failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:should have output matching '#{test[:verify_error]}'" end diff --git a/src/cmock.c b/src/cmock.c index e827c07..b10b8c2 100644 --- a/src/cmock.c +++ b/src/cmock.c @@ -19,12 +19,12 @@ //should be big enough to index full range of CMOCK_MEM_MAX #ifndef CMOCK_MEM_INDEX_TYPE -#define CMOCK_MEM_INDEX_TYPE unsigned long +#define CMOCK_MEM_INDEX_TYPE unsigned int #endif //this is used internally during pointer arithmetic. make sure this type is the same size as the target's pointer type #ifndef CMOCK_MEM_PTR_AS_INT -#define CMOCK_MEM_PTR_AS_INT unsigned int +#define CMOCK_MEM_PTR_AS_INT unsigned long #endif //0 for no alignment, 1 for 16-bit, 2 for 32-bit, 3 for 64-bit diff --git a/test/system/test_interactions/unity_ignores.yml b/test/system/test_interactions/unity_ignores.yml new file mode 100644 index 0000000..c6f8574 --- /dev/null +++ b/test/system/test_interactions/unity_ignores.yml @@ -0,0 +1,139 @@ +--- +:cmock: + :plugins: + - # none + +:systest: + :types: | + #define UINT32 unsigned int + + :mockable: | + UINT32 foo(UINT32 a); + void bar(void); + + :source: + :header: | + UINT32 function_a(int a); + void function_b(void); + + :code: | + UINT32 function_a(int a) + { + bar(); + return foo((UINT32)a); + } + + void function_b(void) + { + bar(); + } + + :tests: + :common: | + void setUp(void) {} + void tearDown(void) {} + + :units: + - :pass: :ignore + :should: 'ignore incorrect expects after the TEST_IGNORE call' + :code: | + test() + { + TEST_IGNORE(); + bar_Expect(); + foo_ExpectAndReturn(10, 20); + TEST_ASSERT_EQUAL(40, function_a(30)); + } + + - :pass: :ignore + :should: 'ignore missing expects after the TEST_IGNORE call' + :code: | + test() + { + TEST_IGNORE(); + foo_ExpectAndReturn(10, 20); + TEST_ASSERT_EQUAL(20, function_a(10)); + } + + - :pass: :ignore + :should: 'ignore extra expects after the TEST_IGNORE call' + :code: | + test() + { + TEST_IGNORE(); + bar_Expect(); + bar_Expect(); + foo_ExpectAndReturn(10, 20); + foo_ExpectAndReturn(10, 20); + foo_ExpectAndReturn(10, 20); + TEST_ASSERT_EQUAL(20, function_a(10)); + } + + - :pass: :ignore + :should: 'ignore no expects after the TEST_IGNORE call' + :code: | + test() + { + TEST_IGNORE(); + TEST_ASSERT_EQUAL(20, function_a(10)); + } + + - :pass: :ignore + :should: 'ignore extra expects after the TEST_IGNORE call even if it happens later' + :code: | + test() + { + bar_Expect(); + foo_ExpectAndReturn(10, 20); + function_a(10); + + TEST_IGNORE(); + bar_Expect(); + foo_ExpectAndReturn(10, 20); + TEST_ASSERT_EQUAL(40, function_a(30)); + } + + - :pass: false + :should: 'still fail if there are expect problems before the TEST_IGNORE' + :code: | + test() + { + bar_Expect(); + foo_ExpectAndReturn(10, 20); + function_a(30); + + TEST_IGNORE(); + bar_Expect(); + foo_ExpectAndReturn(10, 20); + TEST_ASSERT_EQUAL(40, function_a(30)); + } + + - :pass: false + :should: 'still fail if there are missing expect problems before the TEST_IGNORE' + :code: | + test() + { + bar_Expect(); + function_a(10); + + TEST_IGNORE(); + bar_Expect(); + foo_ExpectAndReturn(10, 20); + TEST_ASSERT_EQUAL(40, function_a(30)); + } + + - :pass: :ignore + :should: 'ignore if extra expects before the TEST_IGNORE because it ignored the rest of the test that might have made calls to it' + :code: | + test() + { + bar_Expect(); + bar_Expect(); + foo_ExpectAndReturn(10, 20); + function_a(10); + + TEST_IGNORE(); + foo_ExpectAndReturn(10, 20); + TEST_ASSERT_EQUAL(40, function_a(30)); + } +... diff --git a/test/unit/cmock_config_test.rb b/test/unit/cmock_config_test.rb index bafd544..21b6f18 100644 --- a/test/unit/cmock_config_test.rb +++ b/test/unit/cmock_config_test.rb @@ -20,7 +20,7 @@ class CMockConfigTest < Test::Unit::TestCase assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes) assert_equal(CMockConfig::CMockDefaultOptions[:attributes], config.attributes) assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins) - assert_equal(CMockConfig::CMockDefaultOptions[:cexception_include], config.cexception_include) + assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs) end should "replace only options specified in a hash" do @@ -31,16 +31,15 @@ class CMockConfigTest < Test::Unit::TestCase assert_equal(test_includes, config.includes) assert_equal(test_attributes, config.attributes) assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins) - assert_equal(CMockConfig::CMockDefaultOptions[:cexception_include], config.cexception_include) + assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs) end should "replace only options specified in a yaml file" do test_plugins = [:soda, :pizza] - test_include = 'MySillyException.h' config = CMockConfig.new("#{File.expand_path(File.dirname(__FILE__))}/cmock_config_test.yml") assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path) assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes) assert_equal(test_plugins, config.plugins) - assert_equal(test_include, config.cexception_include) + assert_equal(:include, config.treat_externs) end end diff --git a/test/unit/cmock_config_test.yml b/test/unit/cmock_config_test.yml index 51ed770..bf2a843 100644 --- a/test/unit/cmock_config_test.yml +++ b/test/unit/cmock_config_test.yml @@ -2,4 +2,4 @@ :plugins: - 'soda' - 'pizza' - :cexception_include: 'MySillyException.h' \ No newline at end of file + :treat_externs: :include diff --git a/test/unit/cmock_generator_plugin_cexception_test.rb b/test/unit/cmock_generator_plugin_cexception_test.rb index eb0a298..47cf9b1 100644 --- a/test/unit/cmock_generator_plugin_cexception_test.rb +++ b/test/unit/cmock_generator_plugin_cexception_test.rb @@ -10,7 +10,6 @@ require 'cmock_generator_plugin_cexception' class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase def setup create_mocks :config, :utils - @config.stubs!(:respond_to?).returns(true) @cmock_generator_plugin_cexception = CMockGeneratorPluginCexception.new(@config, @utils) end @@ -25,14 +24,6 @@ class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase should "include the cexception library" do expected = "#include \"CException.h\"\n" - @config.expect.cexception_include.returns(nil) - returned = @cmock_generator_plugin_cexception.include_files - assert_equal(expected, returned) - end - - should "include the cexception library with a custom path if specified" do - expected = "#include \"../cexception/lib/CException.h\"\n" - @config.expect.cexception_include.returns("../cexception/lib/CException.h") returned = @cmock_generator_plugin_cexception.include_files assert_equal(expected, returned) end