-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_gitmem.py
More file actions
59 lines (49 loc) · 1.73 KB
/
test_gitmem.py
File metadata and controls
59 lines (49 loc) · 1.73 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
import os
import subprocess
import sys
import argparse
EXAMPLES_DIR = "examples"
def run_gitmem_test(gitmem_path, file_path, should_pass):
try:
result = subprocess.run([gitmem_path, file_path, "-e", "-o", "/dev/null"], capture_output=True, text=True)
passed = (result.returncode == 0)
except FileNotFoundError:
print(f"Error: '{gitmem_path}' executable not found.")
sys.exit(1)
if passed == should_pass:
status = "PASS"
else:
status = "FAIL"
print(f"[{status}] {file_path} (exit code: {result.returncode})")
return status == "PASS"
def main():
parser = argparse.ArgumentParser(description="Test runner for gitmem.")
parser.add_argument(
"--gitmem", "-g",
required=True,
help="Path to the gitmem executable"
)
args = parser.parse_args()
gitmem_path = args.gitmem
total_tests = 0
failed_tests = 0
for outcome in ["passing", "failing"]:
should_pass = (outcome == "passing")
for category in ["syntax", "semantics"]:
test_dir = os.path.join(EXAMPLES_DIR, outcome, category)
if not os.path.isdir(test_dir):
continue
for root, _, files in os.walk(test_dir):
for file in files:
file_path = os.path.join(root, file)
total_tests += 1
if not run_gitmem_test(gitmem_path, file_path, should_pass):
failed_tests += 1
print("\nSummary:")
print(f"Total tests run: {total_tests}")
print(f"Tests failed: {failed_tests}")
print(f"Tests passed: {total_tests - failed_tests}")
if failed_tests > 0:
sys.exit(1)
if __name__ == "__main__":
main()