catala/tests/Makefile

49 lines
2.0 KiB
Makefile
Raw Normal View History

2020-08-07 18:37:28 +03:00
############################################
# Preamble
############################################
2020-12-21 18:15:42 +03:00
BLACK := $(shell tput -Txterm setaf 0)
RED := $(shell tput -Txterm setaf 1)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
LIGHTPURPLE := $(shell tput -Txterm setaf 4)
PURPLE := $(shell tput -Txterm setaf 5)
BLUE := $(shell tput -Txterm setaf 6)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
2020-12-05 19:27:08 +03:00
CATALA_OPTS?=
2021-02-01 22:09:16 +03:00
CATALA=dune exec --no-buffer --no-print-director ../src/catala/catala.exe -- Interpret $(CATALA_OPTS)
2020-08-07 18:37:28 +03:00
pass_tests: $(wildcard */*/output/*.out)
2020-12-10 11:27:51 +03:00
reset_tests: $(subst output/,,$(subst .out,.in,$(wildcard */*/output/*.out)))
2020-08-07 18:37:28 +03:00
# Forces all the tests to be redone
.FORCE:
2020-12-09 19:31:42 +03:00
%.run: .FORCE
$(CATALA) $(word 1,$(subst ., ,$*)).catala -s $(word 3,$(subst ., ,$*))
# Usage: make <test_dir>/output/<test_name>.catala.<scope_name>.out
# This rule runs the test and compares against the expected output. If the
# Catala program is <test_dir>/<test_name>.catala
# and the scope to run is <scope_name>, then the expected output should be in the file
# <test_dir>/output/<test_name>.catala.<scope_name>.out
%.out: .FORCE
@$(CATALA) --unstyled \
$(word 1, $(subst /, , $*))/$(word 2, $(subst /, , $*))/$(word 1, $(subst ., ,$(word 4, $(subst /, , $*)))).catala \
-s $(word 3, $(subst ., ,$*)) 2>&1 | \
colordiff -u -b $@ - || { echo "${RED}FAIL${RESET} ${PURPLE}$*${RESET}"; exit 1; }
2020-12-21 18:15:42 +03:00
@echo "${GREEN}PASS${RESET} ${PURPLE}$*${RESET}"
# Usage: make <test_dir>/<test_name>.catala.<scope_name>.in
# This rule runs the test <test_dir>/<test_name>.catala, prints its output and
# writes this output to the <test_dir>/output/<test_name>.catala.<scope_name>.out file
%.in: .FORCE
@-$(CATALA) $(word 1,$(subst ., ,$*)).catala -s $(word 3,$(subst ., ,$*))
@-$(CATALA) --unstyled $(word 1,$(subst ., ,$*)).catala -s $(word 3,$(subst ., ,$*)) \
> $(dir $*)output/$(lastword $(subst /, ,$*)).out 2>&1