P0.4: wire the logic verification gate (sx assert helper + snapshot runner)

Add a real logic-test gate so future pure-sx game logic fails the build on a
bad assertion:

- tests/test.sx: `expect(cond, msg)` assert helper — prints a greppable
  `FAIL <file>:<line>: <msg>` and exits non-zero via process.exit on failure.
- tools/run_tests.sh: snapshot runner mirroring sx/tests/run_examples.sh; runs
  each tests/<name>.sx and diffs stdout + exit code against tests/expected/.
  Exits 0 iff all tests pass.
- tests/arith.sx (+ expected snapshots): seed passing sanity test.
- README.md: document both halves of the gate — logic runner and the
  reproducible ios-sim build/launch sequence (with device discovery).
This commit is contained in:
swipelab
2026-06-04 18:57:21 +03:00
parent 02924377e7
commit 6d9aee67ba
6 changed files with 192 additions and 0 deletions

13
tests/arith.sx Normal file
View File

@@ -0,0 +1,13 @@
// Trivial logic-gate sanity check: exercises the `expect` helper on passing
// assertions and prints a stable summary line for the snapshot runner to diff.
// Real board-state tests arrive in Phase 1.
#import "modules/std.sx";
t :: #import "test.sx";
main :: () -> s32 {
t.expect(2 + 2 == 4, "two plus two is four");
t.expect(7 % 3 == 1, "seven mod three is one");
t.expect(10 - 4 == 6, "ten minus four is six");
print("ok: arithmetic\n");
return 0;
}

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@
ok: arithmetic

15
tests/test.sx Normal file
View File

@@ -0,0 +1,15 @@
// m3te logic-test assert helper.
//
// `expect(cond, msg)` is a no-op when `cond` holds. On a false condition it
// prints a single greppable `FAIL <file>:<line>: <msg>` line to stdout and
// terminates the process NON-ZERO (exit 1) via process.exit, so a broken
// assertion fails `tools/run_tests.sh` and the build gate.
#import "modules/std.sx";
proc :: #import "modules/process.sx";
expect :: (cond: bool, msg: string, loc: Source_Location = #caller_location) {
if !cond {
print("FAIL {}:{}: {}\n", loc.file, loc.line, msg);
proc.exit(1);
}
}