Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ test: $(TESTS:%=test_%)
clean distclean:
rm -rf gen
.PHONY: test_%
.PHONY: test_% testErrors
test_%: gen/%/signatures.py \
gen/%/c_relay \
gen/%/cs_relay.exe \
......@@ -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/$*
......
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 ***"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment