Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions htmlreport/cppcheck-htmlreport
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ def main() -> None:
'from. You can combine results from several '
'xml reports i.e. "--file file1.xml --file file2.xml ..". '
'Default is reading from stdin.')
parser.add_option('--checkers-report-file', dest='checkers_report',
help='The cppcheck checkers report file as produced '
'with the "--checkers-report" option of cppcheck.')
parser.add_option('--report-dir', dest='report_dir',
help='The directory where the HTML report content is '
'written.')
Expand Down Expand Up @@ -855,6 +858,8 @@ def main() -> None:
output_file.write('\n <tr><td></td><td>' + str(stats_count) + '</td><td>total</td></tr>')
output_file.write('\n </table>')
output_file.write('\n <p><a href="stats.html">Statistics</a></p>')
if options.checkers_report:
output_file.write('\n <p><a href="checkers.html">Checkers</a></p>')
output_file.write(HTML_MENU_END.replace("content", "content_index", 1))

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

stats_file.write(HTML_FOOTER % contentHandler.versionCppcheck)

if options.checkers_report:
print("Creating checkers.html (checkers report)\n")

with io.open(os.path.join(options.report_dir, 'checkers.html'), 'w') as checkers_file:

checkers_file.write(HTML_HEAD % (options.title, '', options.title, ': Checkers'))
checkers_file.write(HTML_HEAD_END)

checkers_file.write(HTML_MENU.replace('id="menu"', 'id="menu_index"', 1).replace("Defects:", "Back to summary", 1) % (''))
checkers_file.write(HTML_MENU_END.replace("content", "content_index", 1))

with io.open(options.checkers_report, 'r', encoding=options.source_encoding) as checkers_report:
content = checkers_report.read()

checkers_file.write("<pre>\n")
checkers_file.write(html_escape(content))
checkers_file.write("</pre>\n")

checkers_file.write(HTML_FOOTER % contentHandler.versionCppcheck)

print("\nOpen '" + options.report_dir + "/index.html' to see the results.")


Expand Down
1 change: 1 addition & 0 deletions test/tools/htmlreport/example-checkers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Just a few random words..
26 changes: 22 additions & 4 deletions test/tools/htmlreport/test_htmlreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,23 @@ def testMissingInclude(self):

output_directory.cleanup()

def testAddCheckersReport(self):
with runCheck(
xml_filename=os.path.join(TEST_TOOLS_DIR, 'example.xml'),
checkers_filename=os.path.join(TEST_TOOLS_DIR, 'example-checkers.txt')
) as (report, output_directory):
self.assertIn('<html', report)

self.assertIn('<a href="checkers.html"', report)

self.assertTrue(
os.path.exists(os.path.join(output_directory.name, 'checkers.html')))

output_directory.cleanup()


@contextlib.contextmanager
def runCheck(source_filename=None, xml_version='1', xml_filename=None):
def runCheck(source_filename=None, xml_version='1', xml_filename=None, checkers_filename=None):
"""Run cppcheck and cppcheck-htmlreport.

Yield a tuple containing the resulting HTML report index and the directory
Expand All @@ -102,10 +116,14 @@ def runCheck(source_filename=None, xml_version='1', xml_filename=None):

assert os.path.exists(xml_filename)

subprocess.check_call(
[*HTML_REPORT_BIN,
args = [*HTML_REPORT_BIN,
'--file=' + os.path.realpath(xml_filename),
'--report-dir=' + os.path.realpath(output_directory.name)],
'--report-dir=' + os.path.realpath(output_directory.name)]
if checkers_filename:
args.append('--checkers-report-file=' + os.path.realpath(checkers_filename))

subprocess.check_call(
args,
cwd=TEST_TOOLS_DIR)

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