"""Replay the independent stored arithmetic fixtures through a CLI executable. Run: python3 scheme/testdata/check_arithmetic.py VILE_BINARY [REPORT_JSON] This manual CLI check is separate from V test-function counts. """ import json,math,pathlib,struct,subprocess,sys if len(sys.argv) not in (2,3):raise SystemExit('usage: check_arithmetic.py VILE_BINARY [REPORT_JSON]') binary=str(pathlib.Path(sys.argv[1]).resolve());fixture=pathlib.Path(__file__).with_name('arithmetic.tsv') rows=[line.split('\t') for line in fixture.read_text().splitlines() if line and not line.startswith(';')] def word(x):return struct.unpack('>Q',struct.pack('>d',x))[0] def check(row,text): kind,source,expected=row if kind=='text':assert text==expected,(source,text,expected);return if expected=='nan':assert text in ['+nan.0','-nan.0'],(source,text);return if expected in ['+inf','-inf']:assert text==expected+'.0',(source,text);return value=float(text);actual=word(value);target=int(expected) assert actual==target or (kind=='ulp' and abs(actual-target)<=4),(source,text,actual,target) valid=[row for row in rows if row[0]!='error'];errors=[row for row in rows if row[0]=='error'] for start in range(0,len(valid),32): batch=valid[start:start+32];cmd=[binary,'-s'] for _,source,_ in batch:cmd+=['-e',source] result=subprocess.run(cmd,text=True,capture_output=True,timeout=60) assert result.returncode==0 and not result.stderr,(result.stderr,batch) actual=result.stdout.splitlines();assert len(actual)==len(batch),(actual,batch) for row,text in zip(batch,actual):check(row,text) for row in errors: result=subprocess.run([binary,'-s','-e',row[1]],text=True,capture_output=True,timeout=10) assert result.returncode!=0,(row,result.stdout) assert not row[2] or row[2] in result.stderr,(row,result.stderr) report={'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.'} if len(sys.argv)==3:pathlib.Path(sys.argv[2]).write_text(json.dumps(report,indent=2)+'\n') print(json.dumps(report))