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

@@ -0,0 +1,7 @@
import t, c
def g(x: int) -> int:
return x
def main() -> int:
return g(1.5)
+7
View File
@@ -0,0 +1,7 @@
import t, c
def f(a: int, b: int) -> int:
return a + b
def main() -> int:
return f(1)
+7
View File
@@ -0,0 +1,7 @@
import t, c
def f(a: int, b: int) -> int:
return a + b
def main() -> int:
return f(1, 2, 3)
@@ -0,0 +1,7 @@
import t, c
def f(a: int, b: int) -> int:
return a + b
def main() -> int:
return f("x", 2)
@@ -0,0 +1,5 @@
import t, c
import lib.core.Handles.HandlesStruct as HandlesStruct
def main() -> int:
return 0
@@ -0,0 +1,6 @@
import t, c
# f8bca62 移动前的旧路径(文件在 lib/Stub/StubMerger/ 下)
import lib.Stub.StubMergerStore as StubMergerStore
def main() -> int:
return 0
@@ -0,0 +1,5 @@
import t, c
import lib.NopeModule as NopeModule
def main() -> int:
return 0
+4
View File
@@ -0,0 +1,4 @@
import t, c
def h(x: int) -> int:
x = x + 1
+4
View File
@@ -0,0 +1,4 @@
import t, c
def main() -> int:
return foo(1)
+7
View File
@@ -0,0 +1,7 @@
import t, c
from stdint import *
import stdio
def main() -> int:
stdio.printf("NegativeTest baseline OK\n")
return 0
+37
View File
@@ -0,0 +1,37 @@
{
"name": "NegativeTest",
"version": "1.0.0",
"source_dir": "./App",
"build_dir": "./.tpv_build",
"compiler": {
"cmd": "llc",
"flags": [
"-filetype=obj",
"-relocation-model=pic"
]
},
"linker": {
"cmd": "clang++",
"flags": [
"-lmsvcrt",
"-lucrt",
"-lpthread",
"-lmingwex",
"-lkernel32",
"-Wl,--allow-multiple-definition"
],
"output": "NegativeTest.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,
"target": "llvm",
"strict_mode": true
}
}
+71
View File
@@ -0,0 +1,71 @@
# NegativeTest 反向测试运行器:对每个错误用例执行 TPC 单文件编译,
# 断言"编译失败且输出诊断信息"。编译成功 = 编译器漏检(FAIL)。
import os
import subprocess
import sys
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
CASES_DIR = os.path.join(ROOT, 'Test', 'NegativeTest', 'App', 'cases')
OUT_DIR = os.path.join(ROOT, 'Test', 'NegativeTest', '.out')
os.makedirs(OUT_DIR, exist_ok=True)
# 用例 -> 期望错误关键字(用于确认报错方向正确)
EXPECT = {
'import_wrong_path.vp': ['NopeModule', '模块', 'import'],
'import_stale_path.vp': ['StubMergerStore', '模块', 'import'],
'import_missing_module.vp': ['HandlesStruct', '模块', 'import'],
'call_too_few.vp': ['参数', '少', '2', 'f'],
'call_too_many.vp': ['参数', '多', '3', 'f'],
'call_wrong_type.vp': ['类型', 'int', 'f'],
'call_float_to_int.vp': ['类型', 'int', 'g'],
'undefined_func.vp': ['foo', '未定义', 'NameError'],
'missing_return.vp': ['返回', 'return', '末尾'],
}
def main() -> int:
cases = sorted(f for f in os.listdir(CASES_DIR) if f.endswith('.vp'))
passed, failed, skipped = [], [], []
for case in cases:
src = os.path.join(CASES_DIR, case)
out_ll = os.path.join(OUT_DIR, case[:-3] + '.ll')
try:
r = subprocess.run(
[sys.executable, 'TransPyC.py', '-f', src, '-o', out_ll],
capture_output=True, text=True, cwd=ROOT, timeout=120,
)
except subprocess.TimeoutExpired:
failed.append((case, 'TIMEOUT', ''))
continue
err_text = (r.stderr or '') + (r.stdout or '')
if r.returncode == 0:
failed.append((case, 'COMPILED_OK(漏检)', err_text.strip()[-500:]))
continue
# 编译失败:检查是否报了我们预期的错误方向
lower = err_text.lower()
keywords = EXPECT.get(case, [])
hit = [k for k in keywords if k.lower() in lower]
if hit:
passed.append((case, 'PASS', hit, err_text.strip()[-300:]))
else:
skipped.append((case, 'ERR_BUT_UNEXPECTED', err_text.strip()[-300:]))
print('\n==== NegativeTest 结果 ====')
print(f'PASS(预期失败且方向正确): {len(passed)}')
for c, tag, hit, tail in passed:
print(f' [PASS] {c} 命中关键字 {hit}')
print(f'FAIL(编译器漏检): {len(failed)}')
for c, tag, tail in failed:
print(f' [FAIL] {c} {tag}')
if tail:
print(f' {tail}')
print(f'SKIP(报错但非预期方向): {len(skipped)}')
for c, tag, tail in skipped:
print(f' [SKIP] {c}')
if tail:
print(f' {tail}')
return 1 if failed else 0
if __name__ == '__main__':
sys.exit(main())