Skip to content

Commit

Permalink
Adds new lint function for empty env files
Browse files Browse the repository at this point in the history
New function that raises a failure if the size of
the environment file, if this one exists, is zero.

Signed-off-by: mcasquer <[email protected]>
  • Loading branch information
mcasquer committed Oct 2, 2024
1 parent dab0f36 commit 62aa444
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ The :ref:`/plugins/report/reportportal` plugin now uploads the
complete set of discovered tests, including those which have not
been executed. These tests are marked as ``skipped``.

``tmt lint`` now reports a failure if empty environment files are found.


tmt-1.36.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
17 changes: 17 additions & 0 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,23 @@ def _lint_step(step: str) -> LinterReturn:
yield from _lint_step('execute')
yield from _lint_step('finish')

def lint_empty_env_files(self) -> LinterReturn:
""" P008: env files are not empty """

env_files = self.node.get("environment-file") or []

if not env_files:
yield LinterOutcome.SKIP, 'no environment files found'
return

for env_file in env_files:
env_file = Path(env_file).resolve()
if not env_file.stat().st_size:
yield LinterOutcome.FAIL, f'the file "{env_file}" is empty'
return

yield LinterOutcome.PASS, 'no empty environment files'

def wake(self) -> None:
""" Wake up all steps """

Expand Down

0 comments on commit 62aa444

Please sign in to comment.