| 1 | """Replay the independent stored arithmetic fixtures through a CLI executable. |
| 2 | Run: python3 scheme/testdata/check_arithmetic.py VILE_BINARY [REPORT_JSON] |
| 3 | This manual CLI check is separate from V test-function counts. |
| 4 | """ |
| 5 | import json,math,pathlib,struct,subprocess,sys |
| 6 | if len(sys.argv) not in (2,3):raise SystemExit('usage: check_arithmetic.py VILE_BINARY [REPORT_JSON]') |
| 7 | binary=str(pathlib.Path(sys.argv[1]).resolve());fixture=pathlib.Path(__file__).with_name('arithmetic.tsv') |
| 8 | rows=[line.split('\t') for line in fixture.read_text().splitlines() if line and not line.startswith(';')] |
| 9 | def word(x):return struct.unpack('>Q',struct.pack('>d',x))[0] |
| 10 | def 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) |
| 17 | valid=[row for row in rows if row[0]!='error'];errors=[row for row in rows if row[0]=='error'] |
| 18 | for 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) |
| 25 | for 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) |
| 29 | 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.'} |
| 30 | if len(sys.argv)==3:pathlib.Path(sys.argv[2]).write_text(json.dumps(report,indent=2)+'\n') |
| 31 | print(json.dumps(report)) |
| 32 | |