import sys import shlex import subprocess from pathlib import Path from tqdm import tqdm from timeit import default_timer 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")) print(f"Collected {len(test_files)} tests (before filtering)") start = default_timer() for i, test_file in enumerate(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) out.check_returncode() except subprocess.CalledProcessError as e: failed.add(test_file) continue if not all(map(lambda s: s == b"true", out.stdout.splitlines())): failed.add(test_file) time_taken = default_timer() - start total = len(tests) successful = len(tests - failed - skipped) print(f"Test suite ran in {time_taken:.2f} seconds ({successful}/{total}) passed, {len(failed)}/{total} failed, {len(skipped)}/{total} skipped)") if failed: failed_tests = "\n\t- ".join(map(str, failed)) print(f"Failed tests:\n\t- {failed_tests}") return len(failed) == 0 if __name__ == "__main__": sys.exit(main())