Fixed #9830 (Addons should return 0 when success)

This commit is contained in:
Daniel Marjamäki 2020-08-29 07:44:13 +02:00
parent acd1e848dd
commit c6d2e0fae1
9 changed files with 44 additions and 40 deletions

View File

@ -439,3 +439,5 @@ if __name__ == '__main__':
if actual not in VERIFY_EXPECTED:
print('Not expected: ' + actual)
sys.exit(1)
sys.exit(cppcheckdata.EXIT_CODE)

View File

@ -13,6 +13,8 @@ import sys
from xml.etree import ElementTree
from fnmatch import fnmatch
EXIT_CODE = 0
class Directive:
"""
Directive class. Contains information about each preprocessor directive in the source code.
@ -1102,3 +1104,5 @@ def reportError(location, severity, message, addon, errorId, extra=''):
if len(extra) > 0:
message += ' (' + extra + ')'
sys.stderr.write('%s (%s) %s [%s-%s]\n' % (loc, severity, message, addon, errorId))
global EXIT_CODE
EXIT_CODE = 1

View File

@ -38,3 +38,5 @@ for arg in sys.argv[1:]:
continue
cppcheckdata.reportError(token, 'information', 'found a cast', 'findcasts', 'cast')
sys.exit(cppcheckdata.EXIT_CODE)

View File

@ -163,3 +163,5 @@ for arg in sys.argv[1:]:
if actual not in VERIFY_EXPECTED:
print('Not expected: ' + actual)
sys.exit(1)
sys.exit(cppcheckdata.EXIT_CODE)

View File

@ -3126,7 +3126,6 @@ def main():
if args.severity:
checker.setSeverity(args.severity)
exitCode = 0
for item in args.dumpfile:
checker.parseDump(item)
@ -3134,6 +3133,7 @@ def main():
verify_expected = checker.get_verify_expected()
verify_actual = checker.get_verify_actual()
exitCode = 0
for expected in verify_expected:
if expected not in verify_actual:
print('Expected but not seen: ' + expected)
@ -3150,41 +3150,38 @@ def main():
if exitCode != 0:
sys.exit(exitCode)
# Under normal operation exit with a non-zero exit code
# if there were any violations.
if not settings.verify:
number_of_violations = len(checker.get_violations())
if number_of_violations > 0:
exitCode = 1
if settings.verify:
sys.exit(exitCode)
if settings.show_summary:
print("\nMISRA rules violations found:\n\t%s\n" % (
"\n\t".join(["%s: %d" % (viol, len(checker.get_violations(viol))) for viol in
checker.get_violation_types()])))
number_of_violations = len(checker.get_violations())
if number_of_violations > 0:
if settings.show_summary:
print("\nMISRA rules violations found:\n\t%s\n" % (
"\n\t".join(["%s: %d" % (viol, len(checker.get_violations(viol))) for viol in
checker.get_violation_types()])))
rules_violated = {}
for severity, ids in checker.get_violations():
for misra_id in ids:
rules_violated[misra_id] = rules_violated.get(misra_id, 0) + 1
print("MISRA rules violated:")
convert = lambda text: int(text) if text.isdigit() else text
misra_sort = lambda key: [convert(c) for c in re.split(r'[\.-]([0-9]*)', key)]
for misra_id in sorted(rules_violated.keys(), key=misra_sort):
res = re.match(r'misra-c2012-([0-9]+)\\.([0-9]+)', misra_id)
if res is None:
num = 0
else:
num = int(res.group(1)) * 100 + int(res.group(2))
severity = '-'
if num in checker.ruleTexts:
severity = checker.ruleTexts[num].cppcheck_severity
print("\t%15s (%s): %d" % (misra_id, severity, rules_violated[misra_id]))
rules_violated = {}
for severity, ids in checker.get_violations():
for misra_id in ids:
rules_violated[misra_id] = rules_violated.get(misra_id, 0) + 1
print("MISRA rules violated:")
convert = lambda text: int(text) if text.isdigit() else text
misra_sort = lambda key: [convert(c) for c in re.split(r'[\.-]([0-9]*)', key)]
for misra_id in sorted(rules_violated.keys(), key=misra_sort):
res = re.match(r'misra-c2012-([0-9]+)\\.([0-9]+)', misra_id)
if res is None:
num = 0
else:
num = int(res.group(1)) * 100 + int(res.group(2))
severity = '-'
if num in checker.ruleTexts:
severity = checker.ruleTexts[num].cppcheck_severity
print("\t%15s (%s): %d" % (misra_id, severity, rules_violated[misra_id]))
if args.show_suppressed_rules:
checker.showSuppressedRules()
sys.exit(exitCode)
if __name__ == '__main__':
main()
sys.exit(cppcheckdata.EXIT_CODE)

View File

@ -87,3 +87,5 @@ for arg in sys.argv[1:]:
if not res:
reportError(
scope.bodyStart, 'style', 'Function ' + scope.className + ' violates naming convention', 'functionName')
sys.exit(cppcheckdata.EXIT_CODE)

View File

@ -249,4 +249,5 @@ if __name__ == "__main__":
if len(errors):
print('Found errors: {}'.format(len(errors)))
sys.exit(1)
sys.exit(0)

View File

@ -34,3 +34,5 @@ for arg in sys.argv[1:]:
for cfg in data.iterconfigurations():
print('Checking %s, config %s...' % (arg, cfg.name))
checkstatic(cfg)
sys.exit(cppcheckdata.EXIT_CODE)

View File

@ -243,17 +243,9 @@ if __name__ == '__main__':
sys.exit(0)
for dumpfile in args.dumpfile:
if not os.path.isfile(dumpfile):
print("Error: File not found: %s" % dumpfile)
sys.exit(127)
if not os.access(dumpfile, os.R_OK):
print("Error: Permission denied: %s" % dumpfile)
sys.exit(13)
if not args.quiet:
print('Checking ' + dumpfile + '...')
y2038safe = check_y2038_safe(dumpfile, quiet)
if not y2038safe and exit_code == 0:
exit_code = 1
check_y2038_safe(dumpfile, quiet)
sys.exit(exit_code)
sys.exit(cppcheckdata.EXIT_CODE)