vile / scheme / testdata / check_arithmetic.py
31 lines · 31 sloc · 2.1 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1"""Replay the independent stored arithmetic fixtures through a CLI executable.
2Run: python3 scheme/testdata/check_arithmetic.py VILE_BINARY [REPORT_JSON]
3This manual CLI check is separate from V test-function counts.
4"""
5import json,math,pathlib,struct,subprocess,sys
6if len(sys.argv) not in (2,3):raise SystemExit('usage: check_arithmetic.py VILE_BINARY [REPORT_JSON]')
7binary=str(pathlib.Path(sys.argv[1]).resolve());fixture=pathlib.Path(__file__).with_name('arithmetic.tsv')
8rows=[line.split('\t') for line in fixture.read_text().splitlines() if line and not line.startswith(';')]
9def word(x):return struct.unpack('>Q',struct.pack('>d',x))[0]
10def check(row,text):
11 kind,source,expected=row
12 if kind=='text':assert text==expected,(source,text,expected);return
13 if expected=='nan':assert text in ['+nan.0','-nan.0'],(source,text);return
14 if expected in ['+inf','-inf']:assert text==expected+'.0',(source,text);return
15 value=float(text);actual=word(value);target=int(expected)
16 assert actual==target or (kind=='ulp' and abs(actual-target)<=4),(source,text,actual,target)
17valid=[row for row in rows if row[0]!='error'];errors=[row for row in rows if row[0]=='error']
18for start in range(0,len(valid),32):
19 batch=valid[start:start+32];cmd=[binary,'-s']
20 for _,source,_ in batch:cmd+=['-e',source]
21 result=subprocess.run(cmd,text=True,capture_output=True,timeout=60)
22 assert result.returncode==0 and not result.stderr,(result.stderr,batch)
23 actual=result.stdout.splitlines();assert len(actual)==len(batch),(actual,batch)
24 for row,text in zip(batch,actual):check(row,text)
25for row in errors:
26 result=subprocess.run([binary,'-s','-e',row[1]],text=True,capture_output=True,timeout=10)
27 assert result.returncode!=0,(row,result.stdout)
28 assert not row[2] or row[2] in result.stderr,(row,result.stderr)
29report={'status':'passed','fixture_cases':len(rows),'successful_results':len(valid),'expected_errors':len(errors),'classification':'Manual CLI replay of independently generated fixtures; not additional committed V test-function count.'}
30if len(sys.argv)==3:pathlib.Path(sys.argv[2]).write_text(json.dumps(report,indent=2)+'\n')
31print(json.dumps(report))
32