snapshot before regression test

This commit is contained in:
t
2026-07-18 19:25:40 +08:00
commit 796222a300
2295 changed files with 206453 additions and 0 deletions

71
includes/testcheck.py Normal file
View File

@@ -0,0 +1,71 @@
# testcheck - 回归测试格式化输出库
# 提供 PASS/FAIL 计数、分节标题、汇总报告
import t, c
import stdio
from w32.win32console import SetConsoleOutputCP, SetConsoleCP
CP_UTF8: t.CDefine = 65001
_pass_count: t.CInt = 0
_fail_count: t.CInt = 0
_total_pass: t.CInt = 0
_total_fail: t.CInt = 0
def begin(name: str):
"""开始测试套件,打印头部并重置当前套件计数器(累计计数不变)"""
global _pass_count, _fail_count
_pass_count = 0
_fail_count = 0
SetConsoleOutputCP(CP_UTF8)
SetConsoleCP(CP_UTF8)
stdio.printf("=== %s ===\n\n", name)
def section(name: str):
"""打印分节标题"""
stdio.printf("--- %s ---\n", name)
def ok(msg: str):
"""打印 PASS 并计数"""
global _pass_count
_pass_count += 1
stdio.printf("PASS: %s\n", msg)
def fail(msg: str):
"""打印 FAIL 并计数"""
global _fail_count
_fail_count += 1
stdio.printf("FAIL: %s\n", msg)
def check(cond: t.CInt, ok_msg: str, fail_msg: str):
"""条件检查,自动选择 PASS/FAIL"""
if cond:
ok(ok_msg)
else:
fail(fail_msg)
def info(msg: str):
"""打印信息消息(不计入 PASS/FAIL"""
stdio.printf("%s\n", msg)
def end() -> t.CInt:
"""打印当前套件汇总,累加到总计,返回当前套件失败数"""
global _total_pass, _total_fail
_total_pass += _pass_count
_total_fail += _fail_count
stdio.printf("\n--- Summary ---\n")
stdio.printf("PASS: %d, FAIL: %d\n", _pass_count, _fail_count)
return _fail_count
def summary() -> t.CInt:
"""打印所有套件的总计汇总,返回总失败数"""
stdio.printf("\n=== Total Summary ===\n")
stdio.printf("Total PASS: %d, Total FAIL: %d\n", _total_pass, _total_fail)
return _total_fail