From 2b2cb091459f050f94c966a8e49fa70d8ccde395 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 1 Sep 2022 10:24:55 +0200 Subject: [PATCH] Add python version of run.sh --- tests/run.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 tests/run.py diff --git a/tests/run.py b/tests/run.py new file mode 100755 index 0000000..cb5d88d --- /dev/null +++ b/tests/run.py @@ -0,0 +1,38 @@ +#!/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)