* smarter stripping of typedef lines

* better error reporting when config file requires an array but didn't get one

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@151 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mvandervoord
2009-12-29 20:56:31 +00:00
parent 4a1a7bdb4d
commit ece9f0dc89
6 changed files with 58 additions and 11 deletions
+9 -1
View File
@@ -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
+1 -1
View File
@@ -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|
+2 -3
View File
@@ -1,8 +1,7 @@
---
:cmock:
:plugins:
- #none
:includes:
:plugins: []
:includes: []
:mock_path: test/system/generated/
:mock_prefix: mock_
:treat_as_void:
@@ -3,7 +3,6 @@
:plugins:
- # none
:memcmp_if_unknown: false
:tab: ' '
:systest:
:types: |
@@ -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));
}
...
+8 -4
View File
@@ -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})