forked from wavefnd/Wave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
115 lines (92 loc) · 2.98 KB
/
run_tests.py
File metadata and controls
115 lines (92 loc) · 2.98 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
#!/usr/bin/env python3
import subprocess
import time
from pathlib import Path
import threading
import socket
ROOT = Path(__file__).resolve().parent.parent
TEST_DIR = ROOT / "test"
WAVEC = ROOT / "target" / "release" / "wavec"
TIMEOUT_SEC = 5
GREEN = "\033[92m"
RED = "\033[91m"
YELLOW = "\033[93m"
BLUE = "\033[94m"
CYAN = "\033[96m"
RESET = "\033[0m"
KNOWN_TIMEOUT = {
"test22.wave", # input() not implemented
}
if not WAVEC.exists():
print("wavec not found. Run `cargo build --release` first.")
exit(1)
results = []
def send_udp_for_test61():
time.sleep(0.5)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(b"hello from python\n", ("127.0.0.1", 8080))
sock.close()
def run_and_classify(name, cmd):
print(f"{BLUE}RUN {name}{RESET}")
try:
if name == "test61.wave":
t = threading.Thread(target=send_udp_for_test61, daemon=True)
t.start()
result = subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
timeout=TIMEOUT_SEC
)
if result.returncode == 0:
print(f"{GREEN}→ PASS{RESET}\n")
return 1
else:
print(f"{RED}→ FAIL (exit={result.returncode}){RESET}\n")
return 0
except subprocess.TimeoutExpired:
if name in KNOWN_TIMEOUT:
print(f"{CYAN}→ SKIP (expected blocking / unimplemented){RESET}\n")
return 2
else:
print(f"{YELLOW}→ TIMEOUT ({TIMEOUT_SEC}s){RESET}\n")
return -1
for path in sorted(TEST_DIR.glob("test*.wave")):
name = path.name
cmd = [str(WAVEC), "run", f"test/{name}"]
result = run_and_classify(name, cmd)
results.append((name, result))
time.sleep(0.3)
test28 = TEST_DIR / "test28" / "main.wave"
if test28.exists():
result = run_and_classify(
"test28 (dir)",
[str(WAVEC), "run", "test/test28/main.wave"]
)
results.append(("test28 (dir)", result))
pass_tests = [name for name, r in results if r == 1]
fail_tests = [name for name, r in results if r == 0]
timeout_tests = [name for name, r in results if r == -1]
skip_tests = [name for name, r in results if r == 2]
print("\n=========================")
print("🎉 FINAL TEST RESULT")
print("=========================\n")
print(f"{GREEN}PASS ({len(pass_tests)}){RESET}")
for name in pass_tests:
print(f" - {name}")
print(f"\n{CYAN}SKIP ({len(skip_tests)}){RESET}")
for name in skip_tests:
print(f" - {name}")
print(f"\n{RED}FAIL ({len(fail_tests)}){RESET}")
for name in fail_tests:
print(f" - {name}")
print(f"\n{YELLOW}TIMEOUT ({len(timeout_tests)}){RESET}")
for name in timeout_tests:
print(f" - {name}")
print("\n=========================")
print(f"{GREEN}PASS: {len(pass_tests)}{RESET}")
print(f"{CYAN}SKIP: {len(skip_tests)}{RESET}")
print(f"{RED}FAIL: {len(fail_tests)}{RESET}")
print(f"{YELLOW}TIMEOUT: {len(timeout_tests)}{RESET}")
print("=========================\n")