-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
67 lines (55 loc) · 1.75 KB
/
test.py
File metadata and controls
67 lines (55 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import subprocess
import os
import difflib
# ANSI escape codes for colors
RED = "\033[91m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
BLUE = "\033[94m"
MAGENTA = "\033[95m"
CYAN = "\033[96m"
WHITE = "\033[97m"
RESET = "\033[0m"
TEST_DIR = "test_programs"
MYRPAL = "python myrpal.py"
RPAL = r"rpal\rpal.exe"
FLAGS = ["", "-ast", "-st"] # test all 3 modes
def run_cmd(cmd, input_path):
try:
result = subprocess.run(
cmd.split() + [input_path],
capture_output=True,
text=True,
timeout=5
)
return result.stdout.strip()
except subprocess.TimeoutExpired:
return "[ERROR] Timeout"
except Exception as e:
return f"[ERROR] {str(e)}"
def compare_outputs(file_path):
print(f"\n--- Testing {os.path.basename(file_path)} ---")
for flag in FLAGS:
print(f"Testing flag: {flag or '[no flag]'}")
# Run your RPAL implementation with the given flag
my_output = run_cmd(f"{MYRPAL} {flag}".strip(), file_path)
# Adjust flags for the reference RPAL — add `noout` to suppress final result if needed
ref_flag = f"{flag} -noout" if flag else ""
ref_output = run_cmd(f"{RPAL} {ref_flag}".strip(), file_path)
if os.name == 'nt':
os.system('')
if my_output == ref_output:
print(f"{GREEN}[PASS]{RESET} {flag}")
else:
print(f"{RED}[FAIL]{RESET} {flag}")
continue
print("---- Your Output ----")
print(my_output)
print("---- Ref Output ----")
print(ref_output)
def main():
for file in os.listdir(TEST_DIR):
if file.endswith(".txt"):
compare_outputs(os.path.join(TEST_DIR, file))
if __name__ == "__main__":
main()