From fbf2a76be70e00382a3a14f9d0ccc17257ab8283 Mon Sep 17 00:00:00 2001 From: mcasquer Date: Wed, 11 Sep 2024 07:35:37 +0200 Subject: [PATCH] Adds new lint function for empty env files New function that raises a failure if the size of the environment file, if this one exists, is zero. Signed-off-by: mcasquer --- tmt/base.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tmt/base.py b/tmt/base.py index ee984bff15..c6ece92b78 100644 --- a/tmt/base.py +++ b/tmt/base.py @@ -2328,6 +2328,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 """