#!/bin/bash # Tests for / (docs/design-sql-bound-parameters.md, phase 1): # 1. tests/sqlbind_test.cpp - unit tests for SqlBind.cpp (no MySQL needed) # 2. tests/testbind.jet - end to end through jet-2.0 against a real MySQL # server (TEMPORARY tables only), compared with # tests/testbind.expected # 3. jetc - is void in the compiler too, and a # compiled page runs the same / code # # Build jet-2.0 first (./compile). The MySQL part needs: # JETTEST_DB_USER, JETTEST_DB_PASSWORD (required, or it is skipped) # JETTEST_DB_HOST (default localhost), JETTEST_DB_NAME (default test) set -u T="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" JC="$(cd "$T/.." && pwd)" CU="$JC/../CoreUtils" WORK="$(mktemp -d)" trap 'rm -rf "$WORK"' EXIT fail=0 echo "== unit tests (SqlBind) ==" g++ -g -std=c++23 -I"$CU" -I"$JC" "$T/sqlbind_test.cpp" "$JC/SqlBind.cpp" -L"$CU" -lCoreUtils -o "$WORK/sqlbind_test" || exit 1 "$WORK/sqlbind_test" || fail=1 echo "== end to end (jet-2.0 + MySQL) ==" if [ -z "${JETTEST_DB_USER:-}" ] || [ -z "${JETTEST_DB_PASSWORD:-}" ]; then echo "SKIPPED: set JETTEST_DB_USER and JETTEST_DB_PASSWORD" else export JETTEST_DB_HOST="${JETTEST_DB_HOST:-localhost}" JETTEST_DB_NAME="${JETTEST_DB_NAME:-test}" (cd "$T" && "$JC/jet-2.0" testbind.jet) > "$WORK/testbind.out" 2>&1 if diff -u "$T/testbind.expected" "$WORK/testbind.out"; then echo "PASS ($(wc -l < "$T/testbind.expected") lines match)" else echo "FAIL"; fail=1 fi fi echo "== jetc ==" g++ -g -std=c++23 -o "$WORK/jetc" "$JC/jetc/jetc.cpp" "$JC/jetc/JetParser.cpp" "$JC/jetc/JetCodegen.cpp" "$JC/jetc/JetLint.cpp" || exit 1 # A bare must not swallow the content after it looking for . printf 'Aselect ?BC\n' > "$WORK/void.jet" "$WORK/jetc" "$WORK/void.jet" "$WORK/void.cpp" >/dev/null || fail=1 if grep -q 'select ?' "$WORK/void.cpp" && grep -q '""' "$WORK/void.cpp" && grep -q '"C\\n"' "$WORK/void.cpp"; then echo "PASS (bind is void; sql span intact)" else echo "FAIL: unexpected codegen for bind"; grep -n 'interpretSpan\|out.write' "$WORK/void.cpp"; fail=1 fi if [ -n "${JETTEST_DB_USER:-}" ] && [ -n "${JETTEST_DB_PASSWORD:-}" ]; then # The whole end-to-end test again, compiled by jetc instead of interpreted. # Drop the #! line, and the newline after (the interpreter stops # at ; a compiled page would emit it as text). tail -n +2 "$T/testbind.jet" | head -c -1 > "$WORK/compiled.jet" "$WORK/jetc" "$WORK/compiled.jet" "$WORK/compiled.cpp" >/dev/null || fail=1 objs="" for f in "$JC"/*.cpp; do [ "$(basename "$f")" = "jet-2.0.cpp" ] && continue o="$WORK/$(basename "${f%.cpp}").o" g++ -g -c -std=c++23 -I"$CU" -I"$JC" "$f" -o "$o" & objs="$objs $o" done wait g++ -g -std=c++23 -I"$CU" -I"$JC" "$WORK/compiled.cpp" $objs -L"$CU" -lCoreUtils -lmysqlclient -lssl -lcrypto -o "$WORK/compiled" || exit 1 (cd "$T" && "$WORK/compiled") > "$WORK/compiled.out" 2>&1 if diff -u "$T/testbind.expected" "$WORK/compiled.out"; then echo "PASS (compiled page output matches)" else echo "FAIL (compiled page)"; fail=1 fi fi [ $fail = 0 ] && echo "ALL PASSED" || echo "FAILURES" exit $fail