Reputation: 12730
My makefile:
.PHONY: test-unit test-functional mocha
test: test-unit test-functional
test-unit: SUITE = "unit"
test-unit: mocha
@echo "unit"
test-functional: SUITE = "functional"
test-functional: mocha
@echo "functional"
mocha:
@echo ===== RUNNING TESTS: $(SUITE) =====
I'd like to use this makefile to run both of my test suites without duplicating the code for what it takes to run a suite (abstracted into the mocha
task). However, Make is being smart and realizes that mocha
has already been run when it comes to test-functional
and doesn't run it again.
make test
:
===== RUNNING TESTS: unit =====
unit
functional
Is there a better way to approach this perhaps to achieve similar abstraction, or perhaps flag mocha
as needing to be run every time?
Upvotes: 2
Views: 397
Reputation: 130
I don't prefer the canned recipe approach for my application for reasons unimportant.
To solve this for myself, the prerequisite is a .PHONY and my harness-target calls each step as a sub-make:
dedupe-emails-1
and dedupe-emails-2
both depend on the same target which must be re-made.
run: create-views
$(MAKE) dedupe-emails-1
$(MAKE) dedupe-emails-2
$(MAKE) report-dupes.csv
Upvotes: 0
Reputation: 81032
Use a Canned Recipe for the body of the mocha
task and stick it in both test tasks.
Instead of
mocha:
@echo ===== RUNNING TESTS: $(SUITE) =====
test: mocha
use
define mocha
@echo ===== RUNNING TESTS: $(SUITE) =====
endef
test:
$(mocha)
....
define mocha =
(or :=
etc.) for make 4.0+ I believe.
Upvotes: 2