feat: add foreign function support

This commit is contained in:
2026-04-22 22:56:39 +02:00
parent 041a49e574
commit 8bcae8cb31
13 changed files with 368 additions and 46 deletions
+12
View File
@@ -12,6 +12,7 @@ def run_test(test_file: Path, compiler_bin: Path):
expected_code = 0
code_lines = []
harness_lines = None
expected_output_lines = None
current_section = None
for line in lines:
@@ -20,6 +21,8 @@ def run_test(test_file: Path, compiler_bin: Path):
current_section = trimmed[1:-1]
if current_section == "harness":
harness_lines = []
elif current_section == "expected_output":
expected_output_lines = []
elif current_section:
if current_section == "expected_return_code":
if trimmed:
@@ -28,6 +31,8 @@ def run_test(test_file: Path, compiler_bin: Path):
code_lines.append(line)
elif current_section == "harness":
harness_lines.append(line)
elif current_section == "expected_output":
expected_output_lines.append(line)
code = "".join(code_lines)
harness = "".join(harness_lines) if harness_lines is not None else None
@@ -75,6 +80,13 @@ def run_test(test_file: Path, compiler_bin: Path):
if exec_res.returncode != expected_code:
raise Exception(f"Expected return code {expected_code}, but got {exec_res.returncode}")
# 4. Check the standard output if expected_output is provided
if expected_output_lines is not None:
expected_out = "".join(expected_output_lines).strip()
actual_out = exec_res.stdout.strip()
if expected_out != actual_out:
raise Exception(f"Expected output:\n{expected_out}\n\nActual output:\n{actual_out}")
def main():
GREEN = '\033[92m'
RED = '\033[91m'