Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: testing/gmock/scripts/gmock_doctor.py

Issue 140003: Upgrade gtest to r267 and gmock to r173. (Closed)
Patch Set: final fileset. Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « testing/gmock/scripts/gmock-config.in ('k') | testing/gmock/src/gmock-internal-utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python2.4 1 #!/usr/bin/python2.4
2 # 2 #
3 # Copyright 2008, Google Inc. 3 # Copyright 2008, Google Inc.
4 # All rights reserved. 4 # All rights reserved.
5 # 5 #
6 # Redistribution and use in source and binary forms, with or without 6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are 7 # modification, are permitted provided that the following conditions are
8 # met: 8 # met:
9 # 9 #
10 # * Redistributions of source code must retain the above copyright 10 # * Redistributions of source code must retain the above copyright
(...skipping 18 matching lines...) Expand all
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 31
32 """Converts gcc errors in code using Google Mock to plain English.""" 32 """Converts gcc errors in code using Google Mock to plain English."""
33 33
34 __author__ = 'wan@google.com (Zhanyong Wan)' 34 __author__ = 'wan@google.com (Zhanyong Wan)'
35 35
36 import re 36 import re
37 import sys 37 import sys
38 38
39 _VERSION = '1.0.0' 39 _VERSION = '1.0.3'
40 40
41 _COMMON_GMOCK_SYMBOLS = [ 41 _COMMON_GMOCK_SYMBOLS = [
42 # Matchers 42 # Matchers
43 '_', 43 '_',
44 'A', 44 'A',
45 'AddressSatisfies', 45 'AddressSatisfies',
46 'AllOf', 46 'AllOf',
47 'An', 47 'An',
48 'AnyOf', 48 'AnyOf',
49 'ContainerEq',
50 'Contains',
49 'ContainsRegex', 51 'ContainsRegex',
50 'DoubleEq', 52 'DoubleEq',
53 'ElementsAre',
54 'ElementsAreArray',
51 'EndsWith', 55 'EndsWith',
52 'Eq', 56 'Eq',
53 'Field', 57 'Field',
54 'FloatEq', 58 'FloatEq',
55 'Ge', 59 'Ge',
56 'Gt', 60 'Gt',
57 'HasSubstr', 61 'HasSubstr',
58 'IsInitializedProto', 62 'IsInitializedProto',
59 'Le', 63 'Le',
60 'Lt', 64 'Lt',
61 'MatcherCast', 65 'MatcherCast',
66 'Matches',
62 'MatchesRegex', 67 'MatchesRegex',
68 'NanSensitiveDoubleEq',
69 'NanSensitiveFloatEq',
63 'Ne', 70 'Ne',
64 'Not', 71 'Not',
65 'NotNull', 72 'NotNull',
66 'Pointee', 73 'Pointee',
67 'PointeeIsInitializedProto', 74 'PointeeIsInitializedProto',
68 'Property', 75 'Property',
69 'Ref', 76 'Ref',
77 'ResultOf',
78 'SafeMatcherCast',
70 'StartsWith', 79 'StartsWith',
71 'StrCaseEq', 80 'StrCaseEq',
72 'StrCaseNe', 81 'StrCaseNe',
73 'StrEq', 82 'StrEq',
74 'StrNe', 83 'StrNe',
75 'Truly', 84 'Truly',
76 'TypedEq', 85 'TypedEq',
86 'Value',
77 87
78 # Actions 88 # Actions
89 'Assign',
79 'ByRef', 90 'ByRef',
91 'DeleteArg',
80 'DoAll', 92 'DoAll',
81 'DoDefault', 93 'DoDefault',
82 'IgnoreResult', 94 'IgnoreResult',
83 'Invoke', 95 'Invoke',
84 'InvokeArgument', 96 'InvokeArgument',
85 'InvokeWithoutArgs', 97 'InvokeWithoutArgs',
86 'Return', 98 'Return',
99 'ReturnNew',
87 'ReturnNull', 100 'ReturnNull',
88 'ReturnRef', 101 'ReturnRef',
102 'SaveArg',
103 'SetArgReferee',
89 'SetArgumentPointee', 104 'SetArgumentPointee',
90 'SetArrayArgument', 105 'SetArrayArgument',
106 'SetErrnoAndReturn',
107 'Throw',
108 'WithArg',
91 'WithArgs', 109 'WithArgs',
110 'WithoutArgs',
92 111
93 # Cardinalities 112 # Cardinalities
94 'AnyNumber', 113 'AnyNumber',
95 'AtLeast', 114 'AtLeast',
96 'AtMost', 115 'AtMost',
97 'Between', 116 'Between',
98 'Exactly', 117 'Exactly',
99 118
100 # Sequences 119 # Sequences
101 'InSequence', 120 'InSequence',
102 'Sequence', 121 'Sequence',
103 122
104 # Misc 123 # Misc
105 'DefaultValue', 124 'DefaultValue',
106 'Mock', 125 'Mock',
107 ] 126 ]
108 127
128 # Regex for matching source file path and line number in gcc's errors.
129 _FILE_LINE_RE = r'(?P<file>.*):(?P<line>\d+):\s+'
130
109 131
110 def _FindAllMatches(regex, s): 132 def _FindAllMatches(regex, s):
111 """Generates all matches of regex in string s.""" 133 """Generates all matches of regex in string s."""
112 134
113 r = re.compile(regex) 135 r = re.compile(regex)
114 return r.finditer(s) 136 return r.finditer(s)
115 137
116 138
117 def _GenericDiagnoser(short_name, long_name, regex, diagnosis, msg): 139 def _GenericDiagnoser(short_name, long_name, regex, diagnosis, msg):
118 """Diagnoses the given disease by pattern matching. 140 """Diagnoses the given disease by pattern matching.
119 141
120 Args: 142 Args:
121 short_name: Short name of the disease. 143 short_name: Short name of the disease.
122 long_name: Long name of the disease. 144 long_name: Long name of the disease.
123 regex: Regex for matching the symptoms. 145 regex: Regex for matching the symptoms.
124 diagnosis: Pattern for formatting the diagnosis. 146 diagnosis: Pattern for formatting the diagnosis.
125 msg: Gcc's error messages. 147 msg: Gcc's error messages.
126 Yields: 148 Yields:
127 Tuples of the form 149 Tuples of the form
128 (short name of disease, long name of disease, diagnosis). 150 (short name of disease, long name of disease, diagnosis).
129 """ 151 """
130 152
153 diagnosis = '%(file)s:%(line)s:' + diagnosis
131 for m in _FindAllMatches(regex, msg): 154 for m in _FindAllMatches(regex, msg):
132 yield (short_name, long_name, diagnosis % m.groupdict()) 155 yield (short_name, long_name, diagnosis % m.groupdict())
133 156
134 157
135 def _NeedToReturnReferenceDiagnoser(msg): 158 def _NeedToReturnReferenceDiagnoser(msg):
136 """Diagnoses the NRR disease, given the error messages by gcc.""" 159 """Diagnoses the NRR disease, given the error messages by gcc."""
137 160
138 regex = (r'In member function \'testing::internal::ReturnAction<R>.*\n' 161 regex = (r'In member function \'testing::internal::ReturnAction<R>.*\n'
139 r'(?P<file>.*):(?P<line>\d+):\s+instantiated from here\n' 162 + _FILE_LINE_RE + r'instantiated from here\n'
140 r'.*gmock-actions\.h.*error: creating array with negative size') 163 r'.*gmock-actions\.h.*error: creating array with negative size')
141 diagnosis = """%(file)s:%(line)s: 164 diagnosis = """
142 You are using an Return() action in a function that returns a reference. 165 You are using an Return() action in a function that returns a reference.
143 Please use ReturnRef() instead.""" 166 Please use ReturnRef() instead."""
144 return _GenericDiagnoser('NRR', 'Need to Return Reference', 167 return _GenericDiagnoser('NRR', 'Need to Return Reference',
145 regex, diagnosis, msg) 168 regex, diagnosis, msg)
146 169
147 170
148 def _NeedToReturnSomethingDiagnoser(msg): 171 def _NeedToReturnSomethingDiagnoser(msg):
149 """Diagnoses the NRS disease, given the error messages by gcc.""" 172 """Diagnoses the NRS disease, given the error messages by gcc."""
150 173
151 regex = (r'(?P<file>.*):(?P<line>\d+):\s+' 174 regex = (_FILE_LINE_RE +
152 r'(instantiated from here\n.' 175 r'(instantiated from here\n.'
153 r'*gmock-actions\.h.*error: void value not ignored)' 176 r'*gmock.*actions\.h.*error: void value not ignored)'
154 r'|(error: control reaches end of non-void function)') 177 r'|(error: control reaches end of non-void function)')
155 diagnosis = """%(file)s:%(line)s: 178 diagnosis = """
156 You are using an action that returns void, but it needs to return 179 You are using an action that returns void, but it needs to return
157 *something*. Please tell it *what* to return. Perhaps you can use 180 *something*. Please tell it *what* to return. Perhaps you can use
158 the pattern DoAll(some_action, Return(some_value))?""" 181 the pattern DoAll(some_action, Return(some_value))?"""
159 return _GenericDiagnoser('NRS', 'Need to Return Something', 182 return _GenericDiagnoser('NRS', 'Need to Return Something',
160 regex, diagnosis, msg) 183 regex, diagnosis, msg)
161 184
162 185
163 def _NeedToReturnNothingDiagnoser(msg): 186 def _NeedToReturnNothingDiagnoser(msg):
164 """Diagnoses the NRN disease, given the error messages by gcc.""" 187 """Diagnoses the NRN disease, given the error messages by gcc."""
165 188
166 regex = (r'(?P<file>.*):(?P<line>\d+):\s+instantiated from here\n' 189 regex = (_FILE_LINE_RE + r'instantiated from here\n'
167 r'.*gmock-actions\.h.*error: return-statement with a value, ' 190 r'.*gmock-actions\.h.*error: return-statement with a value, '
168 r'in function returning \'void\'') 191 r'in function returning \'void\'')
169 diagnosis = """%(file)s:%(line)s: 192 diagnosis = """
170 You are using an action that returns *something*, but it needs to return 193 You are using an action that returns *something*, but it needs to return
171 void. Please use a void-returning action instead. 194 void. Please use a void-returning action instead.
172 195
173 All actions but the last in DoAll(...) must return void. Perhaps you need 196 All actions but the last in DoAll(...) must return void. Perhaps you need
174 to re-arrange the order of actions in a DoAll(), if you are using one?""" 197 to re-arrange the order of actions in a DoAll(), if you are using one?"""
175 return _GenericDiagnoser('NRN', 'Need to Return Nothing', 198 return _GenericDiagnoser('NRN', 'Need to Return Nothing',
176 regex, diagnosis, msg) 199 regex, diagnosis, msg)
177 200
178 201
179 def _IncompleteByReferenceArgumentDiagnoser(msg): 202 def _IncompleteByReferenceArgumentDiagnoser(msg):
180 """Diagnoses the IBRA disease, given the error messages by gcc.""" 203 """Diagnoses the IBRA disease, given the error messages by gcc."""
181 204
182 regex = (r'(?P<file>.*):(?P<line>\d+):\s+instantiated from here\n' 205 regex = (_FILE_LINE_RE + r'instantiated from here\n'
183 r'.*gmock-printers\.h.*error: invalid application of ' 206 r'.*gmock-printers\.h.*error: invalid application of '
184 r'\'sizeof\' to incomplete type \'(?P<type>.*)\'') 207 r'\'sizeof\' to incomplete type \'(?P<type>.*)\'')
185 diagnosis = """%(file)s:%(line)s: 208 diagnosis = """
186 In order to mock this function, Google Mock needs to see the definition 209 In order to mock this function, Google Mock needs to see the definition
187 of type "%(type)s" - declaration alone is not enough. Either #include 210 of type "%(type)s" - declaration alone is not enough. Either #include
188 the header that defines it, or change the argument to be passed 211 the header that defines it, or change the argument to be passed
189 by pointer.""" 212 by pointer."""
190 return _GenericDiagnoser('IBRA', 'Incomplete By-Reference Argument Type', 213 return _GenericDiagnoser('IBRA', 'Incomplete By-Reference Argument Type',
191 regex, diagnosis, msg) 214 regex, diagnosis, msg)
192 215
193 216
194 def _OverloadedFunctionMatcherDiagnoser(msg): 217 def _OverloadedFunctionMatcherDiagnoser(msg):
195 """Diagnoses the OFM disease, given the error messages by gcc.""" 218 """Diagnoses the OFM disease, given the error messages by gcc."""
196 219
197 regex = (r'(?P<file>.*):(?P<line>\d+): error: no matching function for ' 220 regex = (_FILE_LINE_RE + r'error: no matching function for '
198 r'call to \'Truly\(<unresolved overloaded function type>\)') 221 r'call to \'Truly\(<unresolved overloaded function type>\)')
199 diagnosis = """%(file)s:%(line)s: 222 diagnosis = """
200 The argument you gave to Truly() is an overloaded function. Please tell 223 The argument you gave to Truly() is an overloaded function. Please tell
201 gcc which overloaded version you want to use. 224 gcc which overloaded version you want to use.
202 225
203 For example, if you want to use the version whose signature is 226 For example, if you want to use the version whose signature is
204 bool Foo(int n); 227 bool Foo(int n);
205 you should write 228 you should write
206 Truly(static_cast<bool (*)(int n)>(Foo))""" 229 Truly(static_cast<bool (*)(int n)>(Foo))"""
207 return _GenericDiagnoser('OFM', 'Overloaded Function Matcher', 230 return _GenericDiagnoser('OFM', 'Overloaded Function Matcher',
208 regex, diagnosis, msg) 231 regex, diagnosis, msg)
209 232
210 233
211 def _OverloadedFunctionActionDiagnoser(msg): 234 def _OverloadedFunctionActionDiagnoser(msg):
212 """Diagnoses the OFA disease, given the error messages by gcc.""" 235 """Diagnoses the OFA disease, given the error messages by gcc."""
213 236
214 regex = (r'(?P<file>.*):(?P<line>\d+): error: ' 237 regex = (_FILE_LINE_RE + r'error: no matching function for call to \'Invoke\('
215 r'no matching function for call to \'Invoke\('
216 r'<unresolved overloaded function type>') 238 r'<unresolved overloaded function type>')
217 diagnosis = """%(file)s:%(line)s: 239 diagnosis = """
218 You are passing an overloaded function to Invoke(). Please tell gcc 240 You are passing an overloaded function to Invoke(). Please tell gcc
219 which overloaded version you want to use. 241 which overloaded version you want to use.
220 242
221 For example, if you want to use the version whose signature is 243 For example, if you want to use the version whose signature is
222 bool MyFunction(int n, double x); 244 bool MyFunction(int n, double x);
223 you should write something like 245 you should write something like
224 Invoke(static_cast<bool (*)(int n, double x)>(MyFunction))""" 246 Invoke(static_cast<bool (*)(int n, double x)>(MyFunction))"""
225 return _GenericDiagnoser('OFA', 'Overloaded Function Action', 247 return _GenericDiagnoser('OFA', 'Overloaded Function Action',
226 regex, diagnosis, msg) 248 regex, diagnosis, msg)
227 249
228 250
229 def _OverloadedMethodActionDiagnoser1(msg): 251 def _OverloadedMethodActionDiagnoser1(msg):
230 """Diagnoses the OMA disease, given the error messages by gcc.""" 252 """Diagnoses the OMA disease, given the error messages by gcc."""
231 253
232 regex = (r'(?P<file>.*):(?P<line>\d+): error: ' 254 regex = (_FILE_LINE_RE + r'error: '
233 r'.*no matching function for call to \'Invoke\(.*, ' 255 r'.*no matching function for call to \'Invoke\(.*, '
234 r'unresolved overloaded function type>') 256 r'unresolved overloaded function type>')
235 diagnosis = """%(file)s:%(line)s: 257 diagnosis = """
236 The second argument you gave to Invoke() is an overloaded method. Please 258 The second argument you gave to Invoke() is an overloaded method. Please
237 tell gcc which overloaded version you want to use. 259 tell gcc which overloaded version you want to use.
238 260
239 For example, if you want to use the version whose signature is 261 For example, if you want to use the version whose signature is
240 class Foo { 262 class Foo {
241 ... 263 ...
242 bool Bar(int n, double x); 264 bool Bar(int n, double x);
243 }; 265 };
244 you should write something like 266 you should write something like
245 Invoke(foo, static_cast<bool (Foo::*)(int n, double x)>(&Foo::Bar))""" 267 Invoke(foo, static_cast<bool (Foo::*)(int n, double x)>(&Foo::Bar))"""
246 return _GenericDiagnoser('OMA', 'Overloaded Method Action', 268 return _GenericDiagnoser('OMA', 'Overloaded Method Action',
247 regex, diagnosis, msg) 269 regex, diagnosis, msg)
248 270
249 271
250 def _MockObjectPointerDiagnoser(msg): 272 def _MockObjectPointerDiagnoser(msg):
251 """Diagnoses the MOP disease, given the error messages by gcc.""" 273 """Diagnoses the MOP disease, given the error messages by gcc."""
252 274
253 regex = (r'(?P<file>.*):(?P<line>\d+): error: request for member ' 275 regex = (_FILE_LINE_RE + r'error: request for member '
254 r'\'gmock_(?P<method>.+)\' in \'(?P<mock_object>.+)\', ' 276 r'\'gmock_(?P<method>.+)\' in \'(?P<mock_object>.+)\', '
255 r'which is of non-class type \'(.*::)*(?P<class_name>.+)\*\'') 277 r'which is of non-class type \'(.*::)*(?P<class_name>.+)\*\'')
256 diagnosis = """%(file)s:%(line)s: 278 diagnosis = """
257 The first argument to ON_CALL() and EXPECT_CALL() must be a mock *object*, 279 The first argument to ON_CALL() and EXPECT_CALL() must be a mock *object*,
258 not a *pointer* to it. Please write '*(%(mock_object)s)' instead of 280 not a *pointer* to it. Please write '*(%(mock_object)s)' instead of
259 '%(mock_object)s' as your first argument. 281 '%(mock_object)s' as your first argument.
260 282
261 For example, given the mock class: 283 For example, given the mock class:
262 284
263 class %(class_name)s : public ... { 285 class %(class_name)s : public ... {
264 ... 286 ...
265 MOCK_METHOD0(%(method)s, ...); 287 MOCK_METHOD0(%(method)s, ...);
266 }; 288 };
267 289
268 and the following mock instance: 290 and the following mock instance:
269 291
270 %(class_name)s* mock_ptr = ... 292 %(class_name)s* mock_ptr = ...
271 293
272 you should use the EXPECT_CALL like this: 294 you should use the EXPECT_CALL like this:
273 295
274 EXPECT_CALL(*mock_ptr, %(method)s(...));""" 296 EXPECT_CALL(*mock_ptr, %(method)s(...));"""
275 return _GenericDiagnoser('MOP', 'Mock Object Pointer', 297 return _GenericDiagnoser('MOP', 'Mock Object Pointer',
276 regex, diagnosis, msg) 298 regex, diagnosis, msg)
277 299
278 300
279 def _OverloadedMethodActionDiagnoser2(msg): 301 def _OverloadedMethodActionDiagnoser2(msg):
280 """Diagnoses the OMA disease, given the error messages by gcc.""" 302 """Diagnoses the OMA disease, given the error messages by gcc."""
281 303
282 regex = (r'(?P<file>.*):(?P<line>\d+): error: no matching function for ' 304 regex = (_FILE_LINE_RE + r'error: no matching function for '
283 r'call to \'Invoke\(.+, <unresolved overloaded function type>\)') 305 r'call to \'Invoke\(.+, <unresolved overloaded function type>\)')
284 diagnosis = """%(file)s:%(line)s: 306 diagnosis = """
285 The second argument you gave to Invoke() is an overloaded method. Please 307 The second argument you gave to Invoke() is an overloaded method. Please
286 tell gcc which overloaded version you want to use. 308 tell gcc which overloaded version you want to use.
287 309
288 For example, if you want to use the version whose signature is 310 For example, if you want to use the version whose signature is
289 class Foo { 311 class Foo {
290 ... 312 ...
291 bool Bar(int n, double x); 313 bool Bar(int n, double x);
292 }; 314 };
293 you should write something like 315 you should write something like
294 Invoke(foo, static_cast<bool (Foo::*)(int n, double x)>(&Foo::Bar))""" 316 Invoke(foo, static_cast<bool (Foo::*)(int n, double x)>(&Foo::Bar))"""
295 return _GenericDiagnoser('OMA', 'Overloaded Method Action', 317 return _GenericDiagnoser('OMA', 'Overloaded Method Action',
296 regex, diagnosis, msg) 318 regex, diagnosis, msg)
297 319
298 320
299 def _NeedToUseSymbolDiagnoser(msg): 321 def _NeedToUseSymbolDiagnoser(msg):
300 """Diagnoses the NUS disease, given the error messages by gcc.""" 322 """Diagnoses the NUS disease, given the error messages by gcc."""
301 323
302 regex = (r'(?P<file>.*):(?P<line>\d+): error: \'(?P<symbol>.+)\' ' 324 regex = (_FILE_LINE_RE + r'error: \'(?P<symbol>.+)\' '
303 r'(was not declared in this scope|has not been declared)') 325 r'(was not declared in this scope|has not been declared)')
304 diagnosis = """%(file)s:%(line)s: 326 diagnosis = """
305 '%(symbol)s' is defined by Google Mock in the testing namespace. 327 '%(symbol)s' is defined by Google Mock in the testing namespace.
306 Did you forget to write 328 Did you forget to write
307 using testing::%(symbol)s; 329 using testing::%(symbol)s;
308 ?""" 330 ?"""
309 for m in _FindAllMatches(regex, msg): 331 for m in _FindAllMatches(regex, msg):
310 symbol = m.groupdict()['symbol'] 332 symbol = m.groupdict()['symbol']
311 if symbol in _COMMON_GMOCK_SYMBOLS: 333 if symbol in _COMMON_GMOCK_SYMBOLS:
312 yield ('NUS', 'Need to Use Symbol', diagnosis % m.groupdict()) 334 yield ('NUS', 'Need to Use Symbol', diagnosis % m.groupdict())
313 335
314 336
315 def _NeedToUseReturnNullDiagnoser(msg): 337 def _NeedToUseReturnNullDiagnoser(msg):
316 """Diagnoses the NRNULL disease, given the error messages by gcc.""" 338 """Diagnoses the NRNULL disease, given the error messages by gcc."""
317 339
318 regex = (r'(?P<file>.*):(?P<line>\d+):\s+instantiated from here\n' 340 regex = (_FILE_LINE_RE + r'instantiated from here\n'
319 r'.*gmock-actions\.h.*error: invalid conversion from ' 341 r'.*gmock-actions\.h.*error: invalid conversion from '
320 r'\'long int\' to \'(?P<type>.+\*)') 342 r'\'long int\' to \'(?P<type>.+\*)')
321 343 diagnosis = """
322 diagnosis = """%(file)s:%(line)s:
323 You are probably calling Return(NULL) and the compiler isn't sure how to turn 344 You are probably calling Return(NULL) and the compiler isn't sure how to turn
324 NULL into a %(type)s*. Use ReturnNull() instead. 345 NULL into a %(type)s*. Use ReturnNull() instead.
325 Note: the line number may be off; please fix all instances of Return(NULL).""" 346 Note: the line number may be off; please fix all instances of Return(NULL)."""
326 return _GenericDiagnoser('NRNULL', 'Need to use ReturnNull', 347 return _GenericDiagnoser('NRNULL', 'Need to use ReturnNull',
327 regex, diagnosis, msg) 348 regex, diagnosis, msg)
328 349
329 350
351 _TTB_DIAGNOSIS = """
352 In a mock class template, types or typedefs defined in the base class
353 template are *not* automatically visible. This is how C++ works. Before
354 you can use a type or typedef named %(type)s defined in base class Base<T>, you
355 need to make it visible. One way to do it is:
356
357 typedef typename Base<T>::%(type)s %(type)s;"""
358
359
360 def _TypeInTemplatedBaseDiagnoser1(msg):
361 """Diagnoses the TTB disease, given the error messages by gcc.
362
363 This version works when the type is used as the mock function's return
364 type.
365 """
366
367 regex = (r'In member function \'int .*\n' + _FILE_LINE_RE +
368 r'error: a function call cannot appear in a constant-expression')
369 diagnosis = _TTB_DIAGNOSIS % {'type': 'Foo'}
370 return _GenericDiagnoser('TTB', 'Type in Template Base',
371 regex, diagnosis, msg)
372
373
374 def _TypeInTemplatedBaseDiagnoser2(msg):
375 """Diagnoses the TTB disease, given the error messages by gcc.
376
377 This version works when the type is used as the mock function's sole
378 parameter type.
379 """
380
381 regex = (r'In member function \'int .*\n'
382 + _FILE_LINE_RE +
383 r'error: \'(?P<type>.+)\' was not declared in this scope\n'
384 r'.*error: template argument 1 is invalid\n')
385 return _GenericDiagnoser('TTB', 'Type in Template Base',
386 regex, _TTB_DIAGNOSIS, msg)
387
388
389 def _TypeInTemplatedBaseDiagnoser3(msg):
390 """Diagnoses the TTB disease, given the error messages by gcc.
391
392 This version works when the type is used as a parameter of a mock
393 function that has multiple parameters.
394 """
395
396 regex = (r'error: expected `;\' before \'::\' token\n'
397 + _FILE_LINE_RE +
398 r'error: \'(?P<type>.+)\' was not declared in this scope\n'
399 r'.*error: template argument 1 is invalid\n'
400 r'.*error: \'.+\' was not declared in this scope')
401 return _GenericDiagnoser('TTB', 'Type in Template Base',
402 regex, _TTB_DIAGNOSIS, msg)
403
404
330 def _WrongMockMethodMacroDiagnoser(msg): 405 def _WrongMockMethodMacroDiagnoser(msg):
331 """Diagnoses the WMM disease, given the error messages by gcc.""" 406 """Diagnoses the WMM disease, given the error messages by gcc."""
332 407
333 regex = (r'(?P<file>.*):(?P<line>\d+):\s+' 408 regex = (_FILE_LINE_RE +
334 r'.*this_method_does_not_take_(?P<wrong_args>\d+)_argument.*\n' 409 r'.*this_method_does_not_take_(?P<wrong_args>\d+)_argument.*\n'
335 r'.*\n' 410 r'.*\n'
336 r'.*candidates are.*FunctionMocker<[^>]+A(?P<args>\d+)\)>' 411 r'.*candidates are.*FunctionMocker<[^>]+A(?P<args>\d+)\)>')
337 ) 412 diagnosis = """
338
339 diagnosis = """%(file)s:%(line)s:
340 You are using MOCK_METHOD%(wrong_args)s to define a mock method that has 413 You are using MOCK_METHOD%(wrong_args)s to define a mock method that has
341 %(args)s arguments. Use MOCK_METHOD%(args)s (or MOCK_CONST_METHOD%(args)s, 414 %(args)s arguments. Use MOCK_METHOD%(args)s (or MOCK_CONST_METHOD%(args)s,
342 MOCK_METHOD%(args)s_T, MOCK_CONST_METHOD%(args)s_T as appropriate) instead.""" 415 MOCK_METHOD%(args)s_T, MOCK_CONST_METHOD%(args)s_T as appropriate) instead."""
343 return _GenericDiagnoser('WMM', 'Wrong MOCK_METHODn macro', 416 return _GenericDiagnoser('WMM', 'Wrong MOCK_METHODn Macro',
344 regex, diagnosis, msg) 417 regex, diagnosis, msg)
345 418
346 419
420 def _WrongParenPositionDiagnoser(msg):
421 """Diagnoses the WPP disease, given the error messages by gcc."""
422
423 regex = (_FILE_LINE_RE +
424 r'error:.*testing::internal::MockSpec<.* has no member named \''
425 r'(?P<method>\w+)\'')
426 diagnosis = """
427 The closing parenthesis of ON_CALL or EXPECT_CALL should be *before*
428 ".%(method)s". For example, you should write:
429 EXPECT_CALL(my_mock, Foo(_)).%(method)s(...);
430 instead of:
431 EXPECT_CALL(my_mock, Foo(_).%(method)s(...));"""
432 return _GenericDiagnoser('WPP', 'Wrong Parenthesis Position',
433 regex, diagnosis, msg)
434
347 435
348 _DIAGNOSERS = [ 436 _DIAGNOSERS = [
349 _IncompleteByReferenceArgumentDiagnoser, 437 _IncompleteByReferenceArgumentDiagnoser,
350 _MockObjectPointerDiagnoser, 438 _MockObjectPointerDiagnoser,
351 _NeedToReturnNothingDiagnoser, 439 _NeedToReturnNothingDiagnoser,
352 _NeedToReturnReferenceDiagnoser, 440 _NeedToReturnReferenceDiagnoser,
353 _NeedToReturnSomethingDiagnoser, 441 _NeedToReturnSomethingDiagnoser,
354 _NeedToUseReturnNullDiagnoser, 442 _NeedToUseReturnNullDiagnoser,
355 _NeedToUseSymbolDiagnoser, 443 _NeedToUseSymbolDiagnoser,
356 _OverloadedFunctionActionDiagnoser, 444 _OverloadedFunctionActionDiagnoser,
357 _OverloadedFunctionMatcherDiagnoser, 445 _OverloadedFunctionMatcherDiagnoser,
358 _OverloadedMethodActionDiagnoser1, 446 _OverloadedMethodActionDiagnoser1,
359 _OverloadedMethodActionDiagnoser2, 447 _OverloadedMethodActionDiagnoser2,
448 _TypeInTemplatedBaseDiagnoser1,
449 _TypeInTemplatedBaseDiagnoser2,
450 _TypeInTemplatedBaseDiagnoser3,
360 _WrongMockMethodMacroDiagnoser, 451 _WrongMockMethodMacroDiagnoser,
452 _WrongParenPositionDiagnoser,
361 ] 453 ]
362 454
363 455
364 def Diagnose(msg): 456 def Diagnose(msg):
365 """Generates all possible diagnoses given the gcc error message.""" 457 """Generates all possible diagnoses given the gcc error message."""
366 458
367 for diagnoser in _DIAGNOSERS: 459 for diagnoser in _DIAGNOSERS:
368 for diagnosis in diagnoser(msg): 460 for diagnosis in diagnoser(msg):
369 yield '[%s - %s]\n%s' % diagnosis 461 yield '[%s - %s]\n%s' % diagnosis
370 462
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 print '\n#%s:' % (i,) 499 print '\n#%s:' % (i,)
408 print d 500 print d
409 print """ 501 print """
410 How did I do? If you think I'm wrong or unhelpful, please send your 502 How did I do? If you think I'm wrong or unhelpful, please send your
411 source code and gcc's error messages to googlemock@googlegroups.com. Then 503 source code and gcc's error messages to googlemock@googlegroups.com. Then
412 you can be helped and I can get smarter -- I promise I won't be upset!""" 504 you can be helped and I can get smarter -- I promise I won't be upset!"""
413 505
414 506
415 if __name__ == '__main__': 507 if __name__ == '__main__':
416 main() 508 main()
OLDNEW
« no previous file with comments | « testing/gmock/scripts/gmock-config.in ('k') | testing/gmock/src/gmock-internal-utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698