Skip to content

Commit

Permalink
[cmd] Fix html generation for report directory without plists
Browse files Browse the repository at this point in the history
Fix HTML generation for report directory which doesn't contain any
analyzer result (plist) file.
  • Loading branch information
csordasmarton committed Feb 24, 2022
1 parent 9a944f8 commit 5a5060a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
12 changes: 6 additions & 6 deletions analyzer/codechecker_analyzer/cmd/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,14 @@ def get_output_file_path(default_file_name: str) -> Optional[str]:
changed_files: Set[str] = set()
processed_path_hashes = set()
processed_file_paths = set()
html_builder: Optional[report_to_html.HtmlBuilder] = None
print_steps = 'print_steps' in args

html_builder: Optional[report_to_html.HtmlBuilder] = None
if export == 'html':
html_builder = report_to_html.HtmlBuilder(
context.path_plist_to_html_dist,
context.checker_labels)

for dir_path, file_paths in report_file.analyzer_result_files(args.input):
metadata = get_metadata(dir_path)
for file_path in file_paths:
Expand Down Expand Up @@ -427,11 +432,6 @@ def get_output_file_path(default_file_name: str) -> Optional[str]:
plaintext.convert(
file_report_map, processed_file_paths, print_steps)
elif export == 'html':
if not html_builder:
html_builder = report_to_html.HtmlBuilder(
context.path_plist_to_html_dist,
context.checker_labels)

print(f"Parsing input file '{file_path}'.")
report_to_html.convert(
file_path, reports, output_dir_path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,25 @@ def test_html_output_for_macros(self):
self.assertTrue('Summary' in out)
self.assertTrue('Statistics' in out)

def test_html_output_for_empty_dir(self):
""" Test parse HTML output for an empty directory. """
with tempfile.TemporaryDirectory() as tmp_dir:
output_path = os.path.join(self.test_workspaces['OUTPUT'], 'html')
extract_cmd = [
'CodeChecker', 'parse',
'-e', 'html',
'-o', output_path,
tmp_dir]

out, err, result = call_command(
extract_cmd, cwd=self.test_dir, env=self.env)
self.assertEqual(result, 0)
self.assertFalse(err)

self.assertTrue('Summary' in out)
self.assertFalse('Html file was generated' in out)
self.assertFalse('Statistics' in out)

def test_codeclimate_export(self):
""" Test exporting codeclimate output. """
test_project_notes = os.path.join(self.test_workspaces['NORMAL'],
Expand Down

0 comments on commit 5a5060a

Please sign in to comment.