Commit d0edc42d authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

added test-cases for compiler error checking of void types

parent 7670af15
TESTS=basic simple nested
LABCOMM_JAR=../compiler/labComm.jar
LABCOMM=java -jar $(LABCOMM_JAR)
LABCOMM=java -jar $(LABCOMM_JAR)
CFLAGS=-O3 -g -Wall -Werror
all:
all:
test: $(TESTS:%=test_%)
# PYTHONPATH=../lib/python \
......@@ -14,12 +14,12 @@ test: $(TESTS:%=test_%)
clean distclean:
rm -rf gen
.PHONY: test_%
.PHONY: test_% testErrors
test_%: gen/%/signatures.py \
gen/%/c_relay \
gen/%/cs_relay.exe \
gen/%/java_relay.class \
gen/%/java_code
gen/%/java_code
PYTHONPATH=../lib/python ./test_encoder_decoder.py \
--signatures=gen/$*/signatures.py \
--test tee gen/$*/testdata \
......@@ -27,6 +27,20 @@ test_%: gen/%/signatures.py \
--test mono gen/$*/cs_relay.exe /dev/stdin /dev/stdout \
--test java \\-cp gen/$*:../lib/java/labcomm.jar java_relay \
/dev/stdin /dev/stdout
# test cases for compiler error checking
.PHONY: compiler_errors testErrorsOK testErrorsNOK
compiler_errors: testErrorsOK testErrorsNOK
# tests that should succeed
testErrorsOK: $(wildcard errors/correct/*.lc)
./test_errors.py --labcomm="$(LABCOMM)" --testOK $^
# tests that should fail
testErrorsNOK: $(wildcard errors/incorrect/*.lc)
./test_errors.py --labcomm="$(LABCOMM)" --testNOK $^
.PRECIOUS: gen/%/.dir
gen/%/.dir:
mkdir -p gen/$*
......@@ -52,7 +66,7 @@ gen/%/c_relay.c: gen/%/typeinfo relay_gen_c.py Makefile
.PRECIOUS: gen/%/c_relay
gen/%/c_relay: gen/%/c_relay.c gen/%/c_code.c Makefile
$(CC) $(CFLAGS) -o $@ $< -I../lib/c -I. -L..//lib/c \
gen/$*/c_code.c -llabcomm
gen/$*/c_code.c -llabcomm
# C# relay test rules
.PRECIOUS: gen/%/cs_code.cs
......
typedef void avoid;
sample avoid doavoid;
// examples of errors: void may not be used
// in structs or arrays
//
// sample struct {
// int a;
// avoid error;
//} foo;
//
//sample void error2[2] ;
//sample avoid error3[_];
typedef void avoid;
// examples of errors: void may not be used
// in structs or arrays
//
sample struct {
int a;
avoid error_1;
} foo;
sample void error_2[2] ;
sample avoid error_3[_];
#!/usr/bin/python
import sys
import argparse
import subprocess
# returns true if test fails
def test_labcomm_compile_OK(lc, args):
cmd = args.labcomm.split() + [lc]
try:
res = subprocess.check_call(cmd)
print "sucess!"
return False
except subprocess.CalledProcessError as ex:
print ex.output
print ex.returncode
return True
def test_labcomm_compile_fail(lc, args):
cmd = args.labcomm.split() + [lc]
try:
res = subprocess.check_call(cmd)
print "failed! (should have produced an error)"
return True
except subprocess.CalledProcessError as ex:
print "sucess!"
print ex.output
print ex.returncode
return False;
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Run test of error messages.')
parser.add_argument('--labcomm');
parser.add_argument('--testOK', nargs='*', default=[])
parser.add_argument('--testNOK', nargs='*', default=[])
args = parser.parse_args()
fail = False;
for test in args.testOK:
fail = fail or test_labcomm_compile_OK(test, args)
pass
for test in args.testNOK:
fail = fail or test_labcomm_compile_fail(test, args)
pass
if fail:
print "*** fail ***"
else:
print "*** success ***"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment