Files
rose-ash/lib/ruby/test.sh
giles 15eb133311
Some checks are pending
Test, Build, and Deploy / test-build-deploy (push) Waiting to run
ruby: Phase 1 parser (+83 tests, 190 total)
2026-04-25 18:50:49 +00:00

93 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Ruby-on-SX test runner.
# Usage:
# bash lib/ruby/test.sh # run all tests
# bash lib/ruby/test.sh -v # verbose
# bash lib/ruby/test.sh tests/parse.sx # single file
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
SX_SERVER="hosts/ocaml/_build/default/bin/sx_server.exe"
if [ ! -x "$SX_SERVER" ]; then
MAIN_ROOT=$(git worktree list | head -1 | awk '{print $1}')
if [ -x "$MAIN_ROOT/$SX_SERVER" ]; then
SX_SERVER="$MAIN_ROOT/$SX_SERVER"
else
echo "ERROR: sx_server.exe not found."
exit 1
fi
fi
VERBOSE=""
FILES=()
for arg in "$@"; do
case "$arg" in
-v|--verbose) VERBOSE=1 ;;
*) FILES+=("$arg") ;;
esac
done
if [ ${#FILES[@]} -eq 0 ]; then
mapfile -t FILES < <(find lib/ruby/tests -maxdepth 2 -name '*.sx' | sort)
fi
TOTAL_PASS=0
TOTAL_FAIL=0
FAILED_FILES=()
for FILE in "${FILES[@]}"; do
[ -f "$FILE" ] || { echo "skip $FILE (not found)"; continue; }
TMPFILE=$(mktemp)
# Build epoch sequence: load runtime files, then test file, then eval summary.
{
echo "(epoch 1)"
echo "(load \"lib/ruby/tokenizer.sx\")"
if [ -f "lib/ruby/parser.sx" ]; then
echo "(epoch 2)"
echo "(load \"lib/ruby/parser.sx\")"
fi
echo "(epoch 3)"
echo "(load \"$FILE\")"
echo "(epoch 4)"
echo "(eval \"(list rb-test-pass rb-test-fail)\")"
} > "$TMPFILE"
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>&1 || true)
rm -f "$TMPFILE"
# Extract epoch 4 result: (ok-len 4 N)\n<val> or (ok 4 <val>)
LINE=$(printf '%s\n' "$OUTPUT" | awk '/^\(ok-len 4 / {getline; print; exit}')
if [ -z "$LINE" ]; then
LINE=$(printf '%s\n' "$OUTPUT" \
| grep -E '^\(ok 4 \([0-9]+ [0-9]+\)\)' | tail -1 \
| sed -E 's/^\(ok 4 //; s/\)$//')
fi
if [ -z "$LINE" ]; then
echo "$FILE: could not extract summary"
printf '%s\n' "$OUTPUT" | grep -v '^(ok ' | tail -10
TOTAL_FAIL=$((TOTAL_FAIL + 1))
FAILED_FILES+=("$FILE")
continue
fi
P=$(printf '%s\n' "$LINE" | sed -E 's/^\(([0-9]+) ([0-9]+)\).*/\1/')
F=$(printf '%s\n' "$LINE" | sed -E 's/^\(([0-9]+) ([0-9]+)\).*/\2/')
TOTAL_PASS=$((TOTAL_PASS + P))
TOTAL_FAIL=$((TOTAL_FAIL + F))
if [ "$F" -gt 0 ]; then
FAILED_FILES+=("$FILE")
printf '✗ %-40s %d/%d\n' "$FILE" "$P" "$((P+F))"
elif [ "$VERBOSE" = "1" ]; then
printf '✓ %-40s %d passed\n' "$FILE" "$P"
fi
done
TOTAL=$((TOTAL_PASS + TOTAL_FAIL))
if [ $TOTAL_FAIL -eq 0 ]; then
echo "$TOTAL_PASS/$TOTAL ruby-on-sx tests passed"
else
echo "$TOTAL_PASS/$TOTAL passed, $TOTAL_FAIL failed in: ${FAILED_FILES[*]}"
fi
[ $TOTAL_FAIL -eq 0 ]