#!/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 # The fork's own PHP, plus every core file the fork patches. Sweeping all # of wordpress/ would lint 3,800 files of upstream code that upstream # already tests, and turn a one-second suite into a minute of waiting. lint_targets() { find "$here/../plugins" "$here/../mu-plugins" "$here" \ -name '*.php' -not -path '*/node_modules/*' 2>/dev/null for patch in "$here"/../patches/*.patch; do [ -e "$patch" ] || continue sed -n 's|^--- a/||p' "$patch" | while IFS= read -r rel; do case "$rel" in *.php) echo "$here/../wordpress/$rel" ;; esac done done } while IFS= read -r file; do [ -f "$file" ] || continue 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 < <(lint_targets) 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/../plugins" "$here" -name '*.js' -not -path '*/node_modules/*' 2>/dev/null) fi [ "$syntax_ok" -eq 1 ] && echo " ok the fork's PHP and JS parses, including every patched core file" 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"