diff options
Diffstat (limited to 'tests/drivers/compiler_contract_test.py')
| -rw-r--r-- | tests/drivers/compiler_contract_test.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/drivers/compiler_contract_test.py b/tests/drivers/compiler_contract_test.py new file mode 100644 index 0000000..63e476c --- /dev/null +++ b/tests/drivers/compiler_contract_test.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +"""accept/reject contracts, selectable in small groups before implementation.""" +import argparse +import json +import re +import subprocess +from pathlib import Path + +parser = argparse.ArgumentParser() +parser.add_argument('host') +parser.add_argument('--group') +parser.add_argument('--case') +args = parser.parse_args() +cases = json.loads(Path('tests/spec/compiler_contracts.json').read_text()) +cases = [c for c in cases if (not args.group or c['group'] == args.group) and (not args.case or args.case in c['name'])] +assert cases, 'no selected contracts' +failures = [] +for c in cases: + source = ('typecheck on;\n' + c['source']).encode() + r = subprocess.run([args.host], input=source, capture_output=True, timeout=10) + text = (r.stdout + r.stderr).decode(errors='replace') + error = bool(re.search(r'(zc:|zc0:|error:|undefined|not defined)', text)) or r.returncode != 0 + valid = (not error) == c['accept'] and r.returncode >= 0 + if valid and 'output' in c: + valid = r.returncode == 0 and r.stdout.decode() == c['output'] + print(('ok ' if valid else 'FAIL ') + c['group'] + ': ' + c['name']) + if not valid: + failures.append(c['name']) + print(text.strip()[:1000]) +raise SystemExit(1 if failures else 0) |
