Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Tidy: Handle empty files
  • Loading branch information
UK992 committed Aug 29, 2016
1 parent 9e726b4 commit d5b76c9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/tidy/servo_tidy/tidy.py
Expand Up @@ -739,6 +739,9 @@ def collect_errors_for_files(files_to_check, checking_functions, line_checking_f
continue
with open(filename, "r") as f:
contents = f.read()
if not contents.strip():
yield filename, 0, "file is empty"
continue
for check in checking_functions:
for error in check(filename, contents):
# the result will be: `(filename, line, message)`
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions python/tidy/servo_tidy_tests/test_tidy.py
Expand Up @@ -39,6 +39,11 @@ def test_spaces_correctnes(self):
self.assertEqual('no newline at EOF', errors.next()[2])
self.assertNoMoreErrors(errors)

def test_empty_file(self):
errors = tidy.collect_errors_for_files(iterFile('empty_file.rs'), [], [tidy.check_by_line], print_text=False)
self.assertEqual('file is empty', errors.next()[2])
self.assertNoMoreErrors(errors)

def test_long_line(self):
errors = tidy.collect_errors_for_files(iterFile('long_line.rs'), [], [tidy.check_by_line], print_text=False)
self.assertEqual('Line is longer than 120 characters', errors.next()[2])
Expand Down

0 comments on commit d5b76c9

Please sign in to comment.