mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 14:21:36 +00:00
Pulling in a rudimentary testsuite - we have to find a better solution ...
This commit is contained in:
parent
2fa544f681
commit
18272f9f34
30 changed files with 415 additions and 0 deletions
154
testsuite/Makefile
Normal file
154
testsuite/Makefile
Normal file
|
@ -0,0 +1,154 @@
|
|||
QCC = ../gmqcc
|
||||
VM = ../qcvm
|
||||
|
||||
TESTLIST = \
|
||||
globaldefs \
|
||||
fielddefs \
|
||||
builtins \
|
||||
variadic \
|
||||
calls \
|
||||
if1 \
|
||||
loops1 \
|
||||
maths1 \
|
||||
maths2 \
|
||||
equality \
|
||||
fields1 \
|
||||
invalid-types
|
||||
|
||||
.PHONY: clean test
|
||||
|
||||
clean:
|
||||
rm -f gmqcc qcvm
|
||||
rm -f */deflist */*.gm.dat */*.qcc.dat */output
|
||||
rm -rf obj
|
||||
|
||||
test: $(TESTLIST)
|
||||
|
||||
obj/%.gm.dat: %/main.qc obj
|
||||
@echo "Testing:" $(subst obj/,,$(subst .gm.dat,,$@))
|
||||
@$(QCC) -std=gmqcc -o $@ $< > $@.out 2> $@.err
|
||||
|
||||
obj/%.qcc.dat: %/main.qc obj
|
||||
@echo "Testing:" $(subst obj/,,$(subst .qcc.dat,,$@))
|
||||
@$(QCC) -std=qcc -o $@ $< > $@.out 2> $@.err
|
||||
|
||||
#######################################################################
|
||||
|
||||
# Macro which causes something to be compiled either with -std=qcc or without...
|
||||
# this may at some point be extended to also store information about the progs.dat
|
||||
# somewhere but for now we only need to build the object.
|
||||
define maketest
|
||||
$(eval $dat = obj/${1}.${2}.dat)
|
||||
$1: obj/$1.$2.dat
|
||||
endef
|
||||
|
||||
#######################################################################
|
||||
|
||||
globaldefs: obj/globaldefs.gm.dat
|
||||
@$(VM) -printdefs $< > $@/deflist
|
||||
@diff $@/deflist $@/deflist.expected
|
||||
|
||||
$(eval $(call maketest,fielddefs,gm))
|
||||
fielddefs:
|
||||
@$(VM) -printfields $< > $@/deflist
|
||||
@diff $@/deflist $@/deflist.expected
|
||||
|
||||
$(eval $(call maketest,builtins,qcc))
|
||||
builtins:
|
||||
@$(VM) -string "Hello 1" $< > $@/output
|
||||
@test "`wc -l $@/output | awk '{ print $$1 }'`" = "1"
|
||||
@grep -qE '^Hello 1$$' $@/output
|
||||
@$(VM) -string "A test message Yeah" $< > $@/output
|
||||
@test "`wc -l $@/output | awk '{ print $$1 }'`" = "1"
|
||||
@grep -qE '^A test message Yeah$$' $@/output
|
||||
|
||||
$(eval $(call maketest,variadic,qcc))
|
||||
variadic:
|
||||
@$(VM) -string "Hello 1" $< > $@/output
|
||||
@test "`wc -l $@/output | awk '{ print $$1 }'`" = "1"
|
||||
@grep -qE '^Hello 1$$' $@/output
|
||||
@$(VM) -string "A test message Yeah" $< > $@/output
|
||||
@test "`wc -l $@/output | awk '{ print $$1 }'`" = "1"
|
||||
@grep -qE '^A test message Yeah$$' $@/output
|
||||
|
||||
$(eval $(call maketest,calls,qcc))
|
||||
calls:
|
||||
@$(VM) -float 1 -float 100 -float 10000 $< > $@/output
|
||||
@grep -qE '^70907$$' $@/output
|
||||
@$(VM) -float 3 -float 201 -float 90127 $< > $@/output
|
||||
@grep -qE '^632719$$' $@/output
|
||||
|
||||
$(eval $(call maketest,if1,qcc))
|
||||
if1:
|
||||
@$(VM) -float 1 -float 100 -float 10000 $< > $@/output
|
||||
@grep -qE '^One$$' $@/output
|
||||
@$(VM) -float 2 -float 100 -float 10000 $< > $@/output
|
||||
@grep -qE '^Two$$' $@/output
|
||||
@$(VM) -float 3 -float 100 -float 10000 $< > $@/output
|
||||
@grep -qE '^Three$$' $@/output
|
||||
@$(VM) -float 4 -float 100 -float 10000 $< > $@/output
|
||||
@grep -qE '^Else$$' $@/output
|
||||
|
||||
$(eval $(call maketest,loops1,qcc))
|
||||
loops1:
|
||||
@$(VM) -float 0 $< > $@/output
|
||||
@diff $@/output $@/0.expected
|
||||
@$(VM) -float 1 $< > $@/output
|
||||
@diff $@/output $@/1.expected
|
||||
@$(VM) -float 4 $< > $@/output
|
||||
@diff $@/output $@/4.expected
|
||||
@$(VM) -float 10 $< > $@/output
|
||||
@diff $@/output $@/10.expected
|
||||
|
||||
$(eval $(call maketest,maths1,qcc))
|
||||
maths1:
|
||||
@$(VM) -float 0 -float 3 $< > $@/output
|
||||
@diff $@/output $@/0.3.expected
|
||||
@$(VM) -float 3 -float 6 $< > $@/output
|
||||
@diff $@/output $@/3.6.expected
|
||||
@$(VM) -float 0 -float 0 $< > $@/output
|
||||
@diff $@/output $@/0.0.expected
|
||||
|
||||
$(eval $(call maketest,maths2,qcc))
|
||||
maths2:
|
||||
@$(VM) -vector '1 2 3' -vector '4 5 6' $< > $@/output
|
||||
@grep -qE '^dot = 32$$' $@/output
|
||||
@$(VM) -vector '-5 12 5.5' -vector '4 -5 1' $< > $@/output
|
||||
@grep -qE '^dot = -74.5$$' $@/output
|
||||
@$(VM) -vector '-5 12 5.5' -vector '0 0 0' $< > $@/output
|
||||
@grep -qE '^dot = 0$$' $@/output
|
||||
|
||||
$(eval $(call maketest,equality,qcc))
|
||||
equality:
|
||||
@$(VM) -float 1 -float 1 $< > $@/output
|
||||
@diff $@/output $@/1.1.expected
|
||||
@$(VM) -float 1 -float 0 $< > $@/output
|
||||
@diff $@/output $@/1.0.expected
|
||||
@$(VM) -float 0 -float 1 $< > $@/output
|
||||
@diff $@/output $@/0.1.expected
|
||||
|
||||
$(eval $(call maketest,fields1,qcc))
|
||||
fields1:
|
||||
@$(VM) -vector '150 2000 150' -vector '220 1300 -200' $< > $@/output
|
||||
@diff $@/output $@/expected
|
||||
|
||||
invalid-types-ok: obj invalid-types/assign.qc invalid-types/op.qc invalid-types/call1.qc invalid-types/call2.qc invalid-types/call3.qc
|
||||
@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
|
||||
@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
|
||||
@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
|
||||
@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
|
||||
@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
|
||||
@touch obj/invalid-types-ok
|
||||
|
||||
invalid-types: invalid-types-ok
|
||||
|
||||
#######################################################################
|
||||
obj:
|
||||
mkdir obj
|
||||
|
||||
../gmqcc:
|
||||
$(MAKE) -C ..
|
||||
|
||||
../qcvm:
|
||||
$(MAKE) -C .. qcvm
|
||||
|
6
testsuite/builtins/main.qc
Normal file
6
testsuite/builtins/main.qc
Normal file
|
@ -0,0 +1,6 @@
|
|||
void(string) print = #1;
|
||||
|
||||
void(string what) main = {
|
||||
print(what);
|
||||
print("\n");
|
||||
};
|
14
testsuite/calls/main.qc
Normal file
14
testsuite/calls/main.qc
Normal file
|
@ -0,0 +1,14 @@
|
|||
void(string, ...) print = #1;
|
||||
string(float) ftos = #2;
|
||||
|
||||
float(float x, float y, float z) sum = {
|
||||
return x + y + z;
|
||||
};
|
||||
|
||||
void(float a, float b, float c) main = {
|
||||
local float f;
|
||||
f = sum(sum(a, sum(a, b, c), c),
|
||||
sum(sum(sum(a, b, c), b, sum(a, b, c)), b, sum(a, b, sum(a, b, c))),
|
||||
sum(sum(a, b, c), b, c));
|
||||
print(ftos(f), "\n");
|
||||
};
|
3
testsuite/equality/0.1.expected
Normal file
3
testsuite/equality/0.1.expected
Normal file
|
@ -0,0 +1,3 @@
|
|||
ne
|
||||
lt
|
||||
le
|
3
testsuite/equality/1.0.expected
Normal file
3
testsuite/equality/1.0.expected
Normal file
|
@ -0,0 +1,3 @@
|
|||
ne
|
||||
gt
|
||||
ge
|
3
testsuite/equality/1.1.expected
Normal file
3
testsuite/equality/1.1.expected
Normal file
|
@ -0,0 +1,3 @@
|
|||
eq
|
||||
ge
|
||||
le
|
11
testsuite/equality/main.qc
Normal file
11
testsuite/equality/main.qc
Normal file
|
@ -0,0 +1,11 @@
|
|||
void(string, ...) print = #1;
|
||||
string(float) ftos = #2;
|
||||
|
||||
void(float a, float b) main = {
|
||||
if (a == b) print("eq\n");
|
||||
if (a != b) print("ne\n");
|
||||
if (a > b) print("gt\n");
|
||||
if (a < b) print("lt\n");
|
||||
if (a >= b) print("ge\n");
|
||||
if (a <= b) print("le\n");
|
||||
};
|
5
testsuite/fielddefs/deflist.expected
Normal file
5
testsuite/fielddefs/deflist.expected
Normal file
|
@ -0,0 +1,5 @@
|
|||
Field: void at 0
|
||||
Field: float globf at 0
|
||||
Field: vector globv at 1
|
||||
Field: string globs at 4
|
||||
Field: function globfunc at 5
|
4
testsuite/fielddefs/main.qc
Normal file
4
testsuite/fielddefs/main.qc
Normal file
|
@ -0,0 +1,4 @@
|
|||
.float globf;
|
||||
.vector globv;
|
||||
.string globs;
|
||||
.void() globfunc;
|
3
testsuite/fields1/expected
Normal file
3
testsuite/fields1/expected
Normal file
|
@ -0,0 +1,3 @@
|
|||
spot1 = '150 2000 175'
|
||||
spot2 = '220 1300 -175'
|
||||
vis: 0
|
43
testsuite/fields1/main.qc
Normal file
43
testsuite/fields1/main.qc
Normal file
|
@ -0,0 +1,43 @@
|
|||
void(string, ...) print = #1;
|
||||
string(float) ftos = #2;
|
||||
entity() spawn = #3;
|
||||
string(vector) vtos = #5;
|
||||
void(string, ...) error = #6;
|
||||
|
||||
entity self;
|
||||
|
||||
.vector origin;
|
||||
.vector view;
|
||||
|
||||
entity() make = {
|
||||
local entity e;
|
||||
e = spawn();
|
||||
e.view = '0 0 25';
|
||||
return e;
|
||||
};
|
||||
|
||||
float(entity targ) visible = {
|
||||
local vector spot1, spot2;
|
||||
spot1 = self.origin + self.view;
|
||||
spot2 = targ.origin + targ.view;
|
||||
|
||||
print("spot1 = ", vtos(spot1), "\n");
|
||||
print("spot2 = ", vtos(spot2), "\n");
|
||||
// This was part of some QC code which had a bug
|
||||
// we don't actually return anything important here.
|
||||
return 0;
|
||||
};
|
||||
|
||||
void(vector a, vector b) main = {
|
||||
local entity targ;
|
||||
|
||||
self = make();
|
||||
targ = make();
|
||||
if (self == targ)
|
||||
error("ERROR, self == targ\n");
|
||||
|
||||
self.origin = a;
|
||||
targ.origin = b;
|
||||
|
||||
print("vis: ", ftos(visible(targ)), "\n");
|
||||
};
|
5
testsuite/globaldefs/deflist.expected
Normal file
5
testsuite/globaldefs/deflist.expected
Normal file
|
@ -0,0 +1,5 @@
|
|||
Global: void at 0
|
||||
Global: float globf at 28
|
||||
Global: vector globv at 29
|
||||
Global: string globs at 32
|
||||
Global: function globfunc at 33
|
4
testsuite/globaldefs/main.qc
Normal file
4
testsuite/globaldefs/main.qc
Normal file
|
@ -0,0 +1,4 @@
|
|||
float globf;
|
||||
vector globv;
|
||||
string globs;
|
||||
void() globfunc;
|
12
testsuite/if1/main.qc
Normal file
12
testsuite/if1/main.qc
Normal file
|
@ -0,0 +1,12 @@
|
|||
void(string, ...) print = #1;
|
||||
|
||||
void(float c) main = {
|
||||
if (c == 1)
|
||||
print("One\n");
|
||||
else if (c == 2)
|
||||
print("Two\n");
|
||||
else if (c == 3)
|
||||
print("Three\n");
|
||||
else
|
||||
print("Else\n");
|
||||
};
|
5
testsuite/invalid-types/assign.qc
Normal file
5
testsuite/invalid-types/assign.qc
Normal file
|
@ -0,0 +1,5 @@
|
|||
void() main = {
|
||||
local float x;
|
||||
local entity e;
|
||||
x = e;
|
||||
};
|
6
testsuite/invalid-types/call1.qc
Normal file
6
testsuite/invalid-types/call1.qc
Normal file
|
@ -0,0 +1,6 @@
|
|||
void(float, string, entity) fun = #1;
|
||||
|
||||
void() main = {
|
||||
local float x;
|
||||
fun(x, x, x);
|
||||
};
|
6
testsuite/invalid-types/call2.qc
Normal file
6
testsuite/invalid-types/call2.qc
Normal file
|
@ -0,0 +1,6 @@
|
|||
void(float, string, entity) fun = #1;
|
||||
|
||||
void() main = {
|
||||
local string x;
|
||||
fun(x, x, x);
|
||||
};
|
6
testsuite/invalid-types/call3.qc
Normal file
6
testsuite/invalid-types/call3.qc
Normal file
|
@ -0,0 +1,6 @@
|
|||
void(float, string, entity) fun = #1;
|
||||
|
||||
void() main = {
|
||||
local entity x;
|
||||
fun(x, x, x);
|
||||
};
|
5
testsuite/invalid-types/op.qc
Normal file
5
testsuite/invalid-types/op.qc
Normal file
|
@ -0,0 +1,5 @@
|
|||
void() main = {
|
||||
local float x, y;
|
||||
local entity e;
|
||||
x = y + e;
|
||||
};
|
1
testsuite/loops1/0.expected
Normal file
1
testsuite/loops1/0.expected
Normal file
|
@ -0,0 +1 @@
|
|||
do 0
|
3
testsuite/loops1/1.expected
Normal file
3
testsuite/loops1/1.expected
Normal file
|
@ -0,0 +1,3 @@
|
|||
for 0
|
||||
while 0
|
||||
do 0
|
30
testsuite/loops1/10.expected
Normal file
30
testsuite/loops1/10.expected
Normal file
|
@ -0,0 +1,30 @@
|
|||
for 0
|
||||
for 1
|
||||
for 2
|
||||
for 3
|
||||
for 4
|
||||
for 5
|
||||
for 6
|
||||
for 7
|
||||
for 8
|
||||
for 9
|
||||
while 0
|
||||
while 1
|
||||
while 2
|
||||
while 3
|
||||
while 4
|
||||
while 5
|
||||
while 6
|
||||
while 7
|
||||
while 8
|
||||
while 9
|
||||
do 0
|
||||
do 1
|
||||
do 2
|
||||
do 3
|
||||
do 4
|
||||
do 5
|
||||
do 6
|
||||
do 7
|
||||
do 8
|
||||
do 9
|
12
testsuite/loops1/4.expected
Normal file
12
testsuite/loops1/4.expected
Normal file
|
@ -0,0 +1,12 @@
|
|||
for 0
|
||||
for 1
|
||||
for 2
|
||||
for 3
|
||||
while 0
|
||||
while 1
|
||||
while 2
|
||||
while 3
|
||||
do 0
|
||||
do 1
|
||||
do 2
|
||||
do 3
|
22
testsuite/loops1/main.qc
Normal file
22
testsuite/loops1/main.qc
Normal file
|
@ -0,0 +1,22 @@
|
|||
void(string, ...) print = #1;
|
||||
string(float) ftos = #2;
|
||||
|
||||
void(float n) main = {
|
||||
local float i;
|
||||
|
||||
for (i = 0; i < n; i += 1) {
|
||||
print("for ", ftos(i), "\n");
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < n) {
|
||||
print("while ", ftos(i), "\n");
|
||||
i += 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
do {
|
||||
print("do ", ftos(i), "\n");
|
||||
i += 1;
|
||||
} while (i < n);
|
||||
};
|
8
testsuite/maths1/0.0.expected
Normal file
8
testsuite/maths1/0.0.expected
Normal file
|
@ -0,0 +1,8 @@
|
|||
input: 0 and 0
|
||||
+ 0
|
||||
* 0
|
||||
/ 0
|
||||
& 0
|
||||
| 0
|
||||
&& 0
|
||||
|| 0
|
8
testsuite/maths1/0.3.expected
Normal file
8
testsuite/maths1/0.3.expected
Normal file
|
@ -0,0 +1,8 @@
|
|||
input: 0 and 3
|
||||
+ 3
|
||||
* 0
|
||||
/ 0
|
||||
& 0
|
||||
| 3
|
||||
&& 0
|
||||
|| 1
|
8
testsuite/maths1/3.6.expected
Normal file
8
testsuite/maths1/3.6.expected
Normal file
|
@ -0,0 +1,8 @@
|
|||
input: 3 and 6
|
||||
+ 9
|
||||
* 18
|
||||
/ 0.5
|
||||
& 2
|
||||
| 7
|
||||
&& 1
|
||||
|| 1
|
14
testsuite/maths1/main.qc
Normal file
14
testsuite/maths1/main.qc
Normal file
|
@ -0,0 +1,14 @@
|
|||
void(string, ...) print = #1;
|
||||
string(float) ftos = #2;
|
||||
string(vector) vtos = #5;
|
||||
|
||||
void(float a, float b) main = {
|
||||
print("input: ", ftos(a), " and ", ftos(b), "\n");
|
||||
print("+ ", ftos(a+b), "\n");
|
||||
print("* ", ftos(a*b), "\n");
|
||||
print("/ ", ftos(a/b), "\n");
|
||||
print("& ", ftos(a&b), "\n");
|
||||
print("| ", ftos(a|b), "\n");
|
||||
print("&& ", ftos(a&&b), "\n");
|
||||
print("|| ", ftos(a||b), "\n");
|
||||
};
|
6
testsuite/maths2/main.qc
Normal file
6
testsuite/maths2/main.qc
Normal file
|
@ -0,0 +1,6 @@
|
|||
void(string, ...) print = #1;
|
||||
string(float) ftos = #2;
|
||||
|
||||
void(vector a, vector b) main = {
|
||||
print("dot = ", ftos(a*b), "\n");
|
||||
};
|
5
testsuite/variadic/main.qc
Normal file
5
testsuite/variadic/main.qc
Normal file
|
@ -0,0 +1,5 @@
|
|||
void(string, ...) print = #1;
|
||||
|
||||
void(string what) main = {
|
||||
print(what, "\n");
|
||||
};
|
Loading…
Reference in a new issue