diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 13337d5..1c68e91 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -26,7 +26,15 @@ class CMockConfig when Hash then options = CMockDefaultOptions.clone.merge(options) else raise "If you specify arguments, it should be a filename or a hash of options" end - options[:plugins] ||= [] + + #do some quick type verification + [:plugins, :includes, :attributes, :treat_as_void].each do |opt| + unless (options[opt].class == Array) + options[opt] = [] + puts "WARNING: :#{opt.to_s} should be an array." unless (options[:verbosity] < 1) + end + end + @options = options @options.each_key { |key| eval("def #{key}() return @options[:#{key}] end") } end diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index b2dada2..90a1dac 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -64,7 +64,7 @@ class CMockHeaderParser source.gsub!(/^[\w\s]*(enum|union|struct)[\w\s]*\{[^\}]+\}[\w\s]*;/m, '') # remove struct definitions source.gsub!(/(\W)(register|auto|static|restrict)(\W)/, '\1\3') # remove problem keywords source.gsub!(/\s*=\s*['"a-zA-Z0-9_\.]+\s*/, '') # remove default value statements from argument lists - source.gsub!(/typedef.*/, '') # remove typedef statements + source.gsub!(/^(?:.*\W)?typedef\W.*/, '') # remove typedef statements #scan for functions which return function pointers, because they are a pain source.gsub!(/([\w\s]+)\(*\(\s*\*([\w\s]+)\s*\(([\w\s,]+)\)\)\s*\(([\w\s,]+)\)\)*/) do |m| diff --git a/test/system/test_compilation/config.yml b/test/system/test_compilation/config.yml index 5e7f7c4..7726699 100644 --- a/test/system/test_compilation/config.yml +++ b/test/system/test_compilation/config.yml @@ -1,8 +1,7 @@ --- :cmock: - :plugins: - - #none - :includes: + :plugins: [] + :includes: [] :mock_path: test/system/generated/ :mock_prefix: mock_ :treat_as_void: diff --git a/test/system/test_interactions/expect_and_return_custom_types.yml b/test/system/test_interactions/expect_and_return_custom_types.yml index d52a9d9..c09ea71 100644 --- a/test/system/test_interactions/expect_and_return_custom_types.yml +++ b/test/system/test_interactions/expect_and_return_custom_types.yml @@ -3,7 +3,6 @@ :plugins: - # none :memcmp_if_unknown: false - :tab: ' ' :systest: :types: | diff --git a/test/system/test_interactions/parsing_challenges.yml b/test/system/test_interactions/parsing_challenges.yml index bef9051..07b55dd 100644 --- a/test/system/test_interactions/parsing_challenges.yml +++ b/test/system/test_interactions/parsing_challenges.yml @@ -4,6 +4,8 @@ - # no plugins :treat_as_void: - VOID_TYPE_CRAZINESS_CFG + :treat_as: + TypeDefInt: HEX8 :systest: :types: | @@ -14,8 +16,17 @@ int y; } POINT_T; typedef void VOID_TYPE_CRAZINESS_CFG; + typedef int TypeDefInt; :mockable: | + /* Make sure we ignore the following + #include "NonExistantFile.h + */ + //#include "AndIgnoreThisToo.h" + + #define SHOULD_IGNORE_NEXT_FUNC_DEF_AS_PART_OF_MACRO \ + void IgnoredFunction(NotAValidType ToMakeItFailIfWeActuallyMockedThis); + // typedef edge case; must be in mockable.h for test to compile // not ANSI C but it has been done and will break cmock if not handled typedef void VOID_TYPE_CRAZINESS_LCL; @@ -45,6 +56,8 @@ unsigned long int incredible_descriptors(register const unsigned short a); + TypeDefInt uses_typedef_like_names(TypeDefInt typedefvar); + :source: :header: | U16* exercise_return_pointers(int a); @@ -52,7 +65,8 @@ void exercise_arglist_pointers(void); char exercise_multiline_declarations(int a, unsigned int b); void exercise_double_pointers(unsigned int a); - int exercise_many_descriptors(int a); + int exercise_many_descriptors(int a); + TypeDefInt exercise_typedef_like_names(TypeDefInt a); :code: | int A, B, C; @@ -94,6 +108,11 @@ return (int)incredible_descriptors((unsigned short)a); } + TypeDefInt exercise_typedef_like_names(TypeDefInt a) + { + return uses_typedef_like_names(a); + } + :tests: :common: | void setUp(void) {} @@ -163,5 +182,23 @@ TEST_ASSERT_EQUAL(777, exercise_many_descriptors(888)); } + - :pass: TRUE + :should: 'handle words like typdef as PART of a variable or type' + :code: | + test() + { + uses_typedef_like_names_ExpectAndReturn((TypeDefInt)54, (TypeDefInt)53); + TEST_ASSERT_EQUAL(53, exercise_typedef_like_names((TypeDefInt)54)); + } + + - :pass: FALSE + :should: 'handle words like typdef as PART of a variable or type during failing tests' + :code: | + test() + { + uses_typedef_like_names_ExpectAndReturn((TypeDefInt)52, (TypeDefInt)53); + TEST_ASSERT_EQUAL(53, exercise_typedef_like_names((TypeDefInt)54)); + } + ... diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index d676fd2..4bbffda 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -131,14 +131,18 @@ class CMockHeaderParserTest < Test::Unit::TestCase should "remove typedef statements" do source = "typedef uint32 (unsigned int);\n" + - "whack me? typedef int INT;\n" + - "typedef who cares what really comes here \\\n" + # exercise multiline typedef + "whack me! typedef int INT;\n" + + "int notatypedef;\n" + + "int typedef_isnt_me;\n" + + " typedef who cares what really comes here \\\n" + # exercise multiline typedef " continuation;\n" + - "this should remain!" + "this should remain!\n" expected = [ - "whack me? this should remain!" + "int notatypedef", + "int typedef_isnt_me", + "this should remain!" ] assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})