parent
709061ba54
commit
5d58b14db8
|
@ -2083,13 +2083,12 @@ class MisraChecker:
|
|||
errmsg = self.ruleTexts[ruleNum].text
|
||||
if self.ruleTexts[ruleNum].misra_severity:
|
||||
misra_severity = self.ruleTexts[ruleNum].misra_severity
|
||||
errmsg += ''.join((' (', self.ruleTexts[ruleNum].misra_severity, ')'))
|
||||
cppcheck_severity = self.ruleTexts[ruleNum].cppcheck_severity
|
||||
elif len(self.ruleTexts) == 0:
|
||||
errmsg = 'misra violation (use --rule-texts=<file> to get proper output)'
|
||||
else:
|
||||
return
|
||||
cppcheckdata.reportError(location, cppcheck_severity, errmsg, 'misra', errorId)
|
||||
cppcheckdata.reportError(location, cppcheck_severity, errmsg, 'misra', errorId, misra_severity)
|
||||
|
||||
if not misra_severity in self.violations:
|
||||
self.violations[misra_severity] = []
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# python -m pytest addons/test/test-misra.py
|
||||
import json
|
||||
import pytest
|
||||
import sys
|
||||
try:
|
||||
|
@ -101,6 +102,33 @@ def test_rules_misra_severity(checker):
|
|||
assert(checker.ruleTexts[2104].misra_severity == '')
|
||||
|
||||
|
||||
def test_extra_output_from_misra_py(checker):
|
||||
# Extra data generated by misra.py addon are available only through --cli option.
|
||||
checker.loadRuleTexts("./addons/test/assets/misra_rules_dummy.txt")
|
||||
with CapturingStderr() as output:
|
||||
checker.parseDump("./addons/test/misra-test.c.dump")
|
||||
captured = ''.join(output.captured)
|
||||
assert("Mandatory" in captured)
|
||||
assert("Required" in captured)
|
||||
assert("Advisory" in captured)
|
||||
|
||||
sys.argv.append("--cli")
|
||||
checker.loadRuleTexts("./addons/test/assets/misra_rules_dummy.txt")
|
||||
with CapturingStdout() as output:
|
||||
checker.parseDump("./addons/test/misra-test.c.dump")
|
||||
sys.argv.remove("--cli")
|
||||
json_output = {}
|
||||
for line in output.captured:
|
||||
try:
|
||||
json_line = json.loads(line)
|
||||
json_output[json_line['errorId']] = json_line
|
||||
except ValueError:
|
||||
pass
|
||||
assert("Mandatory" in json_output['c2012-10.4']['extra'])
|
||||
assert("Required" in json_output['c2012-21.3']['extra'])
|
||||
assert("Advisory" in json_output['c2012-20.1']['extra'])
|
||||
|
||||
|
||||
def test_rules_cppcheck_severity(checker):
|
||||
checker.loadRuleTexts("./addons/test/assets/misra_rules_dummy.txt")
|
||||
with CapturingStderr() as output:
|
||||
|
|
Loading…
Reference in New Issue