Misra severity (#2674)
This commit is contained in:
parent
43b30d974f
commit
2abf542838
|
@ -1057,10 +1057,12 @@ class MisraChecker:
|
|||
|
||||
self.stdversion = stdversion
|
||||
|
||||
self.severity = None
|
||||
|
||||
def __repr__(self):
|
||||
attrs = ["settings", "verify_expected", "verify_actual", "violations",
|
||||
"ruleTexts", "suppressedRules", "dumpfileSuppressions",
|
||||
"filePrefix", "suppressionStats", "stdversion"]
|
||||
"filePrefix", "suppressionStats", "stdversion", "severity"]
|
||||
return "{}({})".format(
|
||||
"MisraChecker",
|
||||
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
|
||||
|
@ -2675,6 +2677,12 @@ class MisraChecker:
|
|||
"""
|
||||
self.filePrefix = prefix
|
||||
|
||||
def setSeverity(self, severity):
|
||||
"""
|
||||
Set the severity for all errors.
|
||||
"""
|
||||
self.severity = severity
|
||||
|
||||
def setSuppressionList(self, suppressionlist):
|
||||
num1 = 0
|
||||
num2 = 0
|
||||
|
@ -2714,6 +2722,10 @@ class MisraChecker:
|
|||
errmsg = 'misra violation (use --rule-texts=<file> to get proper output)'
|
||||
else:
|
||||
return
|
||||
|
||||
if self.severity:
|
||||
cppcheck_severity = self.severity
|
||||
|
||||
cppcheckdata.reportError(location, cppcheck_severity, errmsg, 'misra', errorId, misra_severity)
|
||||
|
||||
if misra_severity not in self.violations:
|
||||
|
@ -3017,6 +3029,7 @@ def get_args():
|
|||
parser.add_argument("-P", "--file-prefix", type=str, help="Prefix to strip when matching suppression file rules")
|
||||
parser.add_argument("-generate-table", help=argparse.SUPPRESS, action="store_true")
|
||||
parser.add_argument("-verify", help=argparse.SUPPRESS, action="store_true")
|
||||
parser.add_argument("--severity", type=str, help="Set a custom severity string, for example 'error' or 'warning'. ")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
|
@ -3055,6 +3068,9 @@ def main():
|
|||
print("No input files.")
|
||||
sys.exit(0)
|
||||
|
||||
if args.severity:
|
||||
checker.setSeverity(args.severity)
|
||||
|
||||
exitCode = 0
|
||||
for item in args.dumpfile:
|
||||
checker.parseDump(item)
|
||||
|
|
|
@ -96,6 +96,15 @@ def test_rules_cppcheck_severity(checker, capsys):
|
|||
assert("(warning)" not in captured)
|
||||
assert("(style)" in captured)
|
||||
|
||||
def test_rules_cppcheck_severity_custom(checker, capsys):
|
||||
checker.loadRuleTexts("./addons/test/misra/misra_rules_dummy.txt")
|
||||
checker.setSeverity("custom-severity")
|
||||
checker.parseDump("./addons/test/misra/misra-test.c.dump")
|
||||
captured = capsys.readouterr().err
|
||||
assert("(error)" not in captured)
|
||||
assert("(warning)" not in captured)
|
||||
assert("(style)" not in captured)
|
||||
assert("(custom-severity)" in captured)
|
||||
|
||||
def test_rules_suppression(checker, capsys):
|
||||
test_sources = ["addons/test/misra/misra-suppressions1-test.c",
|
||||
|
@ -122,7 +131,8 @@ def test_arguments_regression():
|
|||
"--cli",
|
||||
"--no-summary",
|
||||
"--show-suppressed-rules",
|
||||
"-P=src/", "--file-prefix=src/"]
|
||||
"-P=src/", "--file-prefix=src/",
|
||||
"--severity=misra-warning"]
|
||||
# Arguments with expected SystemExit
|
||||
args_exit = ["--non-exists", "--non-exists-param=42", "-h", "--help"]
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import os
|
|||
def find_cppcheck_binary():
|
||||
possible_locations = [
|
||||
"./cppcheck",
|
||||
"./build/bin/cppcheck",
|
||||
r".\bin\cppcheck.exe",
|
||||
]
|
||||
for location in possible_locations:
|
||||
|
|
Loading…
Reference in New Issue