From e4f10bce6da9ac58ff033b04d1dda407d4b37e3d Mon Sep 17 00:00:00 2001 From: "Richard A. Smith" Date: Sun, 20 May 2018 08:48:01 -0400 Subject: [PATCH] Show summary of violations (#1244) - Show a summary of the of the number of violations. This can be disabled with the --no-summary option. - Return an error code if -verify flag not used and violation exists. --- addons/misra.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index 34495fc70..782b1fecf 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -23,9 +23,10 @@ import subprocess ruleTexts = {} VERIFY = False +SHOW_SUMMARY = True VERIFY_EXPECTED = [] VERIFY_ACTUAL = [] - +VIOLATIONS = [] def reportError(location, num1, num2): if VERIFY: @@ -39,8 +40,10 @@ def reportError(location, num1, num2): errmsg = 'misra violation (use --rule-texts= to get proper output) [' + id + ']' else: return - sys.stderr.write('[' + location.file + ':' + str(location.linenr) + '] (style): ' + errmsg + '\n') + errmsg = '[' + location.file + ':' + str(location.linenr) + '] (style): ' + errmsg + '\n' + sys.stderr.write(errmsg) + VIOLATIONS.append(errmsg) def simpleMatch(token, pattern): for p in pattern.split(' '): @@ -1512,10 +1515,13 @@ for arg in sys.argv[1:]: continue elif arg == "-generate-table": generateTable() + elif arg == "--no-summary": + SHOW_SUMMARY = False else: print('Fatal error: unhandled argument ' + arg) sys.exit(1) +exitCode = 0 for arg in sys.argv[1:]: if not arg.endswith('.dump'): continue @@ -1639,4 +1645,11 @@ for arg in sys.argv[1:]: if actual not in VERIFY_EXPECTED: print('Not expected: ' + actual) exitCode = 1 - sys.exit(exitCode) + +if not VERIFY: + if len(VIOLATIONS) > 0: + if SHOW_SUMMARY: + print("\nRule violations found: %d\n"%(len(VIOLATIONS))) + exitCode = 1 + +sys.exit(exitCode)