1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#!/usr/bin/env python3
# execute isolated icon acceptance, rejection and regression fixtures.
from pathlib import Path
import argparse
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument('vm', nargs='?', default='bin/zy')
parser.add_argument('--case', default='')
parser.add_argument('--js', action='store_true')
parser.add_argument('--source', action='store_true', help='test the working library source instead of the embedded module')
args = parser.parse_args()
root = Path(__file__).resolve().parents[2]
cases = sorted((root / 'tests/icon').glob('*/*.zc'))
count = 0
for case in cases:
if args.case and args.case not in str(case):
continue
expected = case.with_suffix('.expected').read_text()
command = ['node', str(root / 'src/js/tinyvm.js')] if args.js else [str(root / args.vm)]
program = case.read_text()
if args.source:
# keep module imports while suppressing its embedded source loader.
library = (root / 'src/lib/icon.zc').read_text()
setup = '\nnamespace;\ninclude run;\nimmediate fn icon_working_source() { run.icon_done = 1; run.next(); return 0; }\nicon_working_source\n'
program = library + setup + program
proc = subprocess.run(command, input=program, text=True, capture_output=True, cwd=root, timeout=30)
assert proc.returncode == 0 and proc.stdout == expected, f'{case.relative_to(root)}\nstdout: {proc.stdout}\nstderr: {proc.stderr}\nexpected: {expected}'
print(f'ok {case.relative_to(root)}')
count += 1
assert count, 'no icon fixtures selected'
print(f'{count} icon fixtures passed')
|