Skip to content

Commit

Permalink
Add a run-with Makefile function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ingydotnet committed Jan 29, 2023
1 parent 8f65cdc commit 1bee088
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .setup.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1bee088

Please sign in to comment.