forked from soplang/soplang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_examples.py
More file actions
78 lines (62 loc) · 2.32 KB
/
check_examples.py
File metadata and controls
78 lines (62 loc) · 2.32 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
68
69
70
71
72
73
74
75
76
77
78
import os
import subprocess
import sys
# Files that are expected to have errors as part of their test
EXPECTED_ERROR_FILES = [
"22_constant_reassignment_test.sop",
"24_constant_type_error_test.sop",
"25_constant_type_error.sop",
]
def run_example(filepath, filename):
"""Run a Soplang example file and return success/failure with error message"""
try:
result = subprocess.run(
["python", "main.py", filepath],
capture_output=True,
text=True,
timeout=5, # 5 second timeout
)
# For files that are supposed to demonstrate errors, a returncode of 0
# and the presence of specific error messages is a success
if filename in EXPECTED_ERROR_FILES:
# These files are expected to fail with specific errors
if result.returncode != 0 or "Khalad" in result.stdout:
return True, None
# For normal files
if result.returncode == 0 and "Khalad" not in result.stdout:
return True, None
else:
return False, result.stdout or result.stderr
except Exception as e:
return False, str(e)
def main():
"""Check all example files in the examples directory"""
examples_dir = "examples"
files = [f for f in os.listdir(examples_dir) if f.endswith(".sop")]
files.sort() # Sort files for consistent output
print(f"Testing {len(files)} example files...\n")
successful = []
failed = []
for filename in files:
filepath = os.path.join(examples_dir, filename)
print(f"Testing {filename}...", end=" ")
success, error = run_example(filepath, filename)
if success:
print("✅ Success")
successful.append(filename)
else:
print("❌ Failed")
failed.append((filename, error))
print(f"\nSummary: {len(successful)} successful, {len(failed)} failed")
if failed:
print("\nFailed files:")
for filename, error in failed:
print(f"\n{filename}:")
error_lines = error.split("\n")[:5] # Show first 5 lines of error
for line in error_lines:
print(f" {line}")
if len(error.split("\n")) > 5:
print(" ...")
return len(failed)
if __name__ == "__main__":
sys.exit(main())