]> git.xonotic.org Git - xonotic/gmqcc.git/blob - testsuite/Makefile
e902e55612af9bcf84edc96b597d56cdf33abc68
[xonotic/gmqcc.git] / testsuite / Makefile
1 QCC = ../gmqcc
2 VM = ../qcvm
3
4 TESTLIST = \
5         globaldefs \
6         fielddefs  \
7         builtins   \
8         variadic   \
9         calls      \
10         if1        \
11         loops1     \
12         maths1     \
13         maths2     \
14         equality   \
15         fields1    \
16         invalid-types \
17         ngraphs    \
18         invalid-assign \
19         field-parameters \
20         functions-as-parameters
21
22 .PHONY: clean test
23
24 clean:
25         rm -f gmqcc qcvm
26         rm -f */deflist */*.gm.dat */*.qcc.dat */output
27         rm -rf obj
28
29 test: $(TESTLIST)
30
31 obj/%.gm.dat: %/main.qc obj
32         @echo "Testing:" $(subst obj/,,$(subst .gm.dat,,$@))
33         @$(QCC) -std=gmqcc -o $@ $< > $@.out 2> $@.err
34
35 obj/%.qcc.dat: %/main.qc obj
36         @echo "Testing:" $(subst obj/,,$(subst .qcc.dat,,$@))
37         @$(QCC) -std=qcc -o $@ $< > $@.out 2> $@.err
38
39 #######################################################################
40
41 # Macro which causes something to be compiled either with -std=qcc or without...
42 # this may at some point be extended to also store information about the progs.dat
43 # somewhere but for now we only need to build the object.
44 define maketest
45 $(eval $dat = obj/${1}.${2}.dat)
46 $1: obj/$1.$2.dat
47 endef
48
49 #######################################################################
50
51 globaldefs: obj/globaldefs.gm.dat
52         @$(VM) -printdefs $< > $@/deflist
53         @diff $@/deflist $@/deflist.expected
54
55 $(eval $(call maketest,fielddefs,gm))
56 fielddefs:
57         @$(VM) -printfields $< > $@/deflist
58         @diff $@/deflist $@/deflist.expected
59
60 $(eval $(call maketest,builtins,qcc))
61 builtins:
62         @$(VM) -string "Hello 1" $< > $@/output
63         @test "`wc -l $@/output | awk '{ print $$1 }'`" = "1"
64         @grep -qE '^Hello 1$$' $@/output
65         @$(VM) -string "A test message Yeah" $< > $@/output
66         @test "`wc -l $@/output | awk '{ print $$1 }'`" = "1"
67         @grep -qE '^A test message Yeah$$' $@/output
68
69 $(eval $(call maketest,variadic,qcc))
70 variadic:
71         @$(VM) -string "Hello 1" $< > $@/output
72         @test "`wc -l $@/output | awk '{ print $$1 }'`" = "1"
73         @grep -qE '^Hello 1$$' $@/output
74         @$(VM) -string "A test message Yeah" $< > $@/output
75         @test "`wc -l $@/output | awk '{ print $$1 }'`" = "1"
76         @grep -qE '^A test message Yeah$$' $@/output
77
78 $(eval $(call maketest,calls,qcc))
79 calls:
80         @$(VM) -float 1 -float 100 -float 10000 $< > $@/output
81         @grep -qE '^70907$$' $@/output
82         @$(VM) -float 3 -float 201 -float 90127 $< > $@/output
83         @grep -qE '^632719$$' $@/output
84
85 $(eval $(call maketest,if1,qcc))
86 if1:
87         @$(VM) -float 1 -float 100 -float 10000 $< > $@/output
88         @grep -qE '^One$$' $@/output
89         @$(VM) -float 2 -float 100 -float 10000 $< > $@/output
90         @grep -qE '^Two$$' $@/output
91         @$(VM) -float 3 -float 100 -float 10000 $< > $@/output
92         @grep -qE '^Three$$' $@/output
93         @$(VM) -float 4 -float 100 -float 10000 $< > $@/output
94         @grep -qE '^Else$$' $@/output
95
96 $(eval $(call maketest,loops1,qcc))
97 loops1:
98         @$(VM) -float 0 $< > $@/output
99         @diff $@/output $@/0.expected
100         @$(VM) -float 1 $< > $@/output
101         @diff $@/output $@/1.expected
102         @$(VM) -float 4 $< > $@/output
103         @diff $@/output $@/4.expected
104         @$(VM) -float 10 $< > $@/output
105         @diff $@/output $@/10.expected
106
107 $(eval $(call maketest,maths1,qcc))
108 maths1:
109         @$(VM) -float 0 -float 3 $< > $@/output
110         @diff $@/output $@/0.3.expected
111         @$(VM) -float 3 -float 6 $< > $@/output
112         @diff $@/output $@/3.6.expected
113         @$(VM) -float 0 -float 0 $< > $@/output
114         @diff $@/output $@/0.0.expected
115
116 $(eval $(call maketest,maths2,qcc))
117 maths2:
118         @$(VM) -vector '1 2 3' -vector '4 5 6' $< > $@/output
119         @grep -qE '^dot = 32$$' $@/output
120         @$(VM) -vector '-5 12 5.5' -vector '4 -5 1' $< > $@/output
121         @grep -qE '^dot = -74.5$$' $@/output
122         @$(VM) -vector '-5 12 5.5' -vector '0 0 0' $< > $@/output
123         @grep -qE '^dot = 0$$' $@/output
124
125 $(eval $(call maketest,equality,qcc))
126 equality:
127         @$(VM) -float 1 -float 1 $< > $@/output
128         @diff $@/output $@/1.1.expected
129         @$(VM) -float 1 -float 0 $< > $@/output
130         @diff $@/output $@/1.0.expected
131         @$(VM) -float 0 -float 1 $< > $@/output
132         @diff $@/output $@/0.1.expected
133
134 $(eval $(call maketest,fields1,qcc))
135 fields1:
136         @$(VM) -vector '150 2000 150' -vector '220 1300 -200' $< > $@/output
137         @diff $@/output $@/expected
138
139 invalid-types-ok: obj invalid-types/assign.qc invalid-types/op.qc invalid-types/call1.qc invalid-types/call2.qc invalid-types/call3.qc
140         @echo "Testing: invalid-types"
141         @if $(QCC) -std=qcc -o obj/invalid.dat invalid-types/op.qc     > obj/invalid.out 2>&1 ; then echo "Successfully compiled a file which was supposed to fail: op.qc"     ; false ; else true ; fi
142         @if $(QCC) -std=qcc -o obj/invalid.dat invalid-types/call1.qc  > obj/invalid.out 2>&1 ; then echo "Successfully compiled a file which was supposed to fail: call1.qc"  ; false ; else true ; fi
143         @if $(QCC) -std=qcc -o obj/invalid.dat invalid-types/call2.qc  > obj/invalid.out 2>&1 ; then echo "Successfully compiled a file which was supposed to fail: call2.qc"  ; false ; else true ; fi
144         @if $(QCC) -std=qcc -o obj/invalid.dat invalid-types/call3.qc  > obj/invalid.out 2>&1 ; then echo "Successfully compiled a file which was supposed to fail: call3.qc"  ; false ; else true ; fi
145         @if $(QCC) -std=qcc -o obj/invalid.dat invalid-types/assign.qc > obj/invalid.out 2>&1 ; then echo "Successfully compiled a file which was supposed to fail: assign.qc" ; false ; else true ; fi
146         @touch obj/invalid-types-ok
147
148 invalid-types: invalid-types-ok
149
150 $(eval $(call maketest,ngraphs,qcc))
151 ngraphs:
152         @$(VM) $< > $@/output
153         @diff $@/output $@/expected
154
155 invalid-assign-ok: obj invalid-assign/main.qc
156         @echo "Testing: invalid-assign"
157         @if $(QCC) -std=qcc -o obj/invalid.dat invalid-assign/main.qc > obj/invalid.out 2>&1 ; then echo "Successfully compiled a file which was supposed to fail: invalid-assign/main.qc" ; false ; else true ; fi
158
159 invalid-assign: invalid-assign-ok
160
161 $(eval $(call maketest,field-parameters,qcc))
162 field-parameters:
163         @$(VM) $< > $@/output
164         @diff $@/output $@/expected
165
166 $(eval $(call maketest,functions-as-parameters,qcc))
167 functions-as-parameters:
168         @$(VM) $< > $@/output
169         @diff $@/output $@/expected
170
171 #######################################################################
172 obj:
173         mkdir obj
174
175 ../gmqcc:
176         $(MAKE) -C ..
177
178 ../qcvm:
179         $(MAKE) -C .. qcvm
180