#!/usr/bin/env python import os, subprocess teststimeout=20 # Max duration of a test testspath = os.path.dirname(os.path.realpath(__file__)) for file in os.listdir(testspath): testpath=os.path.join(testspath,file) if os.path.isdir(testpath): simulatorpath=os.path.join(testpath,"simulator.py") outpath=os.path.join(testpath,"out") print("- %-50s%s " % (file,"=>"),end='') try: out=subprocess.check_output(simulatorpath, stderr=subprocess.STDOUT,timeout=teststimeout).decode("utf-8") outexpected=open(outpath).read() if outexpected != out: print("failed :(") print("------------- Expected -------------") print(outexpected,end="") print("------------- Got -------------") print(out,end="") else: print("passed") except subprocess.TimeoutExpired as err: print("failed :(") print("------------- Test timeout (should not exceed "+str(teststimeout)+"s) -------------") print(err.output.decode("utf-8"),end="") exit(1) except subprocess.CalledProcessError as err: print("failed :(") print("------------- Non test has a non-zero exit code -------------") print(err.output.decode("utf-8"),end="") exit(2) except Exception as err: print("failed :(") print("Reason: "+str(err)) exit(3)