Files
TransPyC/includes/testcheck.py

55 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# testcheck - 回归测试格式化输出库
# 提供 PASS/FAIL 计数、分节标题、汇总报告
import t, c
import stdio
_pass_count: t.CInt = 0
_fail_count: t.CInt = 0
def begin(name: str):
"""开始测试套件,打印头部并重置计数器"""
global _pass_count, _fail_count
_pass_count = 0
_fail_count = 0
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:
"""打印汇总,返回失败数"""
stdio.printf("\n--- Summary ---\n")
stdio.printf("PASS: %d, FAIL: %d\n", _pass_count, _fail_count)
return _fail_count