把 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 找项目,不引用该文档。
86 lines
2.3 KiB
Plaintext
86 lines
2.3 KiB
Plaintext
import t
|
|
import stdio
|
|
import string
|
|
import testcheck
|
|
|
|
# 定义结构体
|
|
class Point():
|
|
x: t.CInt
|
|
y: t.CInt
|
|
|
|
class Rect():
|
|
origin: Point
|
|
size: Point
|
|
|
|
class Node():
|
|
value: t.CInt
|
|
next: t.CPtr # Node* 类型
|
|
|
|
def test_struct_basic():
|
|
testcheck.section("Test 1: struct basic")
|
|
p: Point = Point()
|
|
p.x = 10
|
|
p.y = 20
|
|
testcheck.check(p.x == 10 and p.y == 20, "struct basic (x=10 y=20)", "struct basic (x y expect 10 20)")
|
|
|
|
def test_struct_nested():
|
|
testcheck.section("Test 2: struct nested")
|
|
r: Rect = Rect()
|
|
r.origin.x = 1
|
|
r.origin.y = 2
|
|
r.size.x = 100
|
|
r.size.y = 200
|
|
testcheck.check(r.origin.x == 1 and r.origin.y == 2 and r.size.x == 100 and r.size.y == 200, "struct nested (origin=1,2 size=100,200)", "struct nested (mismatch)")
|
|
|
|
def test_struct_pointer():
|
|
testcheck.section("Test 3: struct pointer")
|
|
p: Point = Point()
|
|
p.x = 42
|
|
p.y = 84
|
|
# 取结构体指针
|
|
pp: Point | t.CPtr = t.CPtr(t.CUInt64T(p))
|
|
# 通过指针修改
|
|
pp.x = 100
|
|
pp.y = 200
|
|
# 检查原始结构体是否被修改
|
|
testcheck.check(p.x == 100 and p.y == 200, "struct pointer (x=100 y=200)", "struct pointer (x y expect 100 200)")
|
|
|
|
def test_struct_param():
|
|
testcheck.section("Test 4: struct as parameter")
|
|
p: Point = Point()
|
|
p.x = 5
|
|
p.y = 15
|
|
sum_val: t.CInt = point_sum(p)
|
|
testcheck.check(sum_val == 20, "struct param (sum=20)", "struct param (sum expect 20)")
|
|
|
|
def point_sum(p: Point) -> t.CInt:
|
|
return p.x + p.y
|
|
|
|
def test_struct_array():
|
|
testcheck.section("Test 5: struct array")
|
|
# 分配结构体数组
|
|
buf: t.CUInt8T | t.CPtr = w32.win32memory.VirtualAlloc(None, 256, 12288, 4)
|
|
if t.CUInt64T(buf) == 0:
|
|
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
|
return
|
|
string.memset(buf, 0, 256)
|
|
# 将缓冲区转为 Point 数组
|
|
pts: Point | t.CPtr = (Point | t.CPtr)(buf)
|
|
pts[0].x = 1
|
|
pts[0].y = 2
|
|
pts[1].x = 3
|
|
pts[1].y = 4
|
|
total: t.CInt = pts[0].x + pts[0].y + pts[1].x + pts[1].y
|
|
testcheck.check(total == 10, "struct array (total=10)", "struct array (total expect 10)")
|
|
|
|
import w32.win32memory
|
|
|
|
def main() -> t.CInt:
|
|
testcheck.begin("StructTest: 结构体操作基准测试")
|
|
test_struct_basic()
|
|
test_struct_nested()
|
|
test_struct_pointer()
|
|
test_struct_param()
|
|
test_struct_array()
|
|
return testcheck.end()
|