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

+43
View File
@@ -0,0 +1,43 @@
import t
from t import CInt
# ============================================================
# 跨模块 isinstance 测试库
#
# 供 main.vp import 使用:验证 isinstance 对"定义在其他模块
# 的类"也能正确比较(对象 vtable 指针跨 obj 链接解析)。
# ============================================================
@t.CVTable
class Shape:
def area(self) -> CInt:
return 0
@t.CVTable
class Circle(Shape):
r: CInt
def __init__(self, r: CInt):
self.r = r
def area(self) -> CInt:
return self.r
@t.CVTable
class Square(Shape):
s: CInt
def __init__(self, s: CInt):
self.s = s
def area(self) -> CInt:
return self.s
@t.NoVTable
class PlainShape:
tag: CInt
+153
View File
@@ -0,0 +1,153 @@
from stdint import *
import t, c
import testcheck
import geom_lib
from t import CInt, CPtr, CExport
# ============================================================
# isinstance 内建函数测试(运行时 vtable 继承链比较)
#
# 场景覆盖:
# 1. CVTable 自身/子类→基类
# 2. 运行时多态(基类指针指向子类对象)
# 3. 元组 (A, B)
# 4. 多继承(AB 同时是 A 和 B 的实例)
# 5. NoVTable 类(编译时静态判断)
# ============================================================
# ========== CVTable 继承 ==========
@t.CVTable
class Animal:
Name: str
def __init__(self, name: str):
self.Name = name
def speak(self) -> str:
return "..."
@t.CVTable
class Dog(Animal):
def __init__(self, name: str):
self.Name = name
def speak(self) -> str:
return "Woof"
@t.CVTable
class Cat(Animal):
def speak(self) -> str:
return "Meow"
# ========== 多继承 ==========
@t.CVTable
class A:
a: CInt
def get_a(self) -> CInt:
return self.a
@t.CVTable
class B:
b: CInt
def get_b(self) -> CInt:
return self.b
@t.CVTable
class AB(A, B):
def __init__(self, a: CInt, b: CInt):
self.a = a
self.b = b
# ========== NoVTable(编译时判断) ==========
@t.NoVTable
class Plain:
v: CInt
def main() -> CInt | CExport:
testcheck.begin("IsinstanceTest: isinstance 内建函数测试")
# --- 1. 自身类型 + 子类→基类 ---
d: Dog | CPtr = Dog("dog")
testcheck.check(isinstance(d, Dog) == 1, "isinstance(d, Dog) 自身 OK",
"isinstance(d, Dog) FAILED")
testcheck.check(isinstance(d, Animal) == 1, "isinstance(d, Animal) 子类→基类 OK",
"isinstance(d, Animal) FAILED")
testcheck.check(isinstance(d, Cat) == 0, "isinstance(d, Cat) 不匹配 OK",
"isinstance(d, Cat) FAILED")
# --- 2. 运行时多态:基类指针指向子类对象 ---
a: Animal | CPtr = (Animal | CPtr)(d)
testcheck.check(isinstance(a, Dog) == 1,
"isinstance(Animal*, Dog 对象) 运行时多态 OK",
"isinstance(Animal*, Dog) FAILED")
testcheck.check(isinstance(a, Animal) == 1,
"isinstance(Animal*, Animal) 基类自身 OK",
"isinstance(Animal*, Animal) FAILED")
testcheck.check(isinstance(a, Cat) == 0,
"isinstance(Animal*, Cat) 运行时 False OK",
"isinstance(Animal*, Cat) FAILED")
# --- 3. 元组 ---
testcheck.check(isinstance(d, (Cat, Dog)) == 1, "isinstance 元组命中 OK",
"isinstance 元组 FAILED")
testcheck.check(isinstance(d, (Cat, A)) == 0, "isinstance 元组未命中 OK",
"isinstance 元组未命中 FAILED")
# --- 4. 多继承 ---
ab: AB | CPtr = AB(1, 2)
testcheck.check(isinstance(ab, A) == 1, "isinstance(AB, A) 多继承 OK",
"isinstance(AB, A) FAILED")
testcheck.check(isinstance(ab, B) == 1, "isinstance(AB, B) 多继承 OK",
"isinstance(AB, B) FAILED")
testcheck.check(isinstance(ab, Animal) == 0, "isinstance(AB, Animal) False OK",
"isinstance(AB, Animal) FAILED")
testcheck.check(ab.get_a() == 1 and ab.get_b() == 2, "AB 字段/方法正常 OK",
"AB 字段/方法 FAILED")
# --- 5. NoVTable(编译时静态判断) ---
p: Plain | CPtr = Plain()
p.v = 42
testcheck.check(isinstance(p, Plain) == 1, "isinstance NoVTable 编译时 OK",
"isinstance NoVTable FAILED")
testcheck.check(p.v == 42, "NoVTable 字段正常 OK", "NoVTable 字段 FAILED")
# --- 6. 跨模块 isinstance(vtable 跨 obj 链接解析) ---
cc: geom_lib.Circle | CPtr = geom_lib.Circle(5)
testcheck.check(isinstance(cc, geom_lib.Circle) == 1,
"跨模块 isinstance 自身 OK", "跨模块 isinstance 自身 FAILED")
testcheck.check(isinstance(cc, geom_lib.Shape) == 1,
"跨模块 isinstance 子类→基类 OK", "跨模块 isinstance 子类→基类 FAILED")
testcheck.check(isinstance(cc, geom_lib.Square) == 0,
"跨模块 isinstance 不匹配 OK", "跨模块 isinstance 不匹配 FAILED")
sq: geom_lib.Square | CPtr = geom_lib.Square(3)
testcheck.check(isinstance(sq, geom_lib.Shape) == 1,
"跨模块 Square→Shape OK", "跨模块 Square→Shape FAILED")
testcheck.check(isinstance(sq, geom_lib.Circle) == 0,
"跨模块 Square vs Circle OK", "跨模块 Square vs Circle FAILED")
shp: geom_lib.Shape | CPtr = (geom_lib.Shape | CPtr)(cc)
testcheck.check(isinstance(shp, geom_lib.Circle) == 1,
"跨模块运行时多态 OK", "跨模块运行时多态 FAILED")
testcheck.check(shp.area() == 5, "跨模块虚方法分派 OK", "跨模块虚方法分派 FAILED")
testcheck.check(cc.area() == 5, "跨模块 Circle.area OK", "跨模块 Circle.area FAILED")
# --- 7. NoVTable 跨模块静态判断 ---
ps: geom_lib.PlainShape | CPtr = geom_lib.PlainShape()
testcheck.check(isinstance(ps, geom_lib.PlainShape) == 1,
"跨模块 NoVTable 静态 OK", "跨模块 NoVTable 静态 FAILED")
testcheck.ok("isinstance 全部测试完成")
return testcheck.end()
+40
View File
@@ -0,0 +1,40 @@
{
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
"name": "IsinstanceTest",
"version": "1.0.0",
"source_dir": "./App",
"build_dir": "./.tpv_build",
"compiler": {
"cmd": "llc",
"flags": [
"-filetype=obj",
"-relocation-model=pic"
]
},
"linker": {
"cmd": "clang++",
"flags": [
"-Wl,--allow-multiple-definition",
"-lmsvcrt",
"-lucrt",
"-lpthread",
"-lmingwex",
"-lkernel32",
"-luser32"
],
"output": "IsinstanceTest.exe"
},
"includes": [
"../../includes"
],
"target": {
"triple": "x86_64-pc-windows-gnu",
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-f80:128-n8:16:32:64-S128"
},
"options": {
"slice_level": 3,
"sha1_slice_level": 1,
"target": "llvm",
"strict_mode": true
}
}