i have this simple rule:
.PHONY: test
test: src/*Test.php
$(PHPUNIT) $?;\
it will look trhu the unit tests i have and run phpunit.
I wanted to have something like: (warning, non-valid makefile syntax)
ifneq($(HAS_PHPUNIT),)
test: testok
else
test: testbad
endif
testok: src/*Test.php
$(PHPUNIT) $?;\
testbad:
echo "test: failed checking for executable file $(PHPUNIT)";\
echo " You may need to install phpunit";\
i could use the current code and just add if [ ! -e $(PHPUNIT) ]; then warn; else test it; done but then if will be overly verbose as it will warn the user once per file.
what’s the pattern i’m missing here?
The “make way” to do it is to make your one-time check a separate target itself, and list that as a prerequisite of the targets that you would like to only run after that check happens. Here’s one way you can do it with GNU make:
That is, make a dummy target for each test file that executes that set of tests, then make those targets depend on the
check_php_unittarget. The commands forcheck_php_unitcan do whatever validation you want and then print a warning, or exit with an error code and cause the make run to terminate, or whatever you like.