feat(error): add typed errors + source-span diagnostics

This commit is contained in:
2026-08-28 19:58:29 -04:00
parent 911061eab7
commit d02b5aabcd
7 changed files with 529 additions and 0 deletions
+45
View File
@@ -130,6 +130,51 @@ else
fail "two positionals exited rc=$rc (want 2)"
fi
# --- 10. unit tests (tests/unit/*.c via munit) ----------------------------
# Harness contract (see .omo/notepads/stupidtools/learnings.md):
# - each tests/unit/<name>.c declares its extra link sources on its FIRST
# line as: /* LINK: ../../src/foo.c ../../src/bar.c */
# (paths relative to tests/unit/, space-separated)
# - the harness adds -I <repo>/thirdparty/munit -I <repo>/src and
# thirdparty/munit/munit.c automatically, compiles with
# -std=c23 -Wall -Wextra -Wpedantic, and runs each binary.
# - a missing LINK line, a compile failure, or a non-zero exit all FAIL.
UNIT_DIR="$TOP_DIR/tests/unit"
UNIT_BUILD="$TOP_DIR/tests/.unit-build"
if [ -d "$UNIT_DIR" ]; then
if ! mkdir -p "$UNIT_BUILD"; then
fail "cannot create unit build dir: $UNIT_BUILD"
fi
for t in "$UNIT_DIR"/*.c; do
[ -e "$t" ] || continue
name=$(basename "$t" .c)
# first line only: /* LINK: src1.c src2.c */
link=$(sed -n '1s|^/\* LINK: \(.*\) \*/$|\1|p' "$t")
if [ -z "$link" ]; then
fail "unit test $name: missing LINK comment on line 1"
continue
fi
# compile with cwd=tests/unit so LINK paths resolve relative to it;
# absolute paths for everything else.
if (cd "$UNIT_DIR" && cc -std=c23 -Wall -Wextra -Wpedantic \
-I "$TOP_DIR/thirdparty/munit" -I "$TOP_DIR/src" \
"$TOP_DIR/thirdparty/munit/munit.c" $link "$t" \
-o "$UNIT_BUILD/unit_$name") 2>"$UNIT_BUILD/unit_$name.build.log"
then
:
else
fail "unit test $name: compile failed (see $UNIT_BUILD/unit_$name.build.log)"
continue
fi
if "$UNIT_BUILD/unit_$name" >"$UNIT_BUILD/unit_$name.log" 2>&1; then
pass "unit test $name passed"
else
rc=$?
fail "unit test $name exited rc=$rc (see $UNIT_BUILD/unit_$name.log)"
fi
done
fi
# --- summary -------------------------------------------------------------
if [ "$TESTS_FAILED" -ne 0 ]; then
printf 'FAILED: %d/%d checks failed\n' "$TESTS_FAILED" "$TESTS_RUN" >&2