From ce34c2c91b17e027bbb6114110bfa2699ff7d56d Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Tue, 15 Mar 2022 08:39:15 +0000 Subject: [PATCH] Change invalid config return code to 3 (#2005) As current tool behavior was to use the same exit code (2) for both found errors or invalid config, we change the later one to 3, so users can easily differentiate. --- src/ansiblelint/app.py | 5 +++-- src/ansiblelint/constants.py | 4 +++- test/test_commandline_invocations_same_as_config.py | 4 ++-- test/test_utils.py | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ansiblelint/app.py b/src/ansiblelint/app.py index 077201d5f9..41893d0df1 100644 --- a/src/ansiblelint/app.py +++ b/src/ansiblelint/app.py @@ -10,6 +10,7 @@ from ansiblelint._mockings import _perform_mockings from ansiblelint.color import console, console_stderr, render_yaml from ansiblelint.config import options as default_options +from ansiblelint.constants import SUCCESS_RC, VIOLATIONS_FOUND_RC from ansiblelint.errors import MatchError if TYPE_CHECKING: @@ -170,8 +171,8 @@ def report_outcome( ) if mark_as_success or not failures: - return 0 - return 2 + return SUCCESS_RC + return VIOLATIONS_FOUND_RC def choose_formatter_factory( diff --git a/src/ansiblelint/constants.py b/src/ansiblelint/constants.py index 079b9040ce..2327adb29f 100644 --- a/src/ansiblelint/constants.py +++ b/src/ansiblelint/constants.py @@ -12,7 +12,9 @@ DEFAULT_RULESDIR = os.path.join(os.path.dirname(__file__), "rules") CUSTOM_RULESDIR_ENVVAR = "ANSIBLE_LINT_CUSTOM_RULESDIR" -INVALID_CONFIG_RC = 2 +SUCCESS_RC = 0 +VIOLATIONS_FOUND_RC = 2 +INVALID_CONFIG_RC = 3 EXIT_CONTROL_C_RC = 130 # Minimal version of Ansible we support for runtime diff --git a/test/test_commandline_invocations_same_as_config.py b/test/test_commandline_invocations_same_as_config.py index 7b50a007b9..7761f43457 100644 --- a/test/test_commandline_invocations_same_as_config.py +++ b/test/test_commandline_invocations_same_as_config.py @@ -127,8 +127,8 @@ def test_path_from_cli_depend_on_cwd( ), ) def test_config_failure(base_arguments: List[str], config_file: str) -> None: - """Ensures specific config files produce error code 2.""" - with pytest.raises(SystemExit, match="^2$"): + """Ensures specific config files produce error code 3.""" + with pytest.raises(SystemExit, match="^3$"): cli.get_config(base_arguments + ["-c", config_file]) diff --git a/test/test_utils.py b/test/test_utils.py index 3d02f738b7..0f8f0b3a74 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -38,6 +38,7 @@ from ansiblelint import cli, constants, utils from ansiblelint.__main__ import initialize_logger from ansiblelint.cli import get_rules_dirs +from ansiblelint.constants import VIOLATIONS_FOUND_RC from ansiblelint.file_utils import Lintable from ansiblelint.testing import run_ansible_lint @@ -246,8 +247,7 @@ def test_cli_auto_detect(capfd: CaptureFixture[str]) -> None: result = subprocess.run(cmd, check=False).returncode # We de expect to fail on our own repo due to test examples we have - # TODO(ssbarnea) replace it with exact return code once we document them - assert result != 0 + assert result == VIOLATIONS_FOUND_RC out, err = capfd.readouterr()