Files
2125_GCE/integration_tests/test_run.py
T

98 lines
2.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import sys
from pathlib import Path
sys.path.insert(0, str(Path.cwd()))
from gx_cli.main import main
def test_run_basic():
"""Test running a .gx file"""
# First compile a test file
gx_path = Path("/tmp/test_run_basic.gx")
compile_code = main(["compile", "/home/dave/sample_code.py", "-o", str(gx_path)])
if compile_code != 0:
print("FAIL: compilation failed")
return False
# Now run it
exit_code = main(["run", str(gx_path)])
if exit_code != 0:
print("FAIL: run returned non-zero exit code")
return False
print("PASS: Executed .gx file successfully")
return True
def test_run_executes_code():
"""Test that running .gx actually executes the code"""
import io
import contextlib
# Create a simple test Python file
test_py = Path("/tmp/test_simple.py")
test_py.write_text("print('EXECUTION_SUCCESS')\nresult = 42")
gx_path = Path("/tmp/test_simple.gx")
# Compile it
compile_code = main(["compile", str(test_py), "-o", str(gx_path)])
if compile_code != 0:
print("FAIL: compilation failed")
return False
# Capture output
f = io.StringIO()
with contextlib.redirect_stdout(f):
exit_code = main(["run", str(gx_path)])
output = f.getvalue()
if exit_code != 0:
print("FAIL: run returned non-zero")
return False
if "EXECUTION_SUCCESS" not in output:
print("FAIL: code was not executed (output missing)")
return False
print("PASS: Code execution verified")
return True
def main_test():
print("[TEST SUITE] test_run.py")
print()
tests = [
("Basic run", test_run_basic),
("Code execution", test_run_executes_code),
]
passed = 0
failed = 0
for name, test_func in tests:
print(f"Running: {name}...", end=" ")
try:
if test_func():
passed += 1
else:
failed += 1
except Exception as e:
print(f"FAIL: {e}")
failed += 1
print()
print(f"Results: {passed} passed, {failed} failed")
return 0 if failed == 0 else 1
if __name__ == "__main__":
sys.exit(main_test())