Skip to content

Commit

Permalink
Merge pull request Ericsson#4081 from Szelethus/report_converter_no_i…
Browse files Browse the repository at this point in the history
…nputs

[report-converter] Check whether input paths exist
  • Loading branch information
bruntib authored Nov 20, 2023
2 parents 262a78f + c2dfb43 commit 83e8b6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tools/report-converter/codechecker_report_converter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,19 @@ def __call__(

all_files = []

had_nonexistent_path = False
for path in values:
if os.path.isfile(path):
if not os.path.exists(path):
LOG.error(f"File or directory '{path}' does not exist!")
had_nonexistent_path = True
elif os.path.isfile(path):
all_files.append(path)
else:
for root, _, files in os.walk(path):
all_files.extend(os.path.join(root, f) for f in files)
if had_nonexistent_path:
sys.exit(1)
assert all_files

setattr(namespace, 'input', all_files)

Expand Down
12 changes: 12 additions & 0 deletions tools/report-converter/tests/functional/cmdline/test_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def test_help(self):
stderr=subprocess.PIPE)
self.assertEqual(0, ret)

def test_nonexistent_file(self):
""" Get help for report-converter tool. """
process = subprocess.Popen(['report-converter', '-t', 'gcc',
'-o', 'reports/', 'non_existent.sarif'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
universal_newlines=True)
out, _ = process.communicate()
self.assertIn("'non_existent.sarif' does not exist", out)
self.assertEqual(1, process.returncode)

def test_metadata(self):
""" Generate metadata for CodeChecker server. """
analyzer_version = "x.y.z"
Expand Down

0 comments on commit 83e8b6f

Please sign in to comment.