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