diff --git a/tests/2-ir-gen/autogen/eval_lab2.py b/tests/2-ir-gen/autogen/eval_lab2.py index 0d4298551bd2a10f6b1a8f306a0e896f274cc9a5..7bea8849af66a5a162a809a63aa835a8e822f932 100755 --- a/tests/2-ir-gen/autogen/eval_lab2.py +++ b/tests/2-ir-gen/autogen/eval_lab2.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +from pathlib import Path import subprocess # 17 lv0_1 = { @@ -110,6 +111,11 @@ suite = [ ] +def cleanup_case(test_path): + for path in (test_path, test_path + ".o", test_path + ".ll"): + Path(path).unlink(missing_ok=True) + + def eval(): f = open("eval_result", 'w') EXE_PATH = "../../../build/cminusfc" @@ -129,6 +135,7 @@ def eval(): ANSWER_PATH = ANSWER_BASE_PATH + level_name + "/" + case score = cases[case][0] need_input = cases[case][1] + cleanup_case(TEST_PATH) COMMAND = [TEST_PATH] @@ -136,12 +143,21 @@ def eval(): result = subprocess.run([EXE_PATH, "-o", TEST_PATH + ".ll", "-emit-llvm", TEST_PATH + ".cminus"], stderr=subprocess.PIPE, timeout=1) except Exception as _: + cleanup_case(TEST_PATH) f.write('\tFail\n') continue if result.returncode == 0: - subprocess.run(["clang", "-O0", "-w", "-no-pie", TEST_PATH + - ".ll", "-o", TEST_PATH, "-L", "../../../build", "-lcminus_io"]) + try: + compile_result = subprocess.run(["clang", "-O0", "-w", "-no-pie", TEST_PATH + + ".ll", "-o", TEST_PATH, "-L", "../../../build", "-lcminus_io"]) + except OSError: + compile_result = None + if compile_result is None or compile_result.returncode != 0: + f.write('\tFail\n') + has_bonus = False + cleanup_case(TEST_PATH) + continue input_option = None if need_input: with open(ANSWER_PATH + ".in", "rb") as fin: @@ -161,10 +177,10 @@ def eval(): f.write('\tFail\n') has_bonus = False finally: - subprocess.call( - ["rm", "-rf", TEST_PATH, TEST_PATH + ".o", TEST_PATH + ".ll"]) + cleanup_case(TEST_PATH) else: + cleanup_case(TEST_PATH) f.write('\tFail\n') has_bonus = False diff --git a/tests/2-ir-gen/autogen/eval_lab2.sh b/tests/2-ir-gen/autogen/eval_lab2.sh index 20fefb1918343f32bcee908a58a97b305400e78b..49dc00a0c45c55931948adb24e5d9a0cf9962e70 100755 --- a/tests/2-ir-gen/autogen/eval_lab2.sh +++ b/tests/2-ir-gen/autogen/eval_lab2.sh @@ -1,3 +1,4 @@ #!/bin/bash +cd "$(dirname "$0")" || exit 1 python3 eval_lab2.py