From b5890c4f0a02d58fd2037e5b61ae83960b0aa456 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 --- docs/releases.rst | 6 ++++++ tests/lint/plan/data/empty_env | 0 tests/lint/plan/data/empty_env_file.fmf | 5 +++++ tests/lint/plan/data/env | 1 + tests/lint/plan/data/good.fmf | 2 ++ tests/lint/plan/test.sh | 4 ++++ tmt/base.py | 17 +++++++++++++++++ 7 files changed, 35 insertions(+) create mode 100644 tests/lint/plan/data/empty_env create mode 100644 tests/lint/plan/data/empty_env_file.fmf create mode 100644 tests/lint/plan/data/env diff --git a/docs/releases.rst b/docs/releases.rst index 0b62eec8f3..707ddbc104 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -4,6 +4,12 @@ Releases ====================== +tmt-1.38.0 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +``tmt lint`` now reports a failure if empty environment files are found. + + tmt-1.37.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..a958df576d --- /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..8aacb00747 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 file \"$(pwd)/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 c7350fc70f..5325291496 100644 --- a/tmt/base.py +++ b/tmt/base.py @@ -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 """