diff --git a/docs/releases.rst b/docs/releases.rst index 741ff72894..1d3ee3002e 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -12,6 +12,9 @@ The :ref:`/plugins/provision/beaker` provision plugin gains support for :ref:`system.model-name` and :ref:`system.vendor-name` hardware requirements. +The ``tmt lint`` command now reports a failure if empty +environment files are found. + tmt-1.38.0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/lint/plan/data/empty_env b/tests/lint/plan/data/empty_env new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/lint/plan/data/empty_env_file.fmf b/tests/lint/plan/data/empty_env_file.fmf new file mode 100644 index 0000000000..1dde6b5d9d --- /dev/null +++ b/tests/lint/plan/data/empty_env_file.fmf @@ -0,0 +1,5 @@ +summary: Empty environment file plan +environment-file: + - empty_env +execute: + script: tmt --help diff --git a/tests/lint/plan/data/env b/tests/lint/plan/data/env new file mode 100644 index 0000000000..38fac2f997 --- /dev/null +++ b/tests/lint/plan/data/env @@ -0,0 +1 @@ +test=test diff --git a/tests/lint/plan/data/good.fmf b/tests/lint/plan/data/good.fmf index c7cb77f0d9..c161e9a6b2 100644 --- a/tests/lint/plan/data/good.fmf +++ b/tests/lint/plan/data/good.fmf @@ -2,3 +2,5 @@ summary: Basic smoke test execute: script: tmt --help id: 9c73e336-983e-4349-9586-b63c20ea2b89 +environment-file: + - env diff --git a/tests/lint/plan/test.sh b/tests/lint/plan/test.sh index 5ac4191fe1..40edd9537a 100755 --- a/tests/lint/plan/test.sh +++ b/tests/lint/plan/test.sh @@ -50,6 +50,7 @@ rlJournalStart rlRun -s "$tmt plan lint invalid_url" 1 rlAssertGrep "fail P005 remote fmf id in \"default-0\" is invalid, repo 'http://invalid-url' cannot be cloned" $rlRun_LOG + rlAssertGrep "skip P008 no environment files found" $rlRun_LOG rlRun -s "$tmt plan lint invalid_ref" 1 rlAssertGrep "fail P005 remote fmf id in \"default-0\" is invalid, git ref 'invalid-ref-123456' is invalid" $rlRun_LOG @@ -71,6 +72,9 @@ rlJournalStart rlRun -s "$tmt plan lint invalid-plugin-key" 0 rlAssertGrep 'warn C000 key "wrong" not recognized by schema$' $rlRun_LOG rlAssertGrep 'warn C000 key "wrong" not recognized by schema /schemas/prepare/feature' $rlRun_LOG + + rlRun -s "$tmt plan lint empty_env_file" 1 + rlAssertGrep "fail P008 the environment file '.*/tests/lint/plan/data/empty_env' is empty" $rlRun_LOG rlPhaseEnd rlPhaseStartTest "P007: step phases require existing guests and roles" diff --git a/tmt/base.py b/tmt/base.py index 1b33a7d914..d347d42364 100644 --- a/tmt/base.py +++ b/tmt/base.py @@ -2347,6 +2347,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: environment 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 = (self.anchor_path / Path(env_file)).resolve() + if not env_file.stat().st_size: + yield LinterOutcome.FAIL, f"the environment file '{env_file}' is empty" + return + + yield LinterOutcome.PASS, 'no empty environment files' + def wake(self) -> None: """ Wake up all steps """