refactor(test): 收尾 6 个测试用例的新规范语法迁移

CoroTest/DefaultArgTest/FormatStringTest/FuncTest/MLIRLiteTest/ThreadingTest 的 App/main.vp 从旧写法(t.CInt/t.CPtr 注解、多行单语句体)迁到新规范(int 短别名、T* 后缀、单语句体并一行),为既有迁移的遗留未提交部分。验证:TPV 自举产物顺序回归 77/77 全通过。
This commit is contained in:
TermiNexus committed 2026-10-05 09:24:42 +08:00
1 parent 3f532e665d
commit 44ce29200e
6 files changed
+333 -406

No files matched your search

+1 -1
View File
@@ -31,7 +31,7 @@ async def task() -> int:
def main() -> t.CInt: def main() -> t.CInt:
n: t.CInt = 0 n: t.CInt = 0
for i in range(3): for i in range(3):
tt: coro.Coroutine = c.Addr(task()) tt: coro.Coroutine = coro.Coroutine(*&task())
r: t.CInt = coro.coro_run(tt) r: t.CInt = coro.coro_run(tt)
e: t.CInt = coro.coro_exception(tt) e: t.CInt = coro.coro_exception(tt)
m: t.CPtr = coro.coro_exception_msg(tt) m: t.CPtr = coro.coro_exception_msg(tt)
+2 -2
View File
@@ -2,7 +2,7 @@ import t
import stdio import stdio
import testcheck import testcheck
import remote import remote
import vrandom import random
# 同模块:单个尾随默认值 # 同模块:单个尾随默认值
@@ -64,7 +64,7 @@ def main() -> t.CInt:
# ⑥ include 模块(顶层 .vp)默认值:vrandom.randrange(start, stop, step = 1) # ⑥ include 模块(顶层 .vp)默认值:vrandom.randrange(start, stop, step = 1)
# stop-start==1 ⇒ width==1 ⇒ 结果恒为 start;step 未填充时会退化为 0/垃圾 # stop-start==1 ⇒ width==1 ⇒ 结果恒为 start;step 未填充时会退化为 0/垃圾
testcheck.section("include-module defaults") testcheck.section("include-module defaults")
r15: t.CInt = vrandom.randrange(5, 6) r15: t.CInt = random.randrange(5, 6)
testcheck.check(r15 == 5, "vrandom.randrange(5,6) = 5 (step default)", "vrandom.randrange(5,6) != 5") testcheck.check(r15 == 5, "vrandom.randrange(5,6) = 5 (step default)", "vrandom.randrange(5,6) != 5")
return testcheck.end() return testcheck.end()
+1 -2
View File
@@ -8,8 +8,7 @@ import testcheck
# ============================================================ # ============================================================
# FormatStringTest - 格式化字符串回归测试 # FormatStringTest - 格式化字符串回归测试
# ============================================================ # ============================================================
@t.CExport export def main() -> int:
def main() -> int:
testcheck.begin("FormatStringTest: Format String Regression") testcheck.begin("FormatStringTest: Format String Regression")
b: str = "hello world" b: str = "hello world"
+26 -49
View File
@@ -1,73 +1,53 @@
import t
import stdio
import testcheck import testcheck
# import w32.win32memory
import stdlib
# 测试基本函数调用
def add(a: t.CInt, b: t.CInt) -> t.CInt:
return a + b
def sub(a: t.CInt, b: t.CInt) -> t.CInt: def add(a: int, b: int) -> int: return a + b
return a - b def sub(a: int, b: int) -> int: return a - b
def multi_args(a: int, b: int, c: int, d: int) -> int: return a + b + c + d
# 测试多参数 def factorial(n: int) -> int:
def multi_args(a: t.CInt, b: t.CInt, c: t.CInt, d: t.CInt) -> t.CInt: if n <= 1: return 1
return a + b + c + d
# 测试递归
def factorial(n: t.CInt) -> t.CInt:
if n <= 1:
return 1
return n * factorial(n - 1) return n * factorial(n - 1)
# 测试尾递归式斐波那契 def fib(n: int) -> int:
def fib(n: t.CInt) -> t.CInt: if n <= 0: return 0
if n <= 0: if n == 1: return 1
return 0
if n == 1:
return 1
return fib(n - 1) + fib(n - 2) return fib(n - 1) + fib(n - 2)
# 测试指针参数 def add_via_ptr(p: int*, val: int):
def add_via_ptr(p: t.CInt | t.CPtr, val: t.CInt):
p[0] = p[0] + val p[0] = p[0] + val
# 测试 u64 返回值 def make_u64() -> uint64: return 0xDEADBEEF
def make_u64() -> t.CUInt64T:
return t.CUInt64T(0xDEADBEEF)
# 测试 bool 返回值 def is_even(n: int) -> bool: return n % 2 == 0
def is_even(n: t.CInt) -> t.CBool:
return n % 2 == 0
def test_basic_call(): def test_basic_call():
testcheck.section("Test 1: basic function call") testcheck.section("Test 1: basic function call")
r: t.CInt = add(10, 20) r: int = add(10, 20)
testcheck.check(r == 30, "add(10,20)=30", "add(10,20) expect 30") testcheck.check(r == 30, "add(10,20)=30", "add(10,20) expect 30")
def test_multi_args(): def test_multi_args():
testcheck.section("Test 2: multi args") testcheck.section("Test 2: multi args")
r: t.CInt = multi_args(1, 2, 3, 4) r: int = multi_args(1, 2, 3, 4)
testcheck.check(r == 10, "multi_args(1,2,3,4)=10", "multi_args(1,2,3,4) expect 10") testcheck.check(r == 10, "multi_args(1,2,3,4)=10", "multi_args(1,2,3,4) expect 10")
def test_recursion(): def test_recursion():
testcheck.section("Test 3: recursion (factorial)") testcheck.section("Test 3: recursion (factorial)")
r: t.CInt = factorial(10) r: int = factorial(10)
# 10! = 3628800
testcheck.check(r == 3628800, "factorial(10)=3628800", "factorial(10) expect 3628800") testcheck.check(r == 3628800, "factorial(10)=3628800", "factorial(10) expect 3628800")
def test_fibonacci(): def test_fibonacci():
testcheck.section("Test 4: fibonacci") testcheck.section("Test 4: fibonacci")
r: t.CInt = fib(10) r: int = fib(10)
# fib(10) = 55
testcheck.check(r == 55, "fib(10)=55", "fib(10) expect 55") testcheck.check(r == 55, "fib(10)=55", "fib(10) expect 55")
def test_ptr_param(): def test_ptr_param():
testcheck.section("Test 5: pointer parameter") testcheck.section("Test 5: pointer parameter")
x: t.CInt = 10 # buf: int* = w32.win32memory.VirtualAlloc(None, 64, 12288, 4)
# 需要取 x 的地址 buf: int* = stdlib.malloc(int.__sizeof__())
import w32.win32memory if buf is None:
buf: t.CInt | t.CPtr = w32.win32memory.VirtualAlloc(None, 64, 12288, 4)
if t.CUInt64T(buf) == 0:
testcheck.info("SKIP: VirtualAlloc returned NULL") testcheck.info("SKIP: VirtualAlloc returned NULL")
return return
buf[0] = 10 buf[0] = 10
@@ -76,24 +56,21 @@ def test_ptr_param():
def test_u64_return(): def test_u64_return():
testcheck.section("Test 6: u64 return") testcheck.section("Test 6: u64 return")
r: t.CUInt64T = make_u64() r: uint64 = make_u64()
testcheck.check(r == t.CUInt64T(0xDEADBEEF), "u64 return (0xdeadbeef)", "u64 return expect 0xdeadbeef") testcheck.check(r == 0xDEADBEEF, "u64 return (0xdeadbeef)", "u64 return expect 0xdeadbeef")
def test_bool_return(): def test_bool_return():
testcheck.section("Test 7: bool return") testcheck.section("Test 7: bool return")
r1: t.CBool = is_even(4) r1: bool = is_even(4)
r2: t.CBool = is_even(7) r2: bool = is_even(7)
testcheck.check(r1 and not r2, "bool return (is_even(4)=1, is_even(7)=0)", "bool return expect is_even(4)=1, is_even(7)=0") testcheck.check(r1 and not r2, "bool return (is_even(4)=1, is_even(7)=0)", "bool return expect is_even(4)=1, is_even(7)=0")
def test_nested_call(): def test_nested_call():
testcheck.section("Test 8: nested function call") testcheck.section("Test 8: nested function call")
r: t.CInt = add(factorial(3), sub(10, 3)) r: int = add(factorial(3), sub(10, 3))
# 3! = 6, 10-3 = 7, 6+7 = 13
testcheck.check(r == 13, "nested call (add(factorial(3), sub(10,3))=13)", "nested call expect 13") testcheck.check(r == 13, "nested call (add(factorial(3), sub(10,3))=13)", "nested call expect 13")
import w32.win32memory export def main() -> int:
export def main() -> t.CInt:
testcheck.begin("FuncTest: 函数调用基准测试") testcheck.begin("FuncTest: 函数调用基准测试")
test_basic_call() test_basic_call()
test_multi_args() test_multi_args()
+303 -351
View File
File diff suppressed because it is too large. Load diff
-1
View File
@@ -56,7 +56,6 @@ def _increment_worker(arg: t.CPtr) -> t.CPtr:
def _lock_worker(arg: t.CPtr) -> t.CPtr: def _lock_worker(arg: t.CPtr) -> t.CPtr:
lk: vthreading.Lock | t.CPtr = (vthreading.Lock | t.CPtr)(arg) lk: vthreading.Lock | t.CPtr = (vthreading.Lock | t.CPtr)(arg)
global _shared_count global _shared_count
i: t.CInt
for i in range(LOCK_ITER): for i in range(LOCK_ITER):
lk.acquire() lk.acquire()
_shared_count += 1 _shared_count += 1