README: instructions on running tests.
[jackhill/mal.git] / Makefile
CommitLineData
31690700
JM
1#
2# Command line settings
3#
4
5MAL_IMPL = js
6
a05f7822
JM
7PYTHON = python
8
31690700
JM
9#
10# Settings
11#
12
b5dedee0 13IMPLS = bash c clojure cs java js make mal perl php ps python ruby
31690700
JM
14
15step0 = step0_repl
16step1 = step1_read_print
17step2 = step2_eval
18step3 = step3_env
19step4 = step4_if_fn_do
20step5 = step5_tco
21step6 = step6_file
22step7 = step7_quote
23step8 = step8_macros
24step9 = step9_interop
25stepA = stepA_more
26
17ae845e 27EXCLUDE_TESTS = test^make^step5 test^mal^step0 test^mal^step5 test^mal^step9 test^java^step9 test^cs^step9
db4c329a 28EXCLUDE_PERFS = perf^mal # TODO: fix this
31690700
JM
29
30#
31# Utility functions
32#
33
34STEP_TEST_FILES = $(strip $(wildcard $(1)/tests/$($(2)).mal) $(wildcard tests/$($(2)).mal))
35
db4c329a
JM
36bash_STEP_TO_PROG = bash/$($(1)).sh
37c_STEP_TO_PROG = c/$($(1))
31690700 38clojure_STEP_TO_PROG = clojure/src/$($(1)).clj
db4c329a
JM
39cs_STEP_TO_PROG = cs/$($(1)).exe
40java_STEP_TO_PROG = java/src/main/java/mal/$($(1)).java
41js_STEP_TO_PROG = js/$($(1)).js
42make_STEP_TO_PROG = make/$($(1)).mk
43mal_STEP_TO_PROG = mal/$($(1)).mal
b5dedee0 44perl_STEP_TO_PROG = perl/$($(1)).pl
db4c329a
JM
45php_STEP_TO_PROG = php/$($(1)).php
46ps_STEP_TO_PROG = ps/$($(1)).ps
47python_STEP_TO_PROG = python/$($(1)).py
48ruby_STEP_TO_PROG = ruby/$($(1)).rb
49
50
51bash_RUNSTEP = bash ../$(2) $(3)
52c_RUNSTEP = ../$(2) $(3)
53clojure_RUNSTEP = lein with-profile +$(1) trampoline run $(3)
54cs_RUNSTEP = mono ../$(2) --raw $(3)
55java_RUNSTEP = mvn -quiet exec:java -Dexec.mainClass="mal.$($(1))" -Dexec.args="--raw$(if $(3), $(3),)"
56js_RUNSTEP = node ../$(2) $(3)
57make_RUNSTEP = make -f ../$(2) $(3)
58mal_RUNSTEP = $(call $(MAL_IMPL)_RUNSTEP,$(1),$(call $(MAL_IMPL)_STEP_TO_PROG,stepA),../$(2),") #"
b5dedee0 59perl_RUNSTEP = perl ../$(2) $(3)
db4c329a
JM
60php_RUNSTEP = php ../$(2) $(3)
61ps_RUNSTEP = $(4)gs -q -dNODISPLAY -- ../$(2) $(3)$(4)
62python_RUNSTEP = $(PYTHON) ../$(2) $(3)
63ruby_RUNSTEP = ruby ../$(2) $(3)
64
65# Extra options to pass to runtest.py
66cs_TEST_OPTS = --redirect
6301e0b6 67mal_TEST_OPTS = --start-timeout 60 --test-timeout 120
31690700
JM
68
69
70# Derived lists
71STEPS = $(sort $(filter step%,$(.VARIABLES)))
72IMPL_TESTS = $(foreach impl,$(IMPLS),test^$(impl))
73STEP_TESTS = $(foreach step,$(STEPS),test^$(step))
74ALL_TESTS = $(filter-out $(EXCLUDE_TESTS),\
75 $(strip $(sort \
76 $(foreach impl,$(IMPLS),\
77 $(foreach step,$(STEPS),test^$(impl)^$(step))))))
78
79IMPL_STATS = $(foreach impl,$(IMPLS),stats^$(impl))
712af9ef 80IMPL_STATS_LISP = $(foreach impl,$(IMPLS),stats-lisp^$(impl))
31690700 81
db4c329a
JM
82IMPL_PERF = $(filter-out $(EXCLUDE_PERFS),$(foreach impl,$(IMPLS),perf^$(impl)))
83
31690700
JM
84#
85# Build rules
86#
87
88# Build a program in 'c' directory
89c/%:
90 $(MAKE) -C $(dir $(@)) $(notdir $(@))
91
92# Allow test, test^STEP, test^IMPL, and test^IMPL^STEP
93.SECONDEXPANSION:
94$(IMPL_TESTS): $$(filter $$@^%,$$(ALL_TESTS))
95
96.SECONDEXPANSION:
97$(STEP_TESTS): $$(foreach step,$$(subst test^,,$$@),$$(filter %^$$(step),$$(ALL_TESTS)))
98
99.SECONDEXPANSION:
100$(ALL_TESTS): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
101 @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
102 $(foreach step,$(word 3,$(subst ^, ,$(@))),\
103 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
104 $(foreach test,$(call STEP_TEST_FILES,$(impl),$(step)),\
105 echo '----------------------------------------------'; \
106 echo 'Testing $@, step file: $+, test file: $(test)'; \
db4c329a
JM
107 echo 'Running: ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+))'; \
108 ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+)))))
31690700
JM
109
110test: $(ALL_TESTS)
111tests: $(ALL_TESTS)
112
113
114# Stats rules
115
db4c329a
JM
116stats: $(IMPL_STATS)
117stats-lisp: $(IMPL_STATS_LISP)
118
31690700
JM
119.SECONDEXPANSION:
120$(IMPL_STATS):
121 @echo "----------------------------------------------"; \
122 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
123 echo "Stats for $(impl):"; \
124 $(MAKE) --no-print-directory -C $(impl) stats)
125
712af9ef
JM
126.SECONDEXPANSION:
127$(IMPL_STATS_LISP):
128 @echo "----------------------------------------------"; \
129 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
130 echo "Stats (lisp only) for $(impl):"; \
131 $(MAKE) --no-print-directory -C $(impl) stats-lisp)
132
db4c329a
JM
133
134# Performance test rules
135
136perf: $(IMPL_PERF)
137
138.SECONDEXPANSION:
139$(IMPL_PERF):
140 @echo "----------------------------------------------"; \
141 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
142 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
143 echo "Performance test for $(impl):"; \
144 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal)'; \
145 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal); \
146 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal)'; \
147 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal))
148