Commit ba744ffa authored by Tom Niget's avatar Tom Niget

Update test_runner.py

parent 1ba51c0b
# coding: utf-8 # coding: utf-8
import argparse import argparse
import logging
#logging.basicConfig(level=logging.DEBUG)
from os import system, environ from os import system, environ
from pathlib import Path from pathlib import Path
...@@ -17,12 +19,15 @@ load_dotenv() ...@@ -17,12 +19,15 @@ load_dotenv()
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-c", "--compile", action="store_true") parser.add_argument("-c", "--compile", action="store_true")
parser.add_argument("-g", "--generate", action="store_true")
parser.add_argument("-o", "--only", nargs="+")
args = parser.parse_args() args = parser.parse_args()
def run_tests():
def run_tests():
for path in Path('tests').glob('*.py'): for path in Path('tests').glob('*.py'):
if args.only and path.stem not in args.only:
continue
print(path.name) print(path.name)
if path.name.startswith('_'): if path.name.startswith('_'):
print("Skipping") print("Skipping")
...@@ -30,6 +35,7 @@ def run_tests(): ...@@ -30,6 +35,7 @@ def run_tests():
with open(path, "r", encoding="utf-8") as f: with open(path, "r", encoding="utf-8") as f:
code = f.read() code = f.read()
execute = "# norun" not in code execute = "# norun" not in code
compile = "# nocompile" not in code
res = format_code(transpile(code, path.name, path)) res = format_code(transpile(code, path.name, path))
#print(res) #print(res)
name_cpp = path.with_suffix('.cpp') name_cpp = path.with_suffix('.cpp')
...@@ -38,15 +44,13 @@ def run_tests(): ...@@ -38,15 +44,13 @@ def run_tests():
print(".cpp generated") print(".cpp generated")
if args.compile: if args.compile:
continue continue
if not execute: execute_str = "true" if (execute and not args.generate) else "false"
print("Not executing", path.name)
continue
name_bin = path.with_suffix('').as_posix() name_bin = path.with_suffix('').as_posix()
commands = [ commands = [
f'bash -c "PYTHONPATH=stdlib python3 ./{path.as_posix()}"', f'bash -c "export PYTHONPATH=stdlib; if {execute_str}; then python3 ./{path.as_posix()}; fi"',
] ]
if alt := environ.get("ALT_RUNNER"): if compile and (alt := environ.get("ALT_RUNNER")):
commands.append(alt.format(name_bin=name_bin, name_cpp_posix=name_cpp.as_posix())) commands.append(alt.format(name_bin=name_bin, name_cpp_posix=name_cpp.as_posix(), run_file=execute_str))
else: else:
print("no ALT_RUNNER") print("no ALT_RUNNER")
for cmd in commands: for cmd in commands:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment