1# NOTE: `cabal test` will take care to build the local `happy`
2# executable and place it into $PATH for us to pick up.
3#
4# If it doesn't look like the alex binary in $PATH comes from the
5# build tree, then we'll fall back to pointing to
6# ../dist/build/alex/alex to support running tests via "runghc
7# Setup.hs test".
8#
9HAPPY=$(shell which happy)
10ifeq "$(filter $(dir $(shell pwd))%,$(HAPPY))" ""
11HAPPY=../dist/build/happy/happy
12endif
13
14HC = ghc
15HC_OPTS=-Wall -Werror
16
17.PRECIOUS: %.n.hs %.g.hs %.o %.exe %.bin
18
19ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
20HS_PROG_EXT = .exe
21else
22HS_PROG_EXT = .bin
23endif
24
25TESTS = Test.ly TestMulti.ly TestPrecedence.ly bug001.ly \
26	monad001.y monad002.ly precedence001.ly precedence002.y \
27	bogus-token.y bug002.y Partial.ly \
28	issue91.y issue93.y issue94.y issue95.y \
29	AttrGrammar001.y AttrGrammar002.y \
30	test_rules.y monaderror.y monaderror-explist.y \
31	typeclass_monad001.y typeclass_monad002.ly typeclass_monad_lexer.y \
32	rank2.y shift01.y
33
34ERROR_TESTS = error001.y
35
36# NOTE: `cabal` will set the `happy_datadir` env-var accordingly before invoking the test-suite
37#TEST_HAPPY_OPTS = --strict --template=..
38TEST_HAPPY_OPTS = --strict
39
40%.n.hs : %.ly
41	$(HAPPY) $(TEST_HAPPY_OPTS) $< -o $@
42
43%.a.hs : %.ly
44	$(HAPPY) $(TEST_HAPPY_OPTS) -a $< -o $@
45
46%.g.hs : %.ly
47	$(HAPPY) $(TEST_HAPPY_OPTS) -g $< -o $@
48
49%.gc.hs : %.ly
50	$(HAPPY) $(TEST_HAPPY_OPTS) -gc $< -o $@
51
52%.ag.hs : %.ly
53	$(HAPPY) $(TEST_HAPPY_OPTS) -ag $< -o $@
54
55%.agc.hs : %.ly
56	$(HAPPY) $(TEST_HAPPY_OPTS) -agc $< -o $@
57
58%.n.hs : %.y
59	$(HAPPY) $(TEST_HAPPY_OPTS) $< -o $@
60
61%.a.hs : %.y
62	$(HAPPY) $(TEST_HAPPY_OPTS) -a $< -o $@
63
64%.g.hs : %.y
65	$(HAPPY) $(TEST_HAPPY_OPTS) -g $< -o $@
66
67%.gc.hs : %.y
68	$(HAPPY) $(TEST_HAPPY_OPTS) -gc $< -o $@
69
70%.ag.hs : %.y
71	$(HAPPY) $(TEST_HAPPY_OPTS) -ag $< -o $@
72
73%.agc.hs : %.y
74	$(HAPPY) $(TEST_HAPPY_OPTS) -agc $< -o $@
75
76CLEAN_FILES += *.n.hs *.a.hs *.g.hs *.gc.hs *.ag.hs *.agc.hs *.info *.hi *.bin *.exe *.o *.run.stdout *.run.stderr $(SANDBOX_CONFIG)
77
78ALL_TEST_HS = $(shell echo $(TESTS) | sed -e 's/\([^\. ]*\)\.\(l\)\{0,1\}y/\1.n.hs \1.a.hs \1.g.hs \1.gc.hs \1.ag.hs \1.agc.hs/g')
79
80ALL_TESTS = $(patsubst %.hs, %.run, $(ALL_TEST_HS))
81
82CHECK_ERROR_TESTS = $(patsubst %, check.%, $(ERROR_TESTS))
83
84HC_OPTS += -fforce-recomp
85
86.PRECIOUS: %.hs %.o %.bin %.$(HS_PROG_EXT)
87
88%.run : %$(HS_PROG_EXT)
89	@echo "--> Checking $<..."
90	./$<
91
92check.%.y : %.y
93	@echo "--> Checking $<..."
94	$(HAPPY) $(TEST_HAPPY_OPTS) $< 1>$*.run.stdout 2>$*.run.stderr || true
95	@diff -u --ignore-all-space $*.stdout $*.run.stdout
96	@diff -u --ignore-all-space $*.stderr $*.run.stderr
97
98%$(HS_PROG_EXT) : %.hs
99	$(HC) $(HC_OPTS) $($*_LD_OPTS) $< -o $@
100
101all :: $(SANDBOX_CONFIG) $(CHECK_ERROR_TESTS) $(ALL_TESTS)
102
103check-todo::
104	$(HAPPY) $(TEST_HAPPY_OPTS) -ad Test.ly
105	$(HC) Test.hs -o happy_test
106	./happy_test
107	-rm -f ./happy_test
108	$(HAPPY) $(TEST_HAPPY_OPTS) -agd Test.ly
109	$(HC) Test.hs -o happy_test
110	./happy_test
111	-rm -f ./happy_test
112	$(HAPPY) $(TEST_HAPPY_OPTS) -agcd Test.ly
113	$(HC) Test.hs -o happy_test
114	./happy_test
115	-rm -f ./happy_test
116
117.PHONY: clean
118
119clean:
120	$(RM) $(CLEAN_FILES)
121
122cabal.sandbox.config:
123	cabal sandbox init --sandbox=../.cabal-sandbox
124