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:
commit
3c6fb1d246
196 files changed
+24775
No files matched your search
@@ -0,0 +1,164 @@
|
||||
import t
|
||||
import stdio
|
||||
import testcheck
|
||||
|
||||
# ============================================================
|
||||
# Test 1: global 在嵌套函数中
|
||||
# ============================================================
|
||||
g_val: t.CInt = 100
|
||||
|
||||
def outer_modify_global():
|
||||
global g_val
|
||||
def inner_modify():
|
||||
global g_val
|
||||
g_val += 50
|
||||
inner_modify()
|
||||
|
||||
def test_global_in_nested():
|
||||
testcheck.section("Test 1: global in nested function")
|
||||
global g_val
|
||||
g_val = 100
|
||||
outer_modify_global()
|
||||
testcheck.check(g_val == 150, "global nested (g_val == 150)", "global nested (expect 150)")
|
||||
|
||||
# ============================================================
|
||||
# Test 2: nonlocal 在多层嵌套中
|
||||
# ============================================================
|
||||
def test_nonlocal_multi_level():
|
||||
testcheck.section("Test 2: nonlocal multi-level")
|
||||
x: t.CInt = 1
|
||||
def level1():
|
||||
nonlocal x
|
||||
x += 10
|
||||
def level2():
|
||||
nonlocal x
|
||||
x += 100
|
||||
def level3():
|
||||
nonlocal x
|
||||
x += 1000
|
||||
level3()
|
||||
level2()
|
||||
level1()
|
||||
testcheck.check(x == 1111, "nonlocal multi (x == 1111)", "nonlocal multi (expect 1111)")
|
||||
|
||||
# ============================================================
|
||||
# Test 3: global 和 nonlocal 混合
|
||||
# ============================================================
|
||||
g_mixed: t.CInt = 0
|
||||
|
||||
def test_global_nonlocal_mixed():
|
||||
testcheck.section("Test 3: global + nonlocal mixed")
|
||||
global g_mixed
|
||||
g_mixed = 0
|
||||
local_var: t.CInt = 0
|
||||
def modify_both():
|
||||
nonlocal local_var
|
||||
global g_mixed
|
||||
g_mixed += 10
|
||||
local_var += 20
|
||||
modify_both()
|
||||
modify_both()
|
||||
testcheck.check(g_mixed == 20 and local_var == 40, "mixed (global==20 local==40)", "mixed (expect global=20 local=40)")
|
||||
|
||||
# ============================================================
|
||||
# Test 4: lambda 捕获多个变量
|
||||
# ============================================================
|
||||
def test_lambda_multi_capture():
|
||||
testcheck.section("Test 4: lambda multi-capture")
|
||||
a: t.CInt = 10
|
||||
b: t.CInt = 20
|
||||
f = lambda: a + b
|
||||
r: t.CInt = f()
|
||||
testcheck.check(r == 30, "lambda multi-capture (a+b == 30)", "lambda multi-capture (expect 30)")
|
||||
|
||||
# ============================================================
|
||||
# Test 5: lambda 带参数 + 捕获
|
||||
# ============================================================
|
||||
def test_lambda_arg_capture():
|
||||
testcheck.section("Test 5: lambda arg + capture")
|
||||
base: t.CInt = 100
|
||||
add = lambda x: base + x
|
||||
r: t.CInt = add(42)
|
||||
testcheck.check(r == 142, "lambda arg+capture (100+42 == 142)", "lambda arg+capture (expect 142)")
|
||||
|
||||
# ============================================================
|
||||
# Test 6: 嵌套函数返回值
|
||||
# ============================================================
|
||||
def test_nested_return():
|
||||
testcheck.section("Test 6: nested function return")
|
||||
x: t.CInt = 5
|
||||
def double_x() -> t.CInt:
|
||||
nonlocal x
|
||||
x = x * 2
|
||||
return x
|
||||
r: t.CInt = double_x()
|
||||
testcheck.check(r == 10 and x == 10, "nested return (r==10 x==10)", "nested return (expect r=10 x=10)")
|
||||
|
||||
# ============================================================
|
||||
# Test 7: nonlocal 与循环变量
|
||||
# ============================================================
|
||||
def test_nonlocal_loop():
|
||||
testcheck.section("Test 7: nonlocal with loop")
|
||||
total: t.CInt = 0
|
||||
def accumulate(n: t.CInt):
|
||||
nonlocal total
|
||||
for i in range(n):
|
||||
total += i
|
||||
accumulate(5)
|
||||
accumulate(5)
|
||||
# 0+1+2+3+4 = 10, twice = 20
|
||||
testcheck.check(total == 20, "nonlocal loop (total == 20)", "nonlocal loop (expect 20)")
|
||||
|
||||
# ============================================================
|
||||
# Test 8: global 数组操作
|
||||
# ============================================================
|
||||
g_arr: t.CArray[t.CInt, 4] = [0]
|
||||
|
||||
def test_global_array():
|
||||
testcheck.section("Test 8: global array")
|
||||
global g_arr
|
||||
g_arr[0] = 10
|
||||
g_arr[1] = 20
|
||||
g_arr[2] = 30
|
||||
g_arr[3] = 40
|
||||
total: t.CInt = g_arr[0] + g_arr[1] + g_arr[2] + g_arr[3]
|
||||
testcheck.check(total == 100, "global array (total == 100)", "global array (expect 100)")
|
||||
|
||||
# ============================================================
|
||||
# Test 9: 嵌套函数条件调用
|
||||
# ============================================================
|
||||
def test_nested_conditional():
|
||||
testcheck.section("Test 9: nested conditional call")
|
||||
result: t.CInt = 0
|
||||
def set_result(val: t.CInt):
|
||||
nonlocal result
|
||||
result = val
|
||||
if 1:
|
||||
set_result(42)
|
||||
else:
|
||||
set_result(99)
|
||||
testcheck.check(result == 42, "nested conditional (result == 42)", "nested conditional (expect 42)")
|
||||
|
||||
# ============================================================
|
||||
# Test 10: lambda 链式调用
|
||||
# ============================================================
|
||||
def test_lambda_chain():
|
||||
testcheck.section("Test 10: lambda chain")
|
||||
f1 = lambda: 10
|
||||
f2 = lambda: 20
|
||||
r: t.CInt = f1() + f2()
|
||||
testcheck.check(r == 30, "lambda chain (10+20 == 30)", "lambda chain (expect 30)")
|
||||
|
||||
def main() -> t.CInt:
|
||||
testcheck.begin("ClosureAdvancedTest: 高级闭包测试")
|
||||
test_global_in_nested()
|
||||
test_nonlocal_multi_level()
|
||||
test_global_nonlocal_mixed()
|
||||
test_lambda_multi_capture()
|
||||
test_lambda_arg_capture()
|
||||
test_nested_return()
|
||||
test_nonlocal_loop()
|
||||
test_global_array()
|
||||
test_nested_conditional()
|
||||
test_lambda_chain()
|
||||
return testcheck.end()
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "ClosureTest",
|
||||
"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": "ClosureTest.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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user