#!/usr/bin/env bash # Run the Sirius Press test suite. # # tests/run.sh # # Needs PHP 7.4+ with GMP or BCMath, and Node 18+ for the interop suite. Both # are optional in the sense that the script says which one is missing and runs # the rest — but the interop suite is the one that proves a signature made in # a browser verifies on the server, so a run without it has not checked the # thing most worth checking. set -uo pipefail here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PHP_BIN="${PHP:-php}" NODE_BIN="${NODE:-node}" status=0 bar() { printf '\n\033[1m%s\033[0m\n' "$*"; } if command -v "$PHP_BIN" >/dev/null 2>&1; then for suite in test-crypto test-identity test-export; do bar "php ${suite}" "$PHP_BIN" "$here/$suite.php" || status=1 done else printf '\033[33mskipped:\033[0m no PHP on PATH (set PHP=/path/to/php)\n' >&2 status=1 fi if command -v "$NODE_BIN" >/dev/null 2>&1; then bar "node interop (browser wallet vs PHP)" "$NODE_BIN" "$here/interop.mjs" || status=1 else printf '\033[33mskipped:\033[0m no Node on PATH — the browser wallet was not checked against PHP\n' >&2 status=1 fi bar "syntax" syntax_ok=1 if command -v "$PHP_BIN" >/dev/null 2>&1; then while IFS= read -r file; do if ! "$PHP_BIN" -l "$file" >/dev/null 2>&1; then echo " FAIL $file" "$PHP_BIN" -l "$file" 2>&1 | head -3 syntax_ok=0 status=1 fi done < <(find "$here/.." -name '*.php' -not -path '*/dist/*' -not -path '*/node_modules/*') fi if command -v "$NODE_BIN" >/dev/null 2>&1; then while IFS= read -r file; do if ! "$NODE_BIN" --check "$file" >/dev/null 2>&1; then echo " FAIL $file" syntax_ok=0 status=1 fi done < <(find "$here/.." -name '*.js' -not -path '*/dist/*' -not -path '*/node_modules/*') fi [ "$syntax_ok" -eq 1 ] && echo " ok every PHP and JS file parses" echo if [ "$status" -eq 0 ]; then printf '\033[32mAll suites passed.\033[0m\n\n' else printf '\033[31mSomething failed or was skipped.\033[0m\n\n' fi exit "$status"