✓
Passing This code compiles and runs correctly.
Code
// Pins that the produced-program leak check is a Debug-mode audit.
//
// The same leaking program must:
// - Debug: exit 1 with `KORU LEAK CHECK FAILED` (EXPECT_TRAP + patterns)
// - ReleaseFast: exit 0, no leak message (post.sh rebuilds the emitted unit)
//
// The gate lives in the emitted source (`builtin.mode == .Debug`), not a
// koruc flag, so a `zig build-exe -O ReleaseFast` of output_emitted.zig
// is caught the same way `koruc build --release=fast` is. Blindness:
// nothing in the suite previously pinned the runtime leak check at all —
// enforcement was indirect (MUST_RUN exit codes) and no test requested
// release mode. Benchmark binaries ran ReleaseFast with the counter in
// the hot path. A json-parse before/after on a quiet machine is
// aspirational — this pin is the gate, not a throughput number.
//
// The alloc is through `koru_allocator()` on purpose: that is the spine
// the counter watches. A discarded raw allocation is the smallest program
// that fires the check.
~tor leak {}
~proc leak|zig {
_ = koru_allocator().alloc(u8, 16) catch unreachable;
}
~leak()
Actual
KORU LEAK CHECK FAILED: the produced program leaked (trace above)
Expected patterns
Each line is a regex that must match the program output.
KORU LEAK CHECK FAILEDFlows
flow ~leak click a branch to expand · @labels scroll to their anchor
leak
Test Configuration
MUST_RUN EXPECT_TRAP · exit 1
Post-validation Script:
#!/bin/bash
# Debug already ran (MUST_RUN + EXPECT_TRAP): leak check fired, exit 1.
# This half rebuilds the SAME emitted unit at ReleaseFast and demands the
# opposite: exit 0, no leak message. One source, two optimize modes.
set -u
if [ ! -f output_emitted.zig ]; then
echo "FAIL: no output_emitted.zig"
exit 1
fi
if ! grep -q 'mode == .Debug' output_emitted.zig; then
echo "FAIL: emitted source has no Debug mode gate"
exit 1
fi
if ! grep -q 'koru_leak_check' output_emitted.zig; then
echo "FAIL: emitted source has no koru_leak_check"
exit 1
fi
if ! zig build-exe -O ReleaseFast -lc --name output_release output_emitted.zig 2>release_build.err; then
echo "FAIL: ReleaseFast rebuild of output_emitted.zig failed"
sed -n '1,20p' release_build.err
exit 1
fi
set +e
./output_release >release_actual.txt 2>&1
rc=$?
set -e
if [ "$rc" -ne 0 ]; then
echo "FAIL: ReleaseFast leaked program exited $rc; leak check must fold away"
cat release_actual.txt
exit 1
fi
if grep -q "KORU LEAK CHECK FAILED" release_actual.txt; then
echo "FAIL: ReleaseFast still printed the leak check"
cat release_actual.txt
exit 1
fi
echo "PASS: Debug leak-check fired; ReleaseFast folded it"
rm -f output_release output_release.o release_actual.txt release_build.err
rm -rf .zig-cache zig-out
exit 0