Debian Codegraph @

tests/Makefile

raw
1 # NOTE: This assumes that a working `ghc` is on $PATH; this may not
2 # necessarily be the same GHC used by `cabal` for building `happy`.
3 #
4 # Again, if HC has been set in the environment (e.g. by the CI), we keep this setting.
5 # [2021-07-14, PR #196](https://github.com/haskell/happy/pull/196)
6 #
7 HC ?= ghc
8 HC_OPTS=-package array -Wall -Werror -XHaskell98
9
10 # NOTE: `cabal test` will take care to build the local `happy`
11 # executable and place it into $PATH for us to pick up.
12 # (This is ensured by setting build-tool-depends.)
13 #
14 # If it doesn't look like the alex binary in $PATH comes from the
15 # build tree, then we'll fall back to pointing to
16 # ../dist/build/alex/alex to support running tests via "runghc
17 # Setup.hs test".
18 #
19 # If HAPPY has been set outside, e.g. in the environment, we trust this setting.
20 # This way, we can pass in the correct Happy executable from a CI environment
21 # without danger of it being "fixed" by the logic below.
22 # [2021-07-14, PR #196](https://github.com/haskell/happy/pull/196)
23 #
24 HAPPY ?= happy
25
26 .PRECIOUS: %.n.hs %.c.hs %.o %.exe %.bin
27
28 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
29 HS_PROG_EXT = .exe
30 else
31 HS_PROG_EXT = .bin
32 endif
33
34 TESTS = Test.ly TestMulti.ly TestPrecedence.ly bug001.ly \
35 monad001.y monad002.ly precedence001.ly precedence002.y \
36 bogus-token.y bug002.y Partial.ly \
37 issue91.y issue93.y issue94.y issue95.y \
38 test_rules.y monaderror.y monaderror-explist.y \
39 typeclass_monad001.y typeclass_monad002.ly typeclass_monad_lexer.y \
40 rank2.y shift01.y \
41 AttrGrammar001.y AttrGrammar002.y \
42 Pragma.y
43
44 ERROR_TESTS = error001.y
45
46 # NOTE: `cabal` will set the `happy_datadir` env-var accordingly before invoking the test-suite
47 #TEST_HAPPY_OPTS = --strict --template=..
48 TEST_HAPPY_OPTS = --strict -g
49
50 %.n.hs : %.y
51 $(HAPPY) $(TEST_HAPPY_OPTS) $< -o $@
52
53 %.n.hs : %.ly
54 $(HAPPY) $(TEST_HAPPY_OPTS) $< -o $@
55
56 %.c.hs : %.y
57 $(HAPPY) $(TEST_HAPPY_OPTS) -c $< -o $@
58
59 %.c.hs : %.ly
60 $(HAPPY) $(TEST_HAPPY_OPTS) -c $< -o $@
61
62 %.d.hs : %.y
63 $(HAPPY) $(TEST_HAPPY_OPTS) -d $< -o $@
64
65 %.d.hs : %.ly
66 $(HAPPY) $(TEST_HAPPY_OPTS) -d $< -o $@
67
68 CLEAN_FILES += *.n.hs *.c.hs *.info *.hi *.bin *.exe *.o *.run.stdout *.run.stderr
69
70 ALL_TEST_HS = $(shell echo $(TESTS) | sed -e 's/\([^\. ]*\)\.\(l\)\{0,1\}y/\1.n.hs \1.c.hs/g')
71
72 ALL_TESTS = $(patsubst %.hs, %.run, $(ALL_TEST_HS))
73
74 DEBUG_TESTS = Test.d$(HS_PROG_EXT) # Compile a single file with -d to ensure that it works
75
76 CHECK_ERROR_TESTS = $(patsubst %, check.%, $(ERROR_TESTS))
77
78 HC_OPTS += -fforce-recomp
79
80 .PRECIOUS: %.hs %.o %.bin %.$(HS_PROG_EXT)
81
82 %.run : %$(HS_PROG_EXT)
83 @echo "--> Checking $<..."
84 ./$<
85
86 path.run : # simply a test to output the path of the built happy executable, useful in CI
87 @echo "--> Printing happy path..."
88 which $(HAPPY)
89
90 check.%.y : %.y
91 @echo "--> Checking $<..."
92 $(HAPPY) $(TEST_HAPPY_OPTS) -g $< 1>$*.run.stdout 2>$*.run.stderr || true
93 sed -i '/^Up to date$$/d' $*.run.stdout $*.run.stderr
94 @diff -u --ignore-all-space $*.stdout $*.run.stdout
95 @diff -u --ignore-all-space $*.stderr $*.run.stderr
96
97 %$(HS_PROG_EXT) : %.hs
98 $(HC) $(HC_OPTS) $($*_LD_OPTS) $< -o $@
99
100 all :: path.run $(CHECK_ERROR_TESTS) $(DEBUG_TESTS) $(ALL_TESTS)
101
102 check-todo::
103 $(HAPPY) $(TEST_HAPPY_OPTS) -d Test.ly
104 $(HC) Test.hs -o happy_test
105 ./happy_test
106 -rm -f ./happy_test
107 $(HAPPY) $(TEST_HAPPY_OPTS) -cd Test.ly
108 $(HC) Test.hs -o happy_test
109 ./happy_test
110 -rm -f ./happy_test
111
112 .PHONY: clean all check-todo path.run
113
114 clean:
115 $(RM) $(CLEAN_FILES)