marmoset-test-cases/run-tests.py

27 lines
1.0 KiB
Python
Raw Normal View History

2023-09-11 20:51:15 +01:00
#!/bin/python3
import glob
import subprocess
import os
2023-09-12 13:24:27 +01:00
import sys
2023-09-11 20:51:15 +01:00
# will break if there are namespace collisions
file_list = [x.rstrip(".case") for x in glob.glob(f"{os.path.dirname(__file__)}/**/*.case", recursive=True)]
file_only_list = [os.path.basename(x) for x in file_list]
2023-09-12 13:24:27 +01:00
if sys.platform == "win32":
2023-09-12 13:28:27 +01:00
subprocess.run("color", check=True) # enables ANSI escape characters, bug in Python
2023-09-12 13:24:27 +01:00
2023-09-11 20:51:15 +01:00
for file_name in glob.glob("*.c", recursive=False):
if file_name.rstrip(".c") in file_only_list:
should_continue = input(f"{file_name}; run (y/N)?").lower()
if should_continue is not "y":
continue
subprocess.run(["gcc", "-std=c11", "-Wall", "-g", file_name], check=True)
with open(next(x for x in file_list if file_name in x)) as f:
to_run = f.read().split("\n\n")
for x in to_run:
2023-09-12 13:24:27 +01:00
return_data = subprocess.run(["./a.out"], input=x[0].rstrip(), capture_output=True).stdout
print(f"\u001b[{31 + int(return_data.rstrip() == x[1].rstrip())}m{return_data}\u001b[0m")