Skip to content

Commit

Permalink
added exit status so failed tests exit with with # of errors (non-0 s…
Browse files Browse the repository at this point in the history
…tatus) or 0 on success
  • Loading branch information
johncoleman83 committed Aug 11, 2017
1 parent 958452f commit cba0579
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions w3c_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __analyse_css(file_path):
def __analyse(file_path):
"""Start analyse of a file and print the result
"""
nb_errors = 0
try:
result = None
if file_path.endswith('.css'):
Expand All @@ -89,11 +90,21 @@ def __analyse(file_path):
if len(result) > 0:
for msg in result:
__print_stderr("{}\n".format(msg))
nb_errors += 1
else:
__print_stdout("{}: OK\n".format(file_path))

except Exception as e:
__print_stderr("[{}] {}\n".format(e.__class__.__name__, e))
return nb_errors


def __main_app():
nb_errors = 0
for file_path in sys.argv[1:]:
nb_errors += __analyse(file_path)

return nb_errors


if __name__ == "__main__":
Expand All @@ -103,5 +114,6 @@ def __analyse(file_path):
__print_stderr("usage: w3c_validator.py file1 file2 ...\n")
exit(1)

for file_path in sys.argv[1:]:
__analyse(file_path)
"""execute tests, then exit. Exit status = # of errors (0 on success)
"""
sys.exit(__main_app())

0 comments on commit cba0579

Please sign in to comment.