Skip to content

Commit

Permalink
Ensure we return error if argument gives are not present
Browse files Browse the repository at this point in the history
Fixes: #3466
  • Loading branch information
ssbarnea committed May 20, 2023
1 parent 691c880 commit b1f1fa5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 798
PYTEST_REQPASS: 799
steps:
- name: Activate WSL1
if: "contains(matrix.shell, 'wsl')"
Expand Down
10 changes: 10 additions & 0 deletions src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ def _run(self) -> list[MatchError]: # noqa: C901
),
)
lintable.stop_processing = True
# identify missing files/folders
if not lintable.path.exists():
matches.append(
MatchError(
lintable=lintable,
message="File or found not found.",
rule=LoadingFailureRule(),
tag="load-failure[not-found]",
),
)

# -- phase 1 : syntax check in parallel --
def worker(lintable: Lintable) -> list[MatchError]:
Expand Down
17 changes: 17 additions & 0 deletions test/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,20 @@ def test_files_not_scanned_twice(default_rules_collection: RulesCollection) -> N
# this second run should return 0 because the included filed was already
# processed and added to checked_files, which acts like a bypass list.
assert len(run2) == 0


def test_runner_not_found(default_rules_collection: RulesCollection) -> None:
"""Ensure that lintables aren't double-checked."""
checked_files: set[Lintable] = set()

filename = Path("this/folder/does/not/exist").resolve()
runner = Runner(
filename,
rules=default_rules_collection,
verbosity=0,
checked_files=checked_files,
)
result = runner.run()
assert len(runner.checked_files) == 1
assert len(result) == 1
assert result[0].tag == "load-failure[not-found]"

0 comments on commit b1f1fa5

Please sign in to comment.