26 lines
782 B
Python
26 lines
782 B
Python
import glob, sys, subprocess
|
|
|
|
_, src, test, t = sys.argv
|
|
|
|
ig = glob.glob(f'test/{test}/*.in')
|
|
og = glob.glob(f'test/{test}/*.ans')
|
|
|
|
print(test, len(ig), 'tests')
|
|
|
|
for ifn, ofn in zip(ig, og):
|
|
with open(ifn) as fi, open(ofn) as fx:
|
|
try:
|
|
o = subprocess.check_output(['python', src],
|
|
stdin=fi, stderr=subprocess.STDOUT,
|
|
timeout=float(t))
|
|
except subprocess.CalledProcessError as e:
|
|
o = e.output
|
|
except subprocess.TimeoutExpired:
|
|
o = b'TIMED OUT'
|
|
|
|
o = o.decode().strip().replace('\r\n', '\n')
|
|
x = fx.read().strip().replace('\r\n', '\n')
|
|
|
|
if o != x:
|
|
print(ifn, 'expected:', x, 'got:', o, '=' * 50, sep='\n')
|