From 1bee0885334c095383850478563521b86cfeb7e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingy=20d=C3=B6t=20Net?= Date: Sat, 28 Jan 2023 22:36:27 -0500 Subject: [PATCH] Add a run-with Makefile function The run-with function checks to make sure that the runner command is installed before running the test. If not installed it issues a warning message. It used to just fail, which causes all of `make test` to fail. Also before there where lines to check if shellcheck and yamllint were installed. They printed a msg but did not stop the commands from attempting to run only to obviously fail for not being installed. There was no previous check for py.test which was always failing for me since I didn't have it installed. Now when something isn't installed that test is just skipped with an explanation message. --- .setup.mk | 6 ++++++ Makefile | 14 ++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.setup.mk b/.setup.mk index 264b9ffe..2f4b1174 100644 --- a/.setup.mk +++ b/.setup.mk @@ -3,6 +3,12 @@ SHELL := bash .DELETE_ON_ERROR: .SECONDEXPANSION: +define run-with +$(if $(shell command -v $1), \ +$3, \ +$(warning WARNING: Can't 'make $2'. No '$1' command found.)) +endef + ifeq (,$(shell git diff --stat)) GIT_STATUS_IS_CLEAN := 1 endif diff --git a/Makefile b/Makefile index bf32aec2..e7da057e 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,12 @@ test: checkstyle test-unit test-unit: test-bash test-python test-bash: $(BPAN) - prove -r $(if $v,-v )$(test) + $(call run-with,prove,$@,\ + prove -r $(if $v,-v )$(test)) test-python: - py.test tests + $(call run-with,py.test,$@,\ + py.test tests) test-online: cat ./tests/incompletes | env dry_run=1 bash -ex ./openqa-label-known-issues-multi @@ -34,12 +36,12 @@ test-online: checkstyle: test-shellcheck test-yaml test-shellcheck: - @which shellcheck >/dev/null 2>&1 || echo "Command 'shellcheck' not found, can not execute shell script checks" - shellcheck -x $$(file --mime-type * | sed -n 's/^\(.*\):.*text\/x-shellscript.*$$/\1/p') + $(call run-with,shellcheck,$@,\ + shellcheck -x $$(file --mime-type * | sed -n 's/^\(.*\):.*text\/x-shellscript.*$$/\1/p')) test-yaml: - @which yamllint >/dev/null 2>&1 || echo "Command 'yamllint' not found, can not execute YAML syntax checks" - yamllint --strict $$(git ls-files "*.yml" "*.yaml" ":!external/") + $(call run-with,yamllint,$@,\ + yamllint --strict $$(git ls-files "*.yml" "*.yaml" ":!external/")) update-deps: tools/update-deps --specfile dist/rpm/os-autoinst-scripts-deps.spec