From 2ab67595b9e10b896e3b4eecaefd396022c0f9da Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Fri, 16 Aug 2024 11:06:20 -0700 Subject: [PATCH] Continue on template decode errors (#3605) * Continue on template decode errors --- src/cfnlint/runner.py | 9 ++--- test/unit/module/runner/test_run.py | 55 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 test/unit/module/runner/test_run.py diff --git a/src/cfnlint/runner.py b/src/cfnlint/runner.py index 706fe84309..442ff91b24 100644 --- a/src/cfnlint/runner.py +++ b/src/cfnlint/runner.py @@ -293,12 +293,9 @@ def _validate_filenames(self, filenames: Sequence[str | None]) -> Iterator[Match "E0000".startswith(x) for x in self.config.ignore_checks ): matches = [match for match in matches if match.rule.id != "E0000"] - if matches: - yield from iter(matches) - return - else: - yield from iter(matches) - return + + yield from iter(matches) + continue yield from self.validate_template(filename, template) # type: ignore[arg-type] # noqa: E501 def validate_template( diff --git a/test/unit/module/runner/test_run.py b/test/unit/module/runner/test_run.py new file mode 100644 index 0000000000..06d7734e1b --- /dev/null +++ b/test/unit/module/runner/test_run.py @@ -0,0 +1,55 @@ +""" +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +SPDX-License-Identifier: MIT-0 +""" + +import pytest + +from cfnlint.config import ConfigMixIn +from cfnlint.runner import Runner + + +@pytest.mark.parametrize( + "name,config,expected_count", + [ + ( + "Test decode errors with multiple files", + ConfigMixIn( + cli_args=[ + "--template", + "test/fixtures/templates/bad/duplicate.yaml", + "test/fixtures/templates/bad/duplicate.json", + ] + ), + 6, + ), + ( + "Test decode errors with E0000 being ignored", + ConfigMixIn( + cli_args=[ + "--template", + "test/fixtures/templates/bad/core/parse_invalid_map.yaml", + "--ignore-bad-template", + ] + ), + 0, + ), + ( + "Test decode return E0000 errors", + ConfigMixIn( + cli_args=[ + "--template", + "test/fixtures/templates/bad/core/parse_invalid_map.yaml", + ] + ), + 1, + ), + ], +) +def test_run(name, config, expected_count): + + runner = Runner(config) + + errs = list(runner.run()) + + assert len(errs) == expected_count, f"{name}: {errs}"