2021-04-15 22:39:08 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-05-27 20:59:09 +02:00
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
red = '\033[91m'
|
|
|
|
green = '\033[92m'
|
|
|
|
bold = '\033[1m'
|
|
|
|
reset = '\033[0m'
|
|
|
|
prefix_pass = bold + "[" + green + "PASS" + reset + bold + "]" + reset
|
|
|
|
prefix_fail = bold + "[" + red + "FAIL" + reset + bold + "]" + reset
|
|
|
|
|
|
|
|
|
|
|
|
def indent(text, spaces=4):
|
2016-07-20 20:23:20 +02:00
|
|
|
text = text.decode("utf-8")
|
2016-05-27 20:59:09 +02:00
|
|
|
prefix = " "
|
|
|
|
return "\n".join([prefix + line for line in text.split("\n")])
|
|
|
|
|
|
|
|
|
|
|
|
def run_test(test_name, path):
|
|
|
|
os.chdir(path)
|
|
|
|
process = subprocess.Popen(
|
2016-06-03 00:59:44 +02:00
|
|
|
["/bin/sh", "run.sh"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
(output, _) = process.communicate()
|
2016-05-27 20:59:09 +02:00
|
|
|
|
|
|
|
if os.path.exists("expected_fail"):
|
2016-07-20 20:23:20 +02:00
|
|
|
with open("expected_fail", "rb") as f:
|
2016-05-27 20:59:09 +02:00
|
|
|
expected_output = f.read()
|
2016-07-20 20:23:20 +02:00
|
|
|
if process.returncode == 0:
|
|
|
|
print("{} {}: unexpected success:".format(prefix_fail, test_name))
|
|
|
|
print("")
|
|
|
|
print(" Expected:")
|
|
|
|
print(indent(expected_output))
|
|
|
|
print(" Actual:")
|
|
|
|
print(indent(output))
|
|
|
|
return False
|
|
|
|
elif not output.endswith(expected_output):
|
2016-05-27 20:59:09 +02:00
|
|
|
print("{} {}: expected output mismatch".format(
|
|
|
|
prefix_fail, test_name))
|
|
|
|
print("")
|
|
|
|
print(" Expected:")
|
|
|
|
print(indent(expected_output))
|
|
|
|
print(" Actual:")
|
|
|
|
print(indent(output))
|
|
|
|
return False
|
|
|
|
elif process.returncode != 0:
|
|
|
|
print("{} {}: unexpected failure:".format(prefix_fail, test_name))
|
|
|
|
print("")
|
|
|
|
print(indent(output))
|
|
|
|
return False
|
|
|
|
|
|
|
|
print("{} {}".format(prefix_pass, test_name))
|
|
|
|
return True
|
|
|
|
|
2016-08-15 23:19:05 +02:00
|
|
|
|
|
|
|
def usage():
|
|
|
|
print("Usage: run_tests.py [-f]")
|
|
|
|
print(" -f\t\tdon't run slow tests")
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
2016-05-27 20:59:09 +02:00
|
|
|
root_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
test_dir = os.path.join(root_dir, "tests")
|
|
|
|
tests = os.listdir(test_dir)
|
2016-08-15 23:19:05 +02:00
|
|
|
run_slow = True
|
|
|
|
|
|
|
|
if len(sys.argv) > 2:
|
|
|
|
usage()
|
|
|
|
elif len(sys.argv) == 2:
|
|
|
|
if sys.argv[1] != "-f":
|
|
|
|
usage()
|
|
|
|
run_slow = False
|
2016-05-27 20:59:09 +02:00
|
|
|
|
|
|
|
success = True
|
|
|
|
for test in sorted(tests):
|
2016-08-15 23:19:05 +02:00
|
|
|
if test.startswith("slow") and not run_slow:
|
|
|
|
continue
|
2016-08-15 20:30:41 +02:00
|
|
|
path = os.path.join(test_dir, test)
|
|
|
|
if not os.path.isdir(path):
|
|
|
|
continue
|
|
|
|
if not run_test(test, path):
|
2016-05-27 20:59:09 +02:00
|
|
|
success = False
|
|
|
|
|
|
|
|
sys.exit(0 if success else 1)
|