Googletest export
Fix gmock_gen to use MOCK_METHOD instead of old style macros. Fix several related bugs in argument parsing and return types. - handle commas more correctly in return types - handle commas correctly in arguments - handle default values more correctly PiperOrigin-RevId: 294435093
This commit is contained in:
parent
56de7cc8b5
commit
d0930731d6
@ -610,9 +610,21 @@ class TypeConverter(object):
|
|||||||
result.append(p)
|
result.append(p)
|
||||||
|
|
||||||
template_count = 0
|
template_count = 0
|
||||||
|
brace_count = 0
|
||||||
for s in tokens:
|
for s in tokens:
|
||||||
if not first_token:
|
if not first_token:
|
||||||
first_token = s
|
first_token = s
|
||||||
|
|
||||||
|
# Check for braces before templates, as we can have unmatched '<>'
|
||||||
|
# inside default arguments.
|
||||||
|
if s.name == '{':
|
||||||
|
brace_count += 1
|
||||||
|
elif s.name == '}':
|
||||||
|
brace_count -= 1
|
||||||
|
if brace_count > 0:
|
||||||
|
type_modifiers.append(s)
|
||||||
|
continue
|
||||||
|
|
||||||
if s.name == '<':
|
if s.name == '<':
|
||||||
template_count += 1
|
template_count += 1
|
||||||
elif s.name == '>':
|
elif s.name == '>':
|
||||||
|
@ -53,10 +53,8 @@ def _RenderType(ast_type):
|
|||||||
ast_type: The AST of the type.
|
ast_type: The AST of the type.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Rendered string and a boolean to indicate whether we have multiple args
|
Rendered string of the type.
|
||||||
(which is not handled correctly).
|
|
||||||
"""
|
"""
|
||||||
has_multiarg_error = False
|
|
||||||
# Add modifiers like 'const'.
|
# Add modifiers like 'const'.
|
||||||
modifiers = ''
|
modifiers = ''
|
||||||
if ast_type.modifiers:
|
if ast_type.modifiers:
|
||||||
@ -66,82 +64,81 @@ def _RenderType(ast_type):
|
|||||||
# Collect template args.
|
# Collect template args.
|
||||||
template_args = []
|
template_args = []
|
||||||
for arg in ast_type.templated_types:
|
for arg in ast_type.templated_types:
|
||||||
rendered_arg, e = _RenderType(arg)
|
rendered_arg = _RenderType(arg)
|
||||||
if e: has_multiarg_error = True
|
|
||||||
template_args.append(rendered_arg)
|
template_args.append(rendered_arg)
|
||||||
return_type += '<' + ', '.join(template_args) + '>'
|
return_type += '<' + ', '.join(template_args) + '>'
|
||||||
# We are actually not handling multi-template-args correctly. So mark it.
|
|
||||||
if len(template_args) > 1:
|
|
||||||
has_multiarg_error = True
|
|
||||||
if ast_type.pointer:
|
if ast_type.pointer:
|
||||||
return_type += '*'
|
return_type += '*'
|
||||||
if ast_type.reference:
|
if ast_type.reference:
|
||||||
return_type += '&'
|
return_type += '&'
|
||||||
return return_type, has_multiarg_error
|
return return_type
|
||||||
|
|
||||||
|
|
||||||
def _GetNumParameters(parameters, source):
|
def _GenerateArg(source):
|
||||||
num_parameters = len(parameters)
|
"""Strips out comments, default arguments, and redundant spaces from a single argument.
|
||||||
if num_parameters == 1:
|
|
||||||
first_param = parameters[0]
|
Args:
|
||||||
if source[first_param.start:first_param.end].strip() == 'void':
|
source: A string for a single argument.
|
||||||
# We must treat T(void) as a function with no parameters.
|
|
||||||
return 0
|
Returns:
|
||||||
return num_parameters
|
Rendered string of the argument.
|
||||||
|
"""
|
||||||
|
# Remove end of line comments before eliminating newlines.
|
||||||
|
arg = re.sub(r'//.*', '', source)
|
||||||
|
|
||||||
|
# Remove c-style comments.
|
||||||
|
arg = re.sub(r'/\*.*\*/', '', arg)
|
||||||
|
|
||||||
|
# Remove default arguments.
|
||||||
|
arg = re.sub(r'=.*', '', arg)
|
||||||
|
|
||||||
|
# Collapse spaces and newlines into a single space.
|
||||||
|
arg = re.sub(r'\s+', ' ', arg)
|
||||||
|
return arg.strip()
|
||||||
|
|
||||||
|
|
||||||
|
def _EscapeForMacro(s):
|
||||||
|
"""Escapes a string for use as an argument to a C++ macro."""
|
||||||
|
paren_count = 0
|
||||||
|
for c in s:
|
||||||
|
if c == '(':
|
||||||
|
paren_count += 1
|
||||||
|
elif c == ')':
|
||||||
|
paren_count -= 1
|
||||||
|
elif c == ',' and paren_count == 0:
|
||||||
|
return '(' + s + ')'
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
def _GenerateMethods(output_lines, source, class_node):
|
def _GenerateMethods(output_lines, source, class_node):
|
||||||
function_type = (ast.FUNCTION_VIRTUAL | ast.FUNCTION_PURE_VIRTUAL |
|
function_type = (
|
||||||
ast.FUNCTION_OVERRIDE)
|
ast.FUNCTION_VIRTUAL | ast.FUNCTION_PURE_VIRTUAL | ast.FUNCTION_OVERRIDE)
|
||||||
ctor_or_dtor = ast.FUNCTION_CTOR | ast.FUNCTION_DTOR
|
ctor_or_dtor = ast.FUNCTION_CTOR | ast.FUNCTION_DTOR
|
||||||
indent = ' ' * _INDENT
|
indent = ' ' * _INDENT
|
||||||
|
|
||||||
for node in class_node.body:
|
for node in class_node.body:
|
||||||
# We only care about virtual functions.
|
# We only care about virtual functions.
|
||||||
if (isinstance(node, ast.Function) and
|
if (isinstance(node, ast.Function) and node.modifiers & function_type and
|
||||||
node.modifiers & function_type and
|
|
||||||
not node.modifiers & ctor_or_dtor):
|
not node.modifiers & ctor_or_dtor):
|
||||||
# Pick out all the elements we need from the original function.
|
# Pick out all the elements we need from the original function.
|
||||||
const = ''
|
modifiers = 'override'
|
||||||
if node.modifiers & ast.FUNCTION_CONST:
|
if node.modifiers & ast.FUNCTION_CONST:
|
||||||
const = 'CONST_'
|
modifiers = 'const, ' + modifiers
|
||||||
num_parameters = _GetNumParameters(node.parameters, source)
|
|
||||||
return_type = 'void'
|
return_type = 'void'
|
||||||
if node.return_type:
|
if node.return_type:
|
||||||
return_type, has_multiarg_error = _RenderType(node.return_type)
|
return_type = _EscapeForMacro(_RenderType(node.return_type))
|
||||||
if has_multiarg_error:
|
|
||||||
for line in [
|
|
||||||
'// The following line won\'t really compile, as the return',
|
|
||||||
'// type has multiple template arguments. To fix it, use a',
|
|
||||||
'// typedef for the return type.']:
|
|
||||||
output_lines.append(indent + line)
|
|
||||||
tmpl = ''
|
|
||||||
if class_node.templated_types:
|
|
||||||
tmpl = '_T'
|
|
||||||
mock_method_macro = 'MOCK_%sMETHOD%d%s' % (const, num_parameters, tmpl)
|
|
||||||
|
|
||||||
args = ''
|
args = []
|
||||||
if node.parameters:
|
for p in node.parameters:
|
||||||
# Get the full text of the parameters from the start
|
arg = _GenerateArg(source[p.start:p.end])
|
||||||
# of the first parameter to the end of the last parameter.
|
args.append(_EscapeForMacro(arg))
|
||||||
start = node.parameters[0].start
|
|
||||||
end = node.parameters[-1].end
|
|
||||||
# Remove // comments.
|
|
||||||
args_strings = re.sub(r'//.*', '', source[start:end])
|
|
||||||
# Remove /* comments */.
|
|
||||||
args_strings = re.sub(r'/\*.*\*/', '', args_strings)
|
|
||||||
# Remove default arguments.
|
|
||||||
args_strings = re.sub(r'=.*,', ',', args_strings)
|
|
||||||
args_strings = re.sub(r'=.*', '', args_strings)
|
|
||||||
# Condense multiple spaces and eliminate newlines putting the
|
|
||||||
# parameters together on a single line. Ensure there is a
|
|
||||||
# space in an argument which is split by a newline without
|
|
||||||
# intervening whitespace, e.g.: int\nBar
|
|
||||||
args = re.sub(' +', ' ', args_strings.replace('\n', ' '))
|
|
||||||
|
|
||||||
# Create the mock method definition.
|
# Create the mock method definition.
|
||||||
output_lines.extend(['%s%s(%s,' % (indent, mock_method_macro, node.name),
|
output_lines.extend([
|
||||||
'%s%s(%s));' % (indent * 3, return_type, args)])
|
'%sMOCK_METHOD(%s, %s, (%s), (%s));' %
|
||||||
|
(indent, return_type, node.name, ', '.join(args), modifiers)
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
def _GenerateMocks(filename, source, ast_list, desired_class_names):
|
def _GenerateMocks(filename, source, ast_list, desired_class_names):
|
||||||
|
@ -61,7 +61,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD0(Bar,\nint());',
|
'MOCK_METHOD(int, Bar, (), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testSimpleConstructorsAndDestructor(self):
|
def testSimpleConstructorsAndDestructor(self):
|
||||||
@ -78,7 +78,7 @@ class Foo {
|
|||||||
"""
|
"""
|
||||||
# The constructors and destructor should be ignored.
|
# The constructors and destructor should be ignored.
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD0(Bar,\nint());',
|
'MOCK_METHOD(int, Bar, (), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testVirtualDestructor(self):
|
def testVirtualDestructor(self):
|
||||||
@ -91,7 +91,7 @@ class Foo {
|
|||||||
"""
|
"""
|
||||||
# The destructor should be ignored.
|
# The destructor should be ignored.
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD0(Bar,\nint());',
|
'MOCK_METHOD(int, Bar, (), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testExplicitlyDefaultedConstructorsAndDestructor(self):
|
def testExplicitlyDefaultedConstructorsAndDestructor(self):
|
||||||
@ -107,7 +107,7 @@ class Foo {
|
|||||||
"""
|
"""
|
||||||
# The constructors and destructor should be ignored.
|
# The constructors and destructor should be ignored.
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD0(Bar,\nint());',
|
'MOCK_METHOD(int, Bar, (), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testExplicitlyDeletedConstructorsAndDestructor(self):
|
def testExplicitlyDeletedConstructorsAndDestructor(self):
|
||||||
@ -123,7 +123,7 @@ class Foo {
|
|||||||
"""
|
"""
|
||||||
# The constructors and destructor should be ignored.
|
# The constructors and destructor should be ignored.
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD0(Bar,\nint());',
|
'MOCK_METHOD(int, Bar, (), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testSimpleOverrideMethod(self):
|
def testSimpleOverrideMethod(self):
|
||||||
@ -134,7 +134,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD0(Bar,\nint());',
|
'MOCK_METHOD(int, Bar, (), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testSimpleConstMethod(self):
|
def testSimpleConstMethod(self):
|
||||||
@ -145,7 +145,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_CONST_METHOD1(Bar,\nvoid(bool flag));',
|
'MOCK_METHOD(void, Bar, (bool flag), (const, override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testExplicitVoid(self):
|
def testExplicitVoid(self):
|
||||||
@ -156,7 +156,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD0(Bar,\nint(void));',
|
'MOCK_METHOD(int, Bar, (void), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testStrangeNewlineInParameter(self):
|
def testStrangeNewlineInParameter(self):
|
||||||
@ -168,7 +168,7 @@ a) = 0;
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD1(Bar,\nvoid(int a));',
|
'MOCK_METHOD(void, Bar, (int a), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testDefaultParameters(self):
|
def testDefaultParameters(self):
|
||||||
@ -179,7 +179,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD2(Bar,\nvoid(int a, char c ));',
|
'MOCK_METHOD(void, Bar, (int a, char c), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testMultipleDefaultParameters(self):
|
def testMultipleDefaultParameters(self):
|
||||||
@ -196,8 +196,19 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
"MOCK_METHOD7(Bar,\n"
|
'MOCK_METHOD(void, Bar, '
|
||||||
"void(int a , char c , const int* const p , const std::string& s , char tab[] , int const *& rp ));",
|
'(int a, char c, const int* const p, const std::string& s, char tab[], int const *& rp), '
|
||||||
|
'(override));', self.GenerateMethodSource(source))
|
||||||
|
|
||||||
|
def testMultipleSingleLineDefaultParameters(self):
|
||||||
|
source = """
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
virtual void Bar(int a = 42, int b = 43, int c = 44) = 0;
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
|
'MOCK_METHOD(void, Bar, (int a, int b, int c), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testConstDefaultParameter(self):
|
def testConstDefaultParameter(self):
|
||||||
@ -207,9 +218,9 @@ class Test {
|
|||||||
virtual bool Bar(const int test_arg = 42) = 0;
|
virtual bool Bar(const int test_arg = 42) = 0;
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
expected = 'MOCK_METHOD1(Bar,\nbool(const int test_arg ));'
|
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
expected, self.GenerateMethodSource(source))
|
'MOCK_METHOD(bool, Bar, (const int test_arg), (override));',
|
||||||
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testConstRefDefaultParameter(self):
|
def testConstRefDefaultParameter(self):
|
||||||
source = """
|
source = """
|
||||||
@ -218,9 +229,9 @@ class Test {
|
|||||||
virtual bool Bar(const std::string& test_arg = "42" ) = 0;
|
virtual bool Bar(const std::string& test_arg = "42" ) = 0;
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
expected = 'MOCK_METHOD1(Bar,\nbool(const std::string& test_arg ));'
|
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
expected, self.GenerateMethodSource(source))
|
'MOCK_METHOD(bool, Bar, (const std::string& test_arg), (override));',
|
||||||
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testRemovesCommentsWhenDefaultsArePresent(self):
|
def testRemovesCommentsWhenDefaultsArePresent(self):
|
||||||
source = """
|
source = """
|
||||||
@ -231,7 +242,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD2(Bar,\nvoid(int a , char c));',
|
'MOCK_METHOD(void, Bar, (int a, char c), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testDoubleSlashCommentsInParameterListAreRemoved(self):
|
def testDoubleSlashCommentsInParameterListAreRemoved(self):
|
||||||
@ -244,7 +255,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_CONST_METHOD2(Bar,\nvoid(int a, int b));',
|
'MOCK_METHOD(void, Bar, (int a, int b), (const, override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testCStyleCommentsInParameterListAreNotRemoved(self):
|
def testCStyleCommentsInParameterListAreNotRemoved(self):
|
||||||
@ -258,7 +269,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD2(Bar,\nconst string&(int , int b));',
|
'MOCK_METHOD(const string&, Bar, (int, int b), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testArgsOfTemplateTypes(self):
|
def testArgsOfTemplateTypes(self):
|
||||||
@ -268,8 +279,7 @@ class Foo {
|
|||||||
virtual int Bar(const vector<int>& v, map<int, string>* output);
|
virtual int Bar(const vector<int>& v, map<int, string>* output);
|
||||||
};"""
|
};"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD2(Bar,\n'
|
'MOCK_METHOD(int, Bar, (const vector<int>& v, (map<int, string>* output)), (override));',
|
||||||
'int(const vector<int>& v, map<int, string>* output));',
|
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testReturnTypeWithOneTemplateArg(self):
|
def testReturnTypeWithOneTemplateArg(self):
|
||||||
@ -279,7 +289,7 @@ class Foo {
|
|||||||
virtual vector<int>* Bar(int n);
|
virtual vector<int>* Bar(int n);
|
||||||
};"""
|
};"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD1(Bar,\nvector<int>*(int n));',
|
'MOCK_METHOD(vector<int>*, Bar, (int n), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testReturnTypeWithManyTemplateArgs(self):
|
def testReturnTypeWithManyTemplateArgs(self):
|
||||||
@ -288,13 +298,8 @@ class Foo {
|
|||||||
public:
|
public:
|
||||||
virtual map<int, string> Bar();
|
virtual map<int, string> Bar();
|
||||||
};"""
|
};"""
|
||||||
# Comparing the comment text is brittle - we'll think of something
|
|
||||||
# better in case this gets annoying, but for now let's keep it simple.
|
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'// The following line won\'t really compile, as the return\n'
|
'MOCK_METHOD((map<int, string>), Bar, (), (override));',
|
||||||
'// type has multiple template arguments. To fix it, use a\n'
|
|
||||||
'// typedef for the return type.\n'
|
|
||||||
'MOCK_METHOD0(Bar,\nmap<int, string>());',
|
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testSimpleMethodInTemplatedClass(self):
|
def testSimpleMethodInTemplatedClass(self):
|
||||||
@ -306,7 +311,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD0_T(Bar,\nint());',
|
'MOCK_METHOD(int, Bar, (), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testPointerArgWithoutNames(self):
|
def testPointerArgWithoutNames(self):
|
||||||
@ -316,7 +321,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD1(Bar,\nint(C*));',
|
'MOCK_METHOD(int, Bar, (C*), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testReferenceArgWithoutNames(self):
|
def testReferenceArgWithoutNames(self):
|
||||||
@ -326,7 +331,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD1(Bar,\nint(C&));',
|
'MOCK_METHOD(int, Bar, (C&), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testArrayArgWithoutNames(self):
|
def testArrayArgWithoutNames(self):
|
||||||
@ -336,7 +341,7 @@ class Foo {
|
|||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
'MOCK_METHOD1(Bar,\nint(C[]));',
|
'MOCK_METHOD(int, Bar, (C[]), (override));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
|
|
||||||
@ -372,15 +377,14 @@ namespace Baz {
|
|||||||
|
|
||||||
class MockTest : public Test {
|
class MockTest : public Test {
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD0(Foo,
|
MOCK_METHOD(void, Foo, (), (override));
|
||||||
void());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Baz
|
} // namespace Baz
|
||||||
} // namespace Foo
|
} // namespace Foo
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(expected,
|
||||||
expected, self.GenerateMocks(source))
|
self.GenerateMocks(source))
|
||||||
|
|
||||||
def testClassWithStorageSpecifierMacro(self):
|
def testClassWithStorageSpecifierMacro(self):
|
||||||
source = """
|
source = """
|
||||||
@ -392,12 +396,11 @@ class STORAGE_SPECIFIER Test {
|
|||||||
expected = """\
|
expected = """\
|
||||||
class MockTest : public Test {
|
class MockTest : public Test {
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD0(Foo,
|
MOCK_METHOD(void, Foo, (), (override));
|
||||||
void());
|
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(expected,
|
||||||
expected, self.GenerateMocks(source))
|
self.GenerateMocks(source))
|
||||||
|
|
||||||
def testTemplatedForwardDeclaration(self):
|
def testTemplatedForwardDeclaration(self):
|
||||||
source = """
|
source = """
|
||||||
@ -410,12 +413,11 @@ class Test {
|
|||||||
expected = """\
|
expected = """\
|
||||||
class MockTest : public Test {
|
class MockTest : public Test {
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD0(Foo,
|
MOCK_METHOD(void, Foo, (), (override));
|
||||||
void());
|
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(expected,
|
||||||
expected, self.GenerateMocks(source))
|
self.GenerateMocks(source))
|
||||||
|
|
||||||
def testTemplatedClass(self):
|
def testTemplatedClass(self):
|
||||||
source = """
|
source = """
|
||||||
@ -429,12 +431,11 @@ class Test {
|
|||||||
template <typename T0, typename T1>
|
template <typename T0, typename T1>
|
||||||
class MockTest : public Test<T0, T1> {
|
class MockTest : public Test<T0, T1> {
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD0_T(Foo,
|
MOCK_METHOD(void, Foo, (), (override));
|
||||||
void());
|
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(expected,
|
||||||
expected, self.GenerateMocks(source))
|
self.GenerateMocks(source))
|
||||||
|
|
||||||
def testTemplateInATemplateTypedef(self):
|
def testTemplateInATemplateTypedef(self):
|
||||||
source = """
|
source = """
|
||||||
@ -447,12 +448,11 @@ class Test {
|
|||||||
expected = """\
|
expected = """\
|
||||||
class MockTest : public Test {
|
class MockTest : public Test {
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD1(Bar,
|
MOCK_METHOD(void, Bar, (const FooType& test_arg), (override));
|
||||||
void(const FooType& test_arg));
|
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(expected,
|
||||||
expected, self.GenerateMocks(source))
|
self.GenerateMocks(source))
|
||||||
|
|
||||||
def testTemplateInATemplateTypedefWithComma(self):
|
def testTemplateInATemplateTypedefWithComma(self):
|
||||||
source = """
|
source = """
|
||||||
@ -466,12 +466,27 @@ class Test {
|
|||||||
expected = """\
|
expected = """\
|
||||||
class MockTest : public Test {
|
class MockTest : public Test {
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD1(Bar,
|
MOCK_METHOD(void, Bar, (const FooType& test_arg), (override));
|
||||||
void(const FooType& test_arg));
|
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(expected,
|
||||||
expected, self.GenerateMocks(source))
|
self.GenerateMocks(source))
|
||||||
|
|
||||||
|
def testParenthesizedCommaInArg(self):
|
||||||
|
source = """
|
||||||
|
class Test {
|
||||||
|
public:
|
||||||
|
virtual void Bar(std::function<void(int, int)> f);
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
expected = """\
|
||||||
|
class MockTest : public Test {
|
||||||
|
public:
|
||||||
|
MOCK_METHOD(void, Bar, (std::function<void(int, int)> f), (override));
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
self.assertEqualIgnoreLeadingWhitespace(expected,
|
||||||
|
self.GenerateMocks(source))
|
||||||
|
|
||||||
def testEnumType(self):
|
def testEnumType(self):
|
||||||
source = """
|
source = """
|
||||||
@ -486,12 +501,11 @@ class Test {
|
|||||||
expected = """\
|
expected = """\
|
||||||
class MockTest : public Test {
|
class MockTest : public Test {
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD0(Foo,
|
MOCK_METHOD(void, Foo, (), (override));
|
||||||
void());
|
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(expected,
|
||||||
expected, self.GenerateMocks(source))
|
self.GenerateMocks(source))
|
||||||
|
|
||||||
def testEnumClassType(self):
|
def testEnumClassType(self):
|
||||||
source = """
|
source = """
|
||||||
@ -506,12 +520,11 @@ class Test {
|
|||||||
expected = """\
|
expected = """\
|
||||||
class MockTest : public Test {
|
class MockTest : public Test {
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD0(Foo,
|
MOCK_METHOD(void, Foo, (), (override));
|
||||||
void());
|
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(expected,
|
||||||
expected, self.GenerateMocks(source))
|
self.GenerateMocks(source))
|
||||||
|
|
||||||
def testStdFunction(self):
|
def testStdFunction(self):
|
||||||
source = """
|
source = """
|
||||||
@ -528,12 +541,11 @@ class Test {
|
|||||||
expected = """\
|
expected = """\
|
||||||
class MockTest : public Test {
|
class MockTest : public Test {
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD0(foo,
|
MOCK_METHOD(std::function<int (std::string)>, foo, (), (override));
|
||||||
std::function<int (std::string)>());
|
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
self.assertEqualIgnoreLeadingWhitespace(
|
self.assertEqualIgnoreLeadingWhitespace(expected,
|
||||||
expected, self.GenerateMocks(source))
|
self.GenerateMocks(source))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user