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