40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
import sys
|
|
from tqdm import tqdm
|
|
import shlex
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
NIM_FLAGS = "-d:debug"
|
|
PEON_FLAGS = "-n --showMismatches"
|
|
EXCLUDE = ["fib.pn", "gc.pn", "import_a.pn", "import_b.pn", "fizzbuzz.pn"]
|
|
|
|
|
|
def main() -> int:
|
|
tests: set[Path] = set()
|
|
skipped: set[Path] = set()
|
|
failed: set[Path] = set()
|
|
# We consume the generator now because I want tqdm to show the progress bar!
|
|
test_files = list((Path.cwd() / "tests").resolve(strict=True).glob("*.pn"))
|
|
for test_file in tqdm(test_files):
|
|
tests.add(test_file)
|
|
if test_file.name in EXCLUDE:
|
|
skipped.add(test_file)
|
|
continue
|
|
try:
|
|
cmd = f"nim {NIM_FLAGS} r src/main.nim {test_file} {PEON_FLAGS}"
|
|
out = subprocess.run(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"An error occurred while executing test -> {type(e).__name__}: {e}")
|
|
failed.add(test_file)
|
|
continue
|
|
if not all(map(lambda s: s == b"true", out.stdout.splitlines())):
|
|
failed.add(test_file)
|
|
total = len(tests)
|
|
successful = len(tests - failed - skipped)
|
|
print(f"Collected {total} tests ({successful}/{total}) passed, {len(failed)}/{total} failed, {len(skipped)}/{total} skipped)")
|
|
return len(failed) == 0
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main()) |