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