test: Make white space error report more pronounced
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
ca7a80a946
commit
6b4e44011c
|
@ -10,9 +10,10 @@ HaveError = False
|
||||||
|
|
||||||
def report_error(filename, lineno, msg):
|
def report_error(filename, lineno, msg):
|
||||||
global HaveError
|
global HaveError
|
||||||
|
if not HaveError:
|
||||||
|
sys.stderr.write("\n\nERROR:\nERROR: White space errors\nERROR:\n")
|
||||||
HaveError = True
|
HaveError = True
|
||||||
sys.stderr.write("Whitespace error in file %s on line %d: %s\n" % (
|
sys.stderr.write("%s:%d: %s\n" % (filename, lineno + 1, msg))
|
||||||
filename, lineno + 1, msg))
|
|
||||||
|
|
||||||
def check_file(filename):
|
def check_file(filename):
|
||||||
# Open and read file
|
# Open and read file
|
||||||
|
@ -32,7 +33,7 @@ def check_file(filename):
|
||||||
try:
|
try:
|
||||||
line = line.decode('utf-8')
|
line = line.decode('utf-8')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
report_error(filename, lineno, "Non utf-8 character")
|
report_error(filename, lineno, "Found non utf-8 character")
|
||||||
continue
|
continue
|
||||||
# Check for control characters
|
# Check for control characters
|
||||||
for c in line:
|
for c in line:
|
||||||
|
@ -47,7 +48,7 @@ def check_file(filename):
|
||||||
break
|
break
|
||||||
# Check for trailing space
|
# Check for trailing space
|
||||||
if line.endswith(' '):
|
if line.endswith(' '):
|
||||||
report_error(filename, lineno, "Trailing space")
|
report_error(filename, lineno, "Line has trailing spaces")
|
||||||
if not data.endswith('\n'):
|
if not data.endswith('\n'):
|
||||||
report_error(filename, lineno, "No newline at end of file")
|
report_error(filename, lineno, "No newline at end of file")
|
||||||
if data.endswith('\n\n'):
|
if data.endswith('\n\n'):
|
||||||
|
@ -58,6 +59,7 @@ def main():
|
||||||
for filename in files:
|
for filename in files:
|
||||||
check_file(filename)
|
check_file(filename)
|
||||||
if HaveError:
|
if HaveError:
|
||||||
|
sys.stderr.write("\n\n")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue