-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_gitmem.py
More file actions
182 lines (149 loc) · 4.53 KB
/
test_gitmem.py
File metadata and controls
182 lines (149 loc) · 4.53 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import os
import subprocess
import sys
import argparse
from collections import defaultdict
EXAMPLES_DIR = "examples"
SYNC_KINDS = {
"linear": {"sync": "linear"},
"branching-eager": {"sync": "branching", "branching_mode": "eager"},
"branching-lazy": {"sync": "branching", "branching_mode": "lazy"},
}
def supports_color():
return sys.stdout.isatty() and os.getenv("NO_COLOR") is None
def color(text, code):
if not supports_color():
return text
return f"\033[{code}m{text}\033[0m"
def green(text):
return color(text, "32")
def red(text):
return color(text, "31")
def run_gitmem_test(gitmem_path, file_path, should_accept, sync_kind):
sync_config = SYNC_KINDS[sync_kind]
cmd = [
gitmem_path,
file_path,
"--sync", sync_config["sync"],
]
if "branching_mode" in sync_config:
cmd.extend(["--branching-mode", sync_config["branching_mode"]])
cmd.extend([
"-e",
"-o", "/dev/null"
])
try:
result = subprocess.run(
cmd,
capture_output=True,
text=True
)
if should_accept:
accepted = (result.returncode == 0)
else:
accepted = (result.returncode == 1)
except FileNotFoundError:
print(f"Error: '{gitmem_path}' executable not found.")
sys.exit(1)
status = green("PASS") if accepted else red("FAIL")
print(f"[{status}] {file_path} [{sync_kind}] (exit code: {result.returncode})")
return accepted
def main():
parser = argparse.ArgumentParser(description="Test runner for gitmem.")
parser.add_argument(
"--gitmem", "-g",
required=True,
help="Path to the gitmem executable"
)
parser.add_argument(
"--linear",
action="store_true",
help="Only run linear sync tests"
)
parser.add_argument(
"--branching-eager",
action="store_true",
help="Only run branching-eager tests"
)
parser.add_argument(
"--branching-lazy",
action="store_true",
help="Only run branching-lazy tests"
)
args = parser.parse_args()
gitmem_path = args.gitmem
selected_syncs = []
if args.linear:
selected_syncs.append("linear")
if args.branching_eager:
selected_syncs.append("branching-eager")
if args.branching_lazy:
selected_syncs.append("branching-lazy")
# If none specified, run all
if not selected_syncs:
selected_syncs = list(SYNC_KINDS.keys())
results = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: {
"total": 0,
"failed": 0
})))
total_tests = 0
failed_tests = 0
failing_tests = []
for expectation in ["accept", "reject"]:
should_accept = (expectation == "accept")
for category in ["syntax", "semantics"]:
base_dir = os.path.join(EXAMPLES_DIR, expectation, category)
if not os.path.isdir(base_dir):
continue
for sync_kind in selected_syncs:
# syntax tests are sync-agnostic → only run once
if category == "syntax" and sync_kind != "linear":
continue
if category == "semantics":
if sync_kind == "linear":
test_dir = os.path.join(base_dir, "linear")
else:
test_dir = os.path.join(base_dir, "branching")
else:
test_dir = base_dir
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
results[expectation][category][sync_kind]["total"] += 1
passed = run_gitmem_test(
gitmem_path,
file_path,
should_accept,
sync_kind
)
if not passed:
failed_tests += 1
results[expectation][category][sync_kind]["failed"] += 1
failing_tests.append((file_path, sync_kind))
print("\nDetailed Summary:")
for expectation, categories in results.items():
print(f"\n{expectation.upper()}:")
for category, syncs in categories.items():
print(f" {category}:")
for sync_kind, stats in syncs.items():
passed = stats["total"] - stats["failed"]
print(
f" {sync_kind}: "
f"{passed}/{stats['total']} passed "
f"({stats['failed']} failed)"
)
print("\nOverall Summary:")
print(f"Total tests run: {total_tests}")
print(f"Tests failed: {failed_tests}")
print(f"Tests passed: {total_tests - failed_tests}")
if failing_tests:
print("\nFailing tests:")
for path, sync in failing_tests:
print(f" {red(path)} [{sync}]")
if failed_tests > 0:
sys.exit(1)
if __name__ == "__main__":
main()