mirror of git://gcc.gnu.org/git/gcc.git
check_GNU_style_lib.py: Fix trailing whitespace check
2017-05-29 Tom de Vries <tom@codesourcery.com> * check_GNU_style_lib.py (TrailingWhitespaceCheck.check): Assert no trailing eol. (TrailingWhitespaceTest): New unit test. (check_GNU_style_file): Remove eol before checking. From-SVN: r248556
This commit is contained in:
parent
75017bb975
commit
0a71c876a1
|
|
@ -1,3 +1,10 @@
|
||||||
|
2017-05-29 Tom de Vries <tom@codesourcery.com>
|
||||||
|
|
||||||
|
* check_GNU_style_lib.py (TrailingWhitespaceCheck.check): Assert no
|
||||||
|
trailing eol.
|
||||||
|
(TrailingWhitespaceTest): New unit test.
|
||||||
|
(check_GNU_style_file): Remove eol before checking.
|
||||||
|
|
||||||
2017-05-29 Tom de Vries <tom@codesourcery.com>
|
2017-05-29 Tom de Vries <tom@codesourcery.com>
|
||||||
|
|
||||||
* check_GNU_style_lib.py (check_GNU_style_file): Treat file argument as
|
* check_GNU_style_lib.py (check_GNU_style_file): Treat file argument as
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ class TrailingWhitespaceCheck:
|
||||||
self.re = re.compile('(\s+)$')
|
self.re = re.compile('(\s+)$')
|
||||||
|
|
||||||
def check(self, filename, lineno, line):
|
def check(self, filename, lineno, line):
|
||||||
|
assert(len(line) == 0 or line[-1] != '\n')
|
||||||
m = self.re.search(line)
|
m = self.re.search(line)
|
||||||
if m != None:
|
if m != None:
|
||||||
return CheckError(filename, lineno,
|
return CheckError(filename, lineno,
|
||||||
|
|
@ -223,6 +224,18 @@ class LineLengthTest(unittest.TestCase):
|
||||||
self.assertEqual(r.console_error,
|
self.assertEqual(r.console_error,
|
||||||
self.check.limit * 'a' + error_string(' = 123;'))
|
self.check.limit * 'a' + error_string(' = 123;'))
|
||||||
|
|
||||||
|
class TrailingWhitespaceTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.check = TrailingWhitespaceCheck()
|
||||||
|
|
||||||
|
def test_trailing_whitespace_check_basic(self):
|
||||||
|
r = self.check.check('foo', 123, 'a = 123;')
|
||||||
|
self.assertIsNone(r)
|
||||||
|
r = self.check.check('foo', 123, 'a = 123; ')
|
||||||
|
self.assertIsNotNone(r)
|
||||||
|
r = self.check.check('foo', 123, 'a = 123;\t')
|
||||||
|
self.assertIsNotNone(r)
|
||||||
|
|
||||||
def check_GNU_style_file(file, file_encoding, format):
|
def check_GNU_style_file(file, file_encoding, format):
|
||||||
checks = [LineLengthCheck(), SpacesCheck(), TrailingWhitespaceCheck(),
|
checks = [LineLengthCheck(), SpacesCheck(), TrailingWhitespaceCheck(),
|
||||||
SentenceSeparatorCheck(), SentenceEndOfCommentCheck(),
|
SentenceSeparatorCheck(), SentenceEndOfCommentCheck(),
|
||||||
|
|
@ -244,7 +257,8 @@ def check_GNU_style_file(file, file_encoding, format):
|
||||||
for line in hunk:
|
for line in hunk:
|
||||||
if line.is_added and line.target_line_no != None:
|
if line.is_added and line.target_line_no != None:
|
||||||
for check in checks:
|
for check in checks:
|
||||||
e = check.check(t, line.target_line_no, line.value)
|
line_chomp = line.value.replace('\n', '')
|
||||||
|
e = check.check(t, line.target_line_no, line_chomp)
|
||||||
if e != None:
|
if e != None:
|
||||||
errors.append(e)
|
errors.append(e)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue