htmlreport: fix errors when unmatched suppressions are reported via --enable=information. Incorporate tests.
This commit is contained in:
parent
e38f15ecc0
commit
fad50de311
|
@ -25,3 +25,11 @@ echo ""
|
||||||
../cppcheck --errorlist --inconclusive --xml-version=2 > errorlist.xml
|
../cppcheck --errorlist --inconclusive --xml-version=2 > errorlist.xml
|
||||||
xmllint --noout errorlist.xml
|
xmllint --noout errorlist.xml
|
||||||
./cppcheck-htmlreport --file ./errorlist.xml --title "errorlist" --report-dir .
|
./cppcheck-htmlreport --file ./errorlist.xml --title "errorlist" --report-dir .
|
||||||
|
|
||||||
|
../cppcheck ../samples/memleak/good.c ../samples/resourceLeak/good.c --xml-version=2 --enable=information --suppressions-list=test_suppressions.txt --xml 2> unmatchedSuppr.xml
|
||||||
|
xmllint --noout unmatchedSuppr.xml
|
||||||
|
./cppcheck-htmlreport --file ./unmatchedSuppr.xml --title "unmatched Suppressions" --report-dir=.
|
||||||
|
grep "unmatchedSuppression<.*>information<.*>Unmatched suppression: variableScope*<" index.html
|
||||||
|
grep ">unmatchedSuppression</.*>information<.*>Unmatched suppression: uninitstring<" index.html
|
||||||
|
grep "notexisting" index.html
|
||||||
|
grep ">unmatchedSuppression<.*>information<.*>Unmatched suppression: \*<" index.html
|
||||||
|
|
|
@ -433,6 +433,9 @@ if __name__ == '__main__':
|
||||||
with io.open(source_filename, 'r', encoding=options.source_encoding) as input_file:
|
with io.open(source_filename, 'r', encoding=options.source_encoding) as input_file:
|
||||||
content = input_file.read()
|
content = input_file.read()
|
||||||
except IOError:
|
except IOError:
|
||||||
|
if (error['id'] == 'unmatchedSuppression'):
|
||||||
|
continue; # file not found, bail out
|
||||||
|
else:
|
||||||
sys.stderr.write("ERROR: Source file '%s' not found.\n" %
|
sys.stderr.write("ERROR: Source file '%s' not found.\n" %
|
||||||
source_filename)
|
source_filename)
|
||||||
continue
|
continue
|
||||||
|
@ -521,10 +524,16 @@ if __name__ == '__main__':
|
||||||
if filename in decode_errors: # don't print a link but a note
|
if filename in decode_errors: # don't print a link but a note
|
||||||
output_file.write("\n <tr><td colspan='4'>%s</td></tr>" % (filename))
|
output_file.write("\n <tr><td colspan='4'>%s</td></tr>" % (filename))
|
||||||
output_file.write("\n <tr><td colspan='4'> Could not generated due to UnicodeDecodeError</td></tr>")
|
output_file.write("\n <tr><td colspan='4'> Could not generated due to UnicodeDecodeError</td></tr>")
|
||||||
|
else:
|
||||||
|
if filename.endswith('*'): # assume unmatched suppression
|
||||||
|
output_file.write(
|
||||||
|
"\n <tr><td colspan='4'>%s</td></tr>" %
|
||||||
|
(filename))
|
||||||
else:
|
else:
|
||||||
output_file.write(
|
output_file.write(
|
||||||
"\n <tr><td colspan='4'><a href='%s'>%s</a></td></tr>" %
|
"\n <tr><td colspan='4'><a href='%s'>%s</a></td></tr>" %
|
||||||
(data['htmlfile'], filename))
|
(data['htmlfile'], filename))
|
||||||
|
|
||||||
for error in sorted(data['errors'], key=lambda k: k['line']):
|
for error in sorted(data['errors'], key=lambda k: k['line']):
|
||||||
error_class = ''
|
error_class = ''
|
||||||
try:
|
try:
|
||||||
|
@ -540,6 +549,11 @@ if __name__ == '__main__':
|
||||||
output_file.write(
|
output_file.write(
|
||||||
'\n <tr><td></td><td>%s</td><td>%s</td><td>%s</td></tr>' %
|
'\n <tr><td></td><td>%s</td><td>%s</td><td>%s</td></tr>' %
|
||||||
(error['id'], error['severity'], error['msg']))
|
(error['id'], error['severity'], error['msg']))
|
||||||
|
elif (error['id'] == 'unmatchedSuppression') and filename.endswith('*'):
|
||||||
|
output_file.write(
|
||||||
|
"\n <tr><td></td><td>%s</td><td>%s</td><td %s>%s</td></tr>" %
|
||||||
|
(error['id'], error['severity'], error_class,
|
||||||
|
error['msg']))
|
||||||
else:
|
else:
|
||||||
output_file.write(
|
output_file.write(
|
||||||
"\n <tr><td><a href='%s#line-%d'>%d</a></td><td>%s</td><td>%s</td><td %s>%s</td></tr>" %
|
"\n <tr><td><a href='%s#line-%d'>%d</a></td><td>%s</td><td>%s</td><td %s>%s</td></tr>" %
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
variableScope:../samples/memleak/good.c
|
||||||
|
*:../samples/resourceLeak/notexisting.c*
|
||||||
|
uninitstring:*
|
Loading…
Reference in New Issue