wcc: @test marker attributes + runner

Hare-style `@test fn check_foo() void = { ... }` now parses. The
attribute is recognised by making the args list optional in
parseattrs: `@symbol("rt_syscall")` still requires the parens;
`@test` doesn't. Same change mirrored in lib/ww/parse/decl.ww.

The runner (test/wcc/910_at_test.c) scans a fixture for
`@test fn IDENT(`, synthesises a wrapper `main()` that calls each
test fn, builds it via `ww run`, and asserts exit 0. A failing
@test would either explicitly call abort or trip a runtime trap
(div-by-zero, etc.) and the whole driver exits non-zero.

The 910_at_test target sits alongside the existing C-side test
binaries; `make test` now runs 20 tests instead of 19.

Fixture: test/wcc/data/attest_pass.ww exercises two passing tests
(simple arithmetic and a match-with-yield).
This commit is contained in:
2026-05-12 03:14:20 +09:00
parent 404705b6fd
commit 906e17b128
7 changed files with 228 additions and 18 deletions

View File

@@ -0,0 +1,21 @@
// @test fixture: every test passes (exits without aborting).
@test fn check_add() void = {
let a: i32 = 2;
let b: i32 = 3;
let c: i32 = a + b;
if (c != 5) {
let _: i32 = 1 / 0; // abort via div-by-zero would also work
};
};
@test fn check_match() void = {
let r: (i32 | str) = 7;
let v: i32 = match (r) {
case let n: i32 => yield n;
case let s: str => yield 0;
};
if (v != 7) {
let _: i32 = 1 / 0;
};
};