82
82
# do not even think of increasing this number. If you think you need to
83
83
# increase it, then you almost certainly are doing something wrong as
84
84
# the relationship from working_tree to branch is one way.
85
# Note that this is an exact equality so that when the number drops,
85
# Note that this is an exact equality so that when the number drops,
86
86
#it is not given a buffer but rather has this test updated immediately.
87
87
self.assertEqual(0, occurences)
264
264
self.fail('\n'.join(help_text))
266
def test_no_tabs(self):
267
"""bzrlib source files should not contain any tab characters."""
266
def _push_file(self, dict_, fname, line_no):
267
if fname not in dict_:
268
dict_[fname] = [line_no]
270
dict_[fname].append(line_no)
272
def _format_message(self, dict_, message):
273
files = ["%s: %s" % (f, ', '.join([str(i+1) for i in lines]))
274
for f, lines in dict_.items()]
276
return message + '\n\n %s' % ('\n '.join(files))
278
def test_coding_style(self):
279
"""Check if bazaar code conforms to some coding style conventions.
281
Currently we check for:
283
* trailing white space
285
* no newline at end of files
286
* lines longer than 79 chars
287
(only print how many files and lines are in violation)
291
illegal_newlines = {}
293
no_newline_at_eof = []
270
294
for fname, text in self.get_source_file_contents():
271
295
if not self.is_our_code(fname):
274
incorrect.append(fname)
277
self.fail('Tab characters were found in the following source files.'
278
'\nThey should either be replaced by "\\t" or by spaces:'
280
% ('\n '.join(incorrect)))
297
lines = text.splitlines(True)
298
last_line_no = len(lines) - 1
299
for line_no, line in enumerate(lines):
301
self._push_file(tabs, fname, line_no)
302
if not line.endswith('\n') or line.endswith('\r\n'):
303
if line_no != last_line_no: # not no_newline_at_eof
304
self._push_file(illegal_newlines, fname, line_no)
305
if line.endswith(' \n'):
306
self._push_file(trailing_ws, fname, line_no)
308
self._push_file(long_lines, fname, line_no)
309
if not lines[-1].endswith('\n'):
310
no_newline_at_eof.append(fname)
313
problems.append(self._format_message(tabs,
314
'Tab characters were found in the following source files.'
315
'\nThey should either be replaced by "\\t" or by spaces:'))
317
problems.append(self._format_message(trailing_ws,
318
'Trailing white space was found in the following source files:'
321
problems.append(self._format_message(illegal_newlines,
322
'Non-unix newlines were found in the following source files:'))
324
print ("There are %i lines longer than 79 characters in %i files."
325
% (sum([len(lines) for f, lines in long_lines.items()]),
327
if no_newline_at_eof:
328
no_newline_at_eof.sort()
329
problems.append("The following source files doesn't have a "
330
"newline at the end:"
332
% ('\n '.join(no_newline_at_eof)))
334
raise KnownFailure("test_coding_style has failed")
335
self.fail('\n\n'.join(problems))
282
337
def test_no_asserts(self):
283
338
"""bzr shouldn't use the 'assert' statement."""