Skip to content

Commit e3dceac

Browse files
authored
Optionally list checkers in html report (danmar#7031)
1 parent d7c8ad3 commit e3dceac

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

htmlreport/cppcheck-htmlreport

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ def main() -> None:
628628
'from. You can combine results from several '
629629
'xml reports i.e. "--file file1.xml --file file2.xml ..". '
630630
'Default is reading from stdin.')
631+
parser.add_option('--checkers-report-file', dest='checkers_report',
632+
help='The cppcheck checkers report file as produced '
633+
'with the "--checkers-report" option of cppcheck.')
631634
parser.add_option('--report-dir', dest='report_dir',
632635
help='The directory where the HTML report content is '
633636
'written.')
@@ -855,6 +858,8 @@ def main() -> None:
855858
output_file.write('\n <tr><td></td><td>' + str(stats_count) + '</td><td>total</td></tr>')
856859
output_file.write('\n </table>')
857860
output_file.write('\n <p><a href="stats.html">Statistics</a></p>')
861+
if options.checkers_report:
862+
output_file.write('\n <p><a href="checkers.html">Checkers</a></p>')
858863
output_file.write(HTML_MENU_END.replace("content", "content_index", 1))
859864

860865
output_file.write('\n <table class=\"summaryTable\">')
@@ -983,6 +988,26 @@ def main() -> None:
983988

984989
stats_file.write(HTML_FOOTER % contentHandler.versionCppcheck)
985990

991+
if options.checkers_report:
992+
print("Creating checkers.html (checkers report)\n")
993+
994+
with io.open(os.path.join(options.report_dir, 'checkers.html'), 'w') as checkers_file:
995+
996+
checkers_file.write(HTML_HEAD % (options.title, '', options.title, ': Checkers'))
997+
checkers_file.write(HTML_HEAD_END)
998+
999+
checkers_file.write(HTML_MENU.replace('id="menu"', 'id="menu_index"', 1).replace("Defects:", "Back to summary", 1) % (''))
1000+
checkers_file.write(HTML_MENU_END.replace("content", "content_index", 1))
1001+
1002+
with io.open(options.checkers_report, 'r', encoding=options.source_encoding) as checkers_report:
1003+
content = checkers_report.read()
1004+
1005+
checkers_file.write("<pre>\n")
1006+
checkers_file.write(html_escape(content))
1007+
checkers_file.write("</pre>\n")
1008+
1009+
checkers_file.write(HTML_FOOTER % contentHandler.versionCppcheck)
1010+
9861011
print("\nOpen '" + options.report_dir + "/index.html' to see the results.")
9871012

9881013

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Just a few random words..

test/tools/htmlreport/test_htmlreport.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,23 @@ def testMissingInclude(self):
8080

8181
output_directory.cleanup()
8282

83+
def testAddCheckersReport(self):
84+
with runCheck(
85+
xml_filename=os.path.join(TEST_TOOLS_DIR, 'example.xml'),
86+
checkers_filename=os.path.join(TEST_TOOLS_DIR, 'example-checkers.txt')
87+
) as (report, output_directory):
88+
self.assertIn('<html', report)
89+
90+
self.assertIn('<a href="checkers.html"', report)
91+
92+
self.assertTrue(
93+
os.path.exists(os.path.join(output_directory.name, 'checkers.html')))
94+
95+
output_directory.cleanup()
96+
8397

8498
@contextlib.contextmanager
85-
def runCheck(source_filename=None, xml_version='1', xml_filename=None):
99+
def runCheck(source_filename=None, xml_version='1', xml_filename=None, checkers_filename=None):
86100
"""Run cppcheck and cppcheck-htmlreport.
87101
88102
Yield a tuple containing the resulting HTML report index and the directory
@@ -102,10 +116,14 @@ def runCheck(source_filename=None, xml_version='1', xml_filename=None):
102116

103117
assert os.path.exists(xml_filename)
104118

105-
subprocess.check_call(
106-
[*HTML_REPORT_BIN,
119+
args = [*HTML_REPORT_BIN,
107120
'--file=' + os.path.realpath(xml_filename),
108-
'--report-dir=' + os.path.realpath(output_directory.name)],
121+
'--report-dir=' + os.path.realpath(output_directory.name)]
122+
if checkers_filename:
123+
args.append('--checkers-report-file=' + os.path.realpath(checkers_filename))
124+
125+
subprocess.check_call(
126+
args,
109127
cwd=TEST_TOOLS_DIR)
110128

111129
with open(os.path.join(output_directory.name, 'index.html')) as index_file:

0 commit comments

Comments
 (0)