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