Subplan 02 Slice 2 foundation. vendor/sqlite/ holds the amalgamation (provenance + upgrade notes in its README); make build compiles it into build/vendor/libsqlite3.a (statically linked into dist via -L) and build/vendor/jit/libsqlite3.dylib (dlopen'd by sx run via tests/run.sh's -L flag) — separate directories because the macOS linker prefers a dylib over an archive in one search dir. The sx JIT resolves #foreign symbols via dlsym(RTLD_DEFAULT), where the already-loaded OS libsqlite3 wins by load order — so the vendored build renames its API to dist_sqlite3_* (vendor/sqlite/rename.h, -include'd), making resolution unambiguous in both modes: those symbols exist only in the vendored products. src/db/sqlite.sx binds the renamed surface behind Sqlite/SqliteStmt (open/exec/prepare/bind/step/column/finalize, errmsg, last_insert_rowid, changes, libversion); opaque handles cross the FFI as usize, strings read from sqlite are copied before its buffers die. make test 20/20 (new: sqlite_smoke.sx — pins the loaded version to the vendored 3.53.2, round trip, reopen persistence, BEGIN/ROLLBACK, errmsg; also verified as an AOT binary with no libsqlite3 in otool -L).
48 lines
1.6 KiB
Bash
Executable File
48 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# Test runner — discovers every tests/**/*.sx, runs each via `$SX run`, and
|
|
# reports per-test ok/FAIL. Exits 0 only when every test passes.
|
|
#
|
|
# A test passes iff `$SX run <file>` exits 0 (compile failures count as a
|
|
# failure too). Each test program asserts its own invariants — e.g. via
|
|
# process.assert — and exits non-zero on failure.
|
|
#
|
|
# Locate the compiler via SX (overridable); defaults to the sibling sx repo.
|
|
#
|
|
# `-L build/vendor/jit` lets the JIT dlopen the VENDORED libsqlite3.dylib
|
|
# (built by `make build`) instead of falling back to the OS copy — the
|
|
# version assert in tests/sqlite_smoke.sx depends on it.
|
|
set -u
|
|
|
|
SX="${SX:-/Users/agra/projects/sx/zig-out/bin/sx}"
|
|
TESTS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
REPO_DIR=$(CDPATH= cd -- "$TESTS_DIR/.." && pwd)
|
|
SX_RUN_FLAGS="-L $REPO_DIR/build/vendor/jit"
|
|
|
|
pass=0
|
|
fail=0
|
|
|
|
# Test filenames follow the no-spaces convention, so word-splitting the
|
|
# sorted find output is safe and keeps the loop in the current shell (so the
|
|
# pass/fail counters survive).
|
|
for t in $(find "$TESTS_DIR" -name '*.sx' -type f | sort); do
|
|
name=${t#"$TESTS_DIR"/}
|
|
if "$SX" run "$t" $SX_RUN_FLAGS >/dev/null 2>&1; then
|
|
printf ' %-44s ok\n' "$name"
|
|
pass=$((pass + 1))
|
|
else
|
|
printf ' %-44s FAIL\n' "$name"
|
|
fail=$((fail + 1))
|
|
fi
|
|
done
|
|
|
|
total=$((pass + fail))
|
|
if [ "$total" -eq 0 ]; then
|
|
echo "no tests found under $TESTS_DIR" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "------------------------------------------------"
|
|
printf 'tests: %d pass: %d fail: %d\n' "$total" "$pass" "$fail"
|
|
|
|
[ "$fail" -eq 0 ]
|