Fix handling of string arguments.

Since 2f0a44d7ce, string arguments were being tested with
UNITY_TEST_ASSERT_EQUAL_PTR, not UNITY_TEST_ASSERT_EQUAL_STRING.
Before that change, we would call divine_ptr(arg_type) where
arg_type had the argument name stripped, i.e. "const char *".
Now we are passing it the name as well, i.e. "const char *str"
and it was not prepared to handle that.
This commit is contained in:
John Lindgren
2017-08-31 17:44:08 -04:00
parent 693c658780
commit 42dab4836d
2 changed files with 39 additions and 7 deletions
+5 -4
View File
@@ -146,16 +146,17 @@ class CMockHeaderParser
return args if (arg =~ /^\s*((\.\.\.)|(void))\s*$/) # we're done if we reach void by itself or ...
arg_array = arg.split
arg_elements = arg_array - @c_attributes # split up words and remove known attributes
args << { :type => (arg_type = arg_elements[0..-2].join(' ')),
args << { :type => arg_elements[0..-2].join(' '),
:name => arg_elements[-1]
}.merge(divine_ptr_and_const(arg))
end
return args
end
def divine_ptr(arg_type)
return false unless arg_type.include? '*'
return false if arg_type.gsub(/(const|char|\*|\s)+/,'').empty?
def divine_ptr(arg)
return false unless arg.include? '*'
# treat "const char *" and similar as a string, not a pointer
return false if /(^|\s)(const\s+)?char(\s+const)?\s*\*(?!.*\*)/ =~ arg
return true
end