From c081525fbc736f58106f75b28a25366fc86b759c Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Wed, 15 Apr 2009 12:04:37 +0000 Subject: [PATCH] - updated header parser to pull in variable attribute list from configuration git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@76 bf332499-1b4d-0410-844d-d2d48d5cc64c --- lib/cmock.rb | 2 +- lib/cmock_config.rb | 3 +- lib/cmock_header_parser.rb | 8 +++--- test/unit/cmock_config_test.rb | 5 +++- test/unit/cmock_header_parser_test.rb | 40 ++++++++++++++------------- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/lib/cmock.rb b/lib/cmock.rb index d2628d9..f4b829d 100644 --- a/lib/cmock.rb +++ b/lib/cmock.rb @@ -26,7 +26,7 @@ class CMock path = File.dirname(src) @cfg.set_path(path) - cm_parser = CMockHeaderParser.new(File.read(src)) + cm_parser = CMockHeaderParser.new(File.read(src), @cfg) cm_unityhelper = CMockUnityHelperParser.new(@cfg) cm_writer = CMockFileWriter.new(@cfg) cm_gen_utils = CMockGeneratorUtils.new(@cfg, {:unity_helper => cm_unityhelper}) diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index f48a68d..7e9e8ef 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -5,8 +5,9 @@ class CMockConfig { :mock_path => 'mocks', :mock_prefix => 'Mock', - :includes => [], :plugins => ['cexception', 'ignore'], + :includes => [], + :attributes => ['static', 'inline', '__ramfunc', '__irq', '__fiq'], :tab => ' ', :expect_call_count_type => 'unsigned short', :enforce_strict_ordering => false, diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 5405119..53b400b 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -2,12 +2,12 @@ class CMockHeaderParser attr_accessor :match_type, :attribute_match, :src_lines, :funcs, :c_attributes, :declaration_parse_matcher, :included - def initialize(source, match_type=/[^\s]+\s*\**?/, attributes=['static', '__monitor', '__ramfunc', '__irq', '__fiq']) + def initialize(source, cfg) import_source(source) @funcs = nil - @match_type = match_type - @c_attributes = attributes - @declaration_parse_matcher = /(\w*\s+)*??(#{match_type})\s*(\w+)\s*\(([^\)]*)\)/ + @match_type = /[^\s]+\s*\**?/ + @c_attributes = cfg.attributes + @declaration_parse_matcher = /(\w*\s+)*??(#{@match_type})\s*(\w+)\s*\(([^\)]*)\)/ @included = nil end diff --git a/test/unit/cmock_config_test.rb b/test/unit/cmock_config_test.rb index e4de22f..90b853a 100644 --- a/test/unit/cmock_config_test.rb +++ b/test/unit/cmock_config_test.rb @@ -12,6 +12,7 @@ class CMockConfigTest < Test::Unit::TestCase config = CMockConfig.new assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path) 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[:tab], config.tab) assert_equal(CMockConfig::CMockDefaultOptions[:expect_call_count_type],config.expect_call_count_type) @@ -22,10 +23,12 @@ class CMockConfigTest < Test::Unit::TestCase should "replace only options specified in a hash" do test_includes = ['hello'] + test_attributes = ['blah', 'bleh'] test_bool_type = 'bool' - config = CMockConfig.new(:includes => test_includes, :ignore_bool_type => test_bool_type) + config = CMockConfig.new(:includes => test_includes, :ignore_bool_type => test_bool_type, :attributes => test_attributes) assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path) assert_equal(test_includes, config.includes) + assert_equal(test_attributes, config.attributes) assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins) assert_equal(CMockConfig::CMockDefaultOptions[:tab], config.tab) assert_equal(CMockConfig::CMockDefaultOptions[:expect_call_count_type], config.expect_call_count_type) diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index 3cc4582..eaf6627 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -4,17 +4,19 @@ require File.expand_path(File.dirname(__FILE__)) + "/../../lib/cmock_header_pars class CMockHeaderParserTest < Test::Unit::TestCase def setup - @parser = CMockHeaderParser.new("//some contents") + create_mocks :config + @config.expect.attributes.returns(['static','inline']) + #@parser = CMockHeaderParser.new("//some contents", @config) end def teardown end should "create and initialize variables to defaults appropriately" do - @parser = CMockHeaderParser.new("//some contents") + @parser = CMockHeaderParser.new("", @config) assert_nil(@parser.funcs) assert_equal(/[^\s]+\s*\**?/, @parser.match_type) - assert_equal(['static', '__monitor', '__ramfunc', '__irq', '__fiq'], @parser.c_attributes) + assert_equal(['static', 'inline'], @parser.c_attributes) assert_equal(/(\w*\s+)*??(#{@parser.match_type})\s*(\w+)\s*\(([^\)]*)\)/, @parser.declaration_parse_matcher) assert_nil(@parser.included) end @@ -24,7 +26,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase " abcd;\n" + "// hello;\n" + "who // is you\n" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) expected = [ @@ -43,7 +45,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase "who /* is you\n" + "whatdya say? */\n" + "/* shizzzle*/" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) expected = [ @@ -61,7 +63,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase "#when stuff_happens\n" + "#ifdef _TEST\n" + "#pragma stack_switch" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) expected = [ @@ -78,7 +80,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase should "Match ; { and } as end of line characters" do source = " i like ice cream; and i can eat { vanilla, chocolate } when I want to; so there!" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) expected = [ @@ -100,7 +102,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase source = "hoo hah \\\n" + "when \\ \n" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) expected = [ @@ -115,7 +117,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase "whack me? #typedef int INT\n" + "#typedef who cares what really comes here\n" + "this should remain!" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) expected = [ @@ -132,7 +134,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase "#DEFINE I JUST DON'T CARE\n" + "#deFINE\n" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) expected = [ @@ -155,7 +157,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase "#include \"myheader.h\"\n" + "#include \t \"os.h\"\n" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) parsed_stuff = @parser.parse expected = @@ -173,7 +175,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase "extern unsigned int NumSamples;\n" + "extern FOO_TYPE fooFun;" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) expected = [ @@ -196,7 +198,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase "void\n shiz(void);\n" + "void tat();\n" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) parsed_stuff = @parser.parse expected = @@ -250,9 +252,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase source = "static \tint \n Foo(int a, unsigned int b);\n" + - "goodness \t bool bar \n(uint la, int de, bool da);\n" + "inline \t bool bar \n(uint la, int de, bool da);\n" - @parser = CMockHeaderParser.new(source, /\w+\**/, ['static', 'goodness']) + @parser = CMockHeaderParser.new(source, @config) parsed_stuff = @parser.parse expected = @@ -267,7 +269,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase }, { - :modifier => "goodness", + :modifier => "inline", :args_string => "uint la, int de, bool da", :rettype => "bool", :var_arg => nil, @@ -290,7 +292,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase "\tint \n printf(char * const format, ...);\n" + "bool bar \n(...);\n" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) parsed_stuff = @parser.parse expected = @@ -324,7 +326,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase "bool * HotDog(BOW_WOW *p, unsigned int* pint);\n" + "static bool *HotToTrot(unsigned int * struttin);\n" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) parsed_stuff = @parser.parse expected = @@ -387,7 +389,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase "int buzzlightyear(char*, bool);\n" + "bool woody();\n" - @parser = CMockHeaderParser.new(source) + @parser = CMockHeaderParser.new(source, @config) parsed_stuff = @parser.parse expected =