def run_tests(src_file='tests.scm'):
"""Run a read-eval loop that reads from src_file and collects outputs."""
sys.stderr = sys.stdout = io.StringIO() # Collect output to stdout and stderr
reader = None
try:
reader = TestReader(open(src_file).readlines(), sys.stdout)
src = Buffer(tokenize_lines(reader))
def next_line():
src.current()
return src
read_eval_print_loop(next_line, create_global_frame())
except BaseException as exc:
sys.stderr = sys.__stderr__
if reader:
print("Tests terminated due to unhandled exception "
"after line {0}:\n>>>".format(reader.line_number),
file=sys.stderr)
raise
finally:
sys.stdout = sys.__stdout__ # Revert stdout
sys.stderr = sys.__stderr__ # Revert stderr
summarize(reader.output, reader.expected_output)
评论列表
文章目录