#!/usr/bin/env sh
# Everything that can run WITHOUT PHP or a database: front-end tests, QR decoding, static analysis of PHP/SQL.
# Needs: node >= 18, python3 (+ opencv-python, numpy for the QR decode step).
cd "$(dirname "$0")/.." || exit 1
rc=0
echo "== JS unit tests";            node --test tests/js/format.test.mjs tests/js/qr.test.mjs 2>&1 | grep -E "^# (tests|pass|fail)" || rc=1
echo "== JS static checks";         node tests/js/static-check.mjs   || rc=1
echo "== JS import/export check";   node tests/js/imports-check.mjs   || rc=1
echo "== QR decode (OpenCV)";       node tests/js/qr-matrix.mjs /tmp/qr_cases.json >/dev/null && python3 tests/js/verify_qr.py /tmp/qr_cases.json || rc=1
node tests/js/qr-sweep.mjs /tmp/qr_sweep.json >/dev/null && python3 tests/js/verify_qr.py /tmp/qr_sweep.json || rc=1
echo "== PHP static lint";          python3 tests/tools/php_lint.py | tail -2 || rc=1
echo "== SQL placeholder check";    python3 tests/tools/sql_params_check.py || rc=1
echo "== Schema consistency";       python3 tests/tools/schema_check.py || rc=1
exit $rc
