~maelkum/viuavm

e4cf5c5d6d6cbc2e2632f97f8b79301e967067d6 — Marek Marecki 9 months ago d8b5c19
Pipe stdin for test cases which require it
1 files changed, 13 insertions(+), 7 deletions(-)

M new/tests/suite.py
M new/tests/suite.py => new/tests/suite.py +13 -7
@@ 649,7 649,7 @@ def consume_live_ebreak_lines(ebreak_lines):
    return ebreak


def run_and_capture(interpreter, executable, args=()):
def run_and_capture(interpreter, executable, *, args=(), stdin=None):
    (
        read_fd,
        write_fd,


@@ 659,6 659,7 @@ def run_and_capture(interpreter, executable, args=()):
    env["VIUA_VM_TRACE_FD"] = str(write_fd)
    proc = subprocess.Popen(
        args=(interpreter,) + (executable,) + args,
        stdin=(subprocess.DEVNULL if stdin is None else subprocess.PIPE),
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        pass_fds=(write_fd,),


@@ 666,7 667,7 @@ def run_and_capture(interpreter, executable, args=()):
        text=True,
    )
    os.close(write_fd)
    (stdout, stderr) = proc.communicate()
    (stdout, stderr) = proc.communicate(input=stdin)
    result = proc.wait()

    buffer = b""


@@ 888,10 889,18 @@ def test_case_impl(case_log, case_name, test_program, errors):
            None,
        )

    result, ebreak, abort_report, perf = run_and_capture(
    test_stdin = None
    if os.path.isfile(stdin_path := f"{base_name}.stdin"):
        with open(stdin_path, "r") as ifstream:
            test_stdin = ifstream.read()

    run_test = lambda: run_and_capture(
        INTERPRETER,
        test_executable,
        stdin=test_stdin,
    )

    result, ebreak, abort_report, perf = run_test()
    r_exit = result["exit"]

    if r_exit == -6 and check_kind == "abort":


@@ 1129,10 1138,7 @@ def test_case_impl(case_log, case_name, test_program, errors):
            None,
        )

    result, ebreak, abort_report, _ = run_and_capture(
        INTERPRETER,
        test_executable,
    )
    result, ebreak, abort_report, _ = run_test()
    r_exit = result["exit"]

    if r_exit == -6 and check_kind == "abort":