chore(test): 初始化回归测试仓(新增 .gitignore,TestsOverview.md 改为 README.md)

把 Test/ 纳入 https://git.gvsds.com/GVSDS/Viper_RegressionTesting 。

1) 新增 .gitignore —— 只保留测试源码,剔除全部构建产物:
   目录   **/output*/(output / output_opt / output_orig / output_verify / output_dbg)、
          **/temp*/(temp / temp_opt)、**/.tpv_build/
   二进制 *.exe *.obj *.o *.out *.a *.lib *.dll
   中间物 *.ll *.vpi *.pyi *.deps.txt *.deps.json *.doc.json *_sha1_map.txt
          _pyi_cache_v1.pkl _pyi_cache_v1.sig.json _shared_sym.json _phase1_manifest.json
   其它   build_all.txt(构建日志)、*.log、__pycache__/、*.bak、IDE 目录
   保留   App/*.vp、project.json / project_opt.json / project.vpj、README.md、两个 .py
   实测 `git add -A --dry-run`:196 个文件,无任何构建产物混入。

2) TestsOverview.md → README.md(作为仓库首页文档)。

3) SequentialRegressionTest.py:7 处 TestsOverview.md 引用同步改为 README.md
   (文档串、OVERVIEW 路径、read_test_order 文档与报错文案、argparse description、
   启动横幅);同时修正入口路径 PROJECTRANS —— 旧值 <root>/Projectrans.py 已不存在,
   改为 <root>/TransPyC/Projectrans.py(与 regression_test.py:45-48 记录一致),
   否则本脚本会以 "can't open file" 全量失败。
   regression_test.py 无需改动:它按目录扫描 project.json 找项目,不引用该文档。
This commit is contained in:
TermiNexus committed 2026-09-29 15:14:59 +08:00
commit 3c6fb1d246
196 files changed
+24775

No files matched your search

+160
View File
@@ -0,0 +1,160 @@
from stdint import *
import w32.win32console
import t, c
import testcheck
def add_inline(a: t.CInt, b: t.CInt) -> t.CDefine:
return a + b
def mul_inline(a: t.CInt, b: t.CInt) -> t.CDefine:
return a * b
class AppError(Exception):
pass
class DiskError(AppError):
pass
class NetworkError(AppError):
pass
class TimeoutError(NetworkError):
pass
def raise_disk():
raise DiskError("disk read failed")
def raise_network():
raise NetworkError("connection refused")
def raise_timeout():
raise TimeoutError("operation timed out")
def main() -> t.CInt | t.CExport:
w32.win32console.SetConsoleCP(65001)
w32.win32console.SetConsoleOutputCP(65001)
testcheck.begin("TestFBProject: 异常处理与LLVMIR测试")
testcheck.section("Test 1: Raise and catch exact custom exception")
try:
raise DiskError("disk error")
except DiskError as e:
print("caught DiskError:", e)
testcheck.ok("Test 1: caught DiskError")
except:
testcheck.fail("Test 1: caught by generic except")
testcheck.section("Test 2: Catch parent catches child")
try:
raise_disk()
except AppError as e:
print("caught AppError (child DiskError):", e)
testcheck.ok("Test 2: caught AppError (child DiskError)")
except:
testcheck.fail("Test 2: caught by generic except")
testcheck.section("Test 3: Catch parent catches nested child")
try:
raise_timeout()
except AppError as e:
print("caught AppError (grandchild TimeoutError):", e)
testcheck.ok("Test 3: caught AppError (grandchild TimeoutError)")
except:
testcheck.fail("Test 3: caught by generic except")
testcheck.section("Test 4: Catch mid-level parent")
try:
raise_timeout()
except NetworkError as e:
print("caught NetworkError (child TimeoutError):", e)
testcheck.ok("Test 4: caught NetworkError (child TimeoutError)")
except:
testcheck.fail("Test 4: caught by generic except")
testcheck.section("Test 5: Exact catch before parent")
try:
raise_network()
except NetworkError as e:
print("caught NetworkError:", e)
testcheck.ok("Test 5: caught NetworkError")
except AppError as e:
testcheck.fail("Test 5: caught AppError (should be NetworkError first)")
except:
testcheck.fail("Test 5: caught by generic except")
testcheck.section("Test 6: Parent catch when exact not present")
try:
raise_network()
except DiskError as e:
testcheck.fail("Test 6: caught DiskError (wrong)")
except AppError as e:
print("caught AppError (no NetworkError handler):", e)
testcheck.ok("Test 6: caught AppError (no NetworkError handler)")
except:
testcheck.fail("Test 6: caught by generic except")
testcheck.section("Test 7: Generic except fallback")
try:
raise_disk()
except RuntimeError as e:
testcheck.fail("Test 7: caught RuntimeError (wrong)")
except:
testcheck.ok("Test 7: caught by generic except")
testcheck.section("Test 8: Cross-function with inheritance")
try:
raise_timeout()
except NetworkError as e:
print("caught NetworkError (cross-func TimeoutError):", e)
testcheck.ok("Test 8: caught NetworkError (cross-func TimeoutError)")
except:
testcheck.fail("Test 8: caught by generic except")
testcheck.section("Test 9: Built-in exception still works")
try:
raise ValueError("test")
except ValueError as e:
print("caught ValueError:", e)
testcheck.ok("Test 9: caught ValueError")
except:
testcheck.fail("Test 9: caught by generic except")
testcheck.section("Test 10: Mixed built-in and custom")
try:
raise RuntimeError("test")
except DiskError as e:
testcheck.fail("Test 10: caught DiskError (wrong)")
except RuntimeError as e:
print("caught RuntimeError:", e)
testcheck.ok("Test 10: caught RuntimeError")
except:
testcheck.fail("Test 10: caught by generic except")
testcheck.section("Test LLVMIR: inline LLVM IR add")
x: t.CInt = 10
y: t.CInt = 20
r: t.CInt
c.LLVMIR(f"{c.LOut(r)} = add i32 {c.LInp(x)}, {c.LInp(y)}")
print("LLVMIR add result:", r)
testcheck.check(r == 30, "LLVMIR add (10+20=30)", "LLVMIR add result mismatch")
testcheck.section("Test CDefine function macro")
s: t.CInt = add_inline(3, 4)
print("add_inline(3, 4) =", s)
testcheck.check(s == 7, "add_inline(3, 4) = 7", "add_inline result mismatch")
m: t.CInt = mul_inline(5, 6)
print("mul_inline(5, 6) =", m)
testcheck.check(m == 30, "mul_inline(5, 6) = 30", "mul_inline result mismatch")
testcheck.section("Test LLVMIR with LOut")
out_val: t.CInt = 0
c.LLVMIR(f"{c.LOut(out_val)} = add i32 {c.LInp(x)}, {c.LInp(y)}")
print("LLVMIR LOut result:", out_val)
testcheck.check(out_val == 30, "LLVMIR LOut (10+20=30)", "LLVMIR LOut result mismatch")
return testcheck.end()
+36
View File
@@ -0,0 +1,36 @@
{
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
"name": "TestFBProject",
"version": "1.0.0",
"source_dir": "./App",
"build_dir": "./.tpv_build",
"compiler": {
"cmd": "llc",
"flags": [
"-filetype=obj"
]
},
"linker": {
"cmd": "clang++",
"flags": [
"-Wl,--allow-multiple-definition",
"-lucrt",
"-lkernel32",
"-luser32"
],
"output": "TestFBProject.exe"
},
"includes": [
"../../includes"
],
"target": {
"triple": "x86_64-pc-windows-gnu",
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
},
"options": {
"slice_level": 3,
"sha1_slice_level": 1,
"target": "llvm",
"strict_mode": true
}
}