From 8480c51cbe1d9c73133249ce5c971a13384b0d97 Mon Sep 17 00:00:00 2001 From: Nora Zinaeddin Date: Thu, 28 Mar 2024 14:41:08 +0100 Subject: [PATCH 1/2] Do not allow parse if the does not exist This change prevents the CodeChecker parse command from running if the entered report dir or filepath parameter does not exist. Up until now, the parse command ran with any parameters, reporting zero findings if a wrong parameter was entered. Fixes #4186 --- analyzer/codechecker_analyzer/cmd/parse.py | 8 ++++++++ analyzer/tests/functional/cmdline/test_cmdline.py | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/analyzer/codechecker_analyzer/cmd/parse.py b/analyzer/codechecker_analyzer/cmd/parse.py index 64c6e35353..f9bd1fcb56 100644 --- a/analyzer/codechecker_analyzer/cmd/parse.py +++ b/analyzer/codechecker_analyzer/cmd/parse.py @@ -283,6 +283,14 @@ def main(args): LOG.error(fnerr) sys.exit(1) + incorrect_input_paths = [input_path for input_path in args.input + if not os.path.exists(input_path)] + + if incorrect_input_paths: + for input_path in incorrect_input_paths: + LOG.error(f"Input path {input_path} does not exist!") + sys.exit(1) + export = args.export if 'export' in args else None if export == 'html' and 'output_path' not in args: LOG.error("Argument --export not allowed without argument --output " diff --git a/analyzer/tests/functional/cmdline/test_cmdline.py b/analyzer/tests/functional/cmdline/test_cmdline.py index a3408dd131..d186214943 100644 --- a/analyzer/tests/functional/cmdline/test_cmdline.py +++ b/analyzer/tests/functional/cmdline/test_cmdline.py @@ -250,6 +250,17 @@ def test_analyzer_config(self): self.assertTrue(desc) self.assertFalse(desc[0].islower()) + def test_parse_incorrect_file_path(self): + """ + This test checks whether the parse command stops running if a + non-existent path is specified. + """ + + parse_cmd = [env.codechecker_cmd(), 'parse', '/asd/123/qwe'] + + self.assertIn('Input path /asd/123/qwe does not exist!', + run_cmd(parse_cmd)[1]) + def test_checker_config_format(self): """ Test if checker config option is meeting the reqired format. From 932a25c0643029bf40e710fe0bbf60550f94783f Mon Sep 17 00:00:00 2001 From: Nora Zn Date: Thu, 25 Apr 2024 12:02:23 +0200 Subject: [PATCH 2/2] Update test_cmdline.py --- analyzer/tests/functional/cmdline/test_cmdline.py | 1 - 1 file changed, 1 deletion(-) diff --git a/analyzer/tests/functional/cmdline/test_cmdline.py b/analyzer/tests/functional/cmdline/test_cmdline.py index d633fe051e..77b20520c4 100644 --- a/analyzer/tests/functional/cmdline/test_cmdline.py +++ b/analyzer/tests/functional/cmdline/test_cmdline.py @@ -250,7 +250,6 @@ def test_analyzer_config(self): self.assertTrue(desc) self.assertFalse(desc[0].islower()) - def test_parse_incorrect_file_path(self): """ This test checks whether the parse command stops running if a