1
0
mirror of https://github.com/ThrowTheSwitch/CMock synced 2025-05-20 02:19:34 -04:00

Add handling of treat_inline

- treat_externs only has effect on "extern", not "inline" anymore
- when treat_inline = :include, we remove the "inline" so that the inline functions become 'normal' functions
  - they are handled as as usual and will be mocked
- Add tests to check inline functions are not deleted when treat_inline=:include (and thus mocked)
This commit is contained in:
laurensmiers 2017-09-25 23:39:09 +02:00 committed by laurens
parent dbb2f4964c
commit 7a32429bd2
2 changed files with 52 additions and 4 deletions

@ -126,11 +126,20 @@ class CMockHeaderParser
src_lines = source.split(/\s*;\s*/).uniq
src_lines.delete_if {|line| line.strip.length == 0} # remove blank lines
src_lines.delete_if {|line| !(line =~ /[\w\s\*]+\(+\s*\*[\*\s]*[\w\s]+(?:\[[\w\s]*\]\s*)+\)+\s*\((?:[\w\s\*]*,?)*\s*\)/).nil?} #remove function pointer arrays
if (@treat_externs == :include)
src_lines.delete_if {|line| !(line =~ /(?:^|\s+)(?:inline)\s+/).nil?} # remove inline functions
else
src_lines.delete_if {|line| !(line =~ /(?:^|\s+)(?:extern|inline)\s+/).nil?} # remove inline and extern functions
unless (@treat_externs == :include)
src_lines.delete_if {|line| !(line =~ /(?:^|\s+)(?:extern)\s+/).nil?} # remove extern functions
end
if (@treat_inline == :include)
src_lines.each {
|src_line|
src_line.gsub!(/^inline/, "")
}
else
src_lines.delete_if {|line| !(line =~ /(?:^|\s+)(?:inline)\s+/).nil?} # remove inline functions
end
src_lines.delete_if {|line| line.empty? } #drop empty lines
end

@ -454,6 +454,45 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})
end
it "leave inline functions if inline to be included" do
source =
"extern uint32 foobar(unsigned int);\n" +
"uint32 extern_name_func(unsigned int);\n" +
"uint32 funcinline(unsigned int);\n" +
"inline void inlineBar(unsigned int);\n" +
"static inline void bar(unsigned int);\n"
expected =
[ "uint32 extern_name_func(unsigned int)",
"uint32 funcinline(unsigned int)",
"void inlineBar(unsigned int)",
"void bar(unsigned int)"
]
@parser.treat_inline = :include
assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})
end
it "leave inline and extern functions if inline and extern to be included" do
source =
"extern uint32 foobar(unsigned int);\n" +
"uint32 extern_name_func(unsigned int);\n" +
"uint32 funcinline(unsigned int);\n" +
"inline void inlineBar(unsigned int);\n" +
"static inline void bar(unsigned int);\n"
expected =
[ "extern uint32 foobar(unsigned int)",
"uint32 extern_name_func(unsigned int)",
"uint32 funcinline(unsigned int)",
"void inlineBar(unsigned int)",
"void bar(unsigned int)"
]
@parser.treat_externs = :include
@parser.treat_inline = :include
assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})
end
it "remove defines" do
source =