Skip to content

Commit 54d00cf

Browse files
fix(test): fix unset ROOT_DIR causing test-parity to fail on Linux
The test script was using ROOT_DIR before it was defined, which fails with set -u (unbound variable). Also added has_oracle() helper function to properly check for the Rust/C oracle on both macOS and Linux.
1 parent 8a179c5 commit 54d00cf

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

zig/harness/test-parity.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ set -euo pipefail
4040

4141
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
4242
ZIG_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
43+
ROOT_DIR="$(cd "$ZIG_DIR/.." && pwd)"
44+
45+
# Helper function to check if the Rust/C oracle is available
46+
# Works on both macOS (.dylib) and Linux (.so)
47+
has_oracle() {
48+
[[ -f "$ROOT_DIR/lib/crsqlite.dylib" ]] || \
49+
[[ -f "$ROOT_DIR/lib/crsqlite-linux-x86_64.so" ]] || \
50+
[[ -f "$ROOT_DIR/lib/crsqlite-linux-aarch64.so" ]] || \
51+
[[ -f "$ROOT_DIR/lib/crsqlite-darwin-aarch64.dylib" ]] || \
52+
[[ -f "$ROOT_DIR/lib/crsqlite-darwin-x86_64.dylib" ]]
53+
}
4354

4455
echo "╔═══════════════════════════════════════════════════════════════════════╗"
4556
echo "║ Zig CR-SQLite Parity Test Suite ║"
@@ -503,7 +514,7 @@ fi
503514

504515
# Run fract parity tests (oracle comparison: Zig vs Rust/C)
505516
echo "Running test-fract-parity.sh..."
506-
if [[ -f "$ROOT_DIR/lib/crsqlite.dylib" ]] 2>/dev/null || ROOT_DIR="$(cd "$ZIG_DIR/.." && pwd)" && [[ -f "$ROOT_DIR/lib/crsqlite.dylib" ]]; then
517+
if has_oracle; then
507518
if bash "$SCRIPT_DIR/test-fract-parity.sh" > "$TMPFILE" 2>&1; then
508519
FRACT_PARITY_PASS=$(grep -c "PASS" "$TMPFILE" 2>/dev/null) || FRACT_PARITY_PASS=0
509520
echo " Fract parity tests: $FRACT_PARITY_PASS passed"
@@ -543,8 +554,7 @@ fi
543554

544555
# Run API surface parity test (oracle comparison vs Rust/C)
545556
echo "Running test-api-surface.sh..."
546-
ROOT_DIR="$(cd "$ZIG_DIR/.." && pwd)"
547-
if [[ -f "$ROOT_DIR/lib/crsqlite.dylib" ]]; then
557+
if has_oracle; then
548558
# Export extension paths using the freshly built Zig extension
549559
export ZIG_EXT_PATH="$EXT"
550560
if bash "$SCRIPT_DIR/test-api-surface.sh" > "$TMPFILE" 2>&1; then
@@ -560,13 +570,13 @@ if [[ -f "$ROOT_DIR/lib/crsqlite.dylib" ]]; then
560570
# Note: gaps are tracked but don't fail the suite - they're expected during development
561571
fi
562572
else
563-
echo " API surface tests: SKIPPED (Rust/C extension not found at $ROOT_DIR/lib/crsqlite.dylib)"
573+
echo " API surface tests: SKIPPED (Rust/C extension not found)"
564574
TOTAL_SKIP=$((TOTAL_SKIP + 2))
565575
fi
566576

567577
# Run db_version parity tests (oracle comparison: Zig vs Rust/C)
568578
echo "Running test-db-version-parity.sh..."
569-
if [[ -f "$ROOT_DIR/lib/crsqlite.dylib" ]]; then
579+
if has_oracle; then
570580
if bash "$SCRIPT_DIR/test-db-version-parity.sh" > "$TMPFILE" 2>&1; then
571581
DBVER_PASS=$(grep -c "PASS:" "$TMPFILE" 2>/dev/null) || DBVER_PASS=0
572582
echo " db_version parity tests: $DBVER_PASS passed"
@@ -592,7 +602,7 @@ fi
592602

593603
# Run rows_impacted parity tests (oracle comparison: Zig vs Rust/C counter reset timing)
594604
echo "Running test-rows-impacted-parity.sh..."
595-
if [[ -f "$ROOT_DIR/lib/crsqlite.dylib" ]]; then
605+
if has_oracle; then
596606
if bash "$SCRIPT_DIR/test-rows-impacted-parity.sh" > "$TMPFILE" 2>&1; then
597607
ROWS_PASS=$(grep -c "PASS:" "$TMPFILE" 2>/dev/null) || ROWS_PASS=0
598608
echo " rows_impacted parity tests: $ROWS_PASS passed"

0 commit comments

Comments
 (0)