From c556928d0ae66db14cc57789fdd77b6712615c96 Mon Sep 17 00:00:00 2001 From: Cormac Shannon <> Date: Thu, 12 Mar 2026 19:04:21 +0000 Subject: [PATCH] Add compatibility test script for third-party Lua projects (issue #24) Tests lua-TestMore, json.lua, and lume against the Lush binary to verify parser/lexer/runtime changes don't break standard Lua code. --- .gitignore | 2 ++ test-compat.sh | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100755 test-compat.sh diff --git a/.gitignore b/.gitignore index ae2899e0..f88415a2 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ testes/libs/all temp lua + +compat-tests/ diff --git a/test-compat.sh b/test-compat.sh new file mode 100755 index 00000000..7786136c --- /dev/null +++ b/test-compat.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +LUSH="${LUSH:-$SCRIPT_DIR/lua}" +COMPAT_DIR="$SCRIPT_DIR/compat-tests" + +if [[ "${1:-}" == "--clean" ]]; then + rm -rf "$COMPAT_DIR" + echo "Cleaned $COMPAT_DIR" +fi + +mkdir -p "$COMPAT_DIR" + +# --- Helpers --- + +RESULTS_FILE="$COMPAT_DIR/.results.tmp" +FAIL_COUNT=0 +: > "$RESULTS_FILE" + +run_test() { + local name="$1"; shift + local logfile="$COMPAT_DIR/$name.log" + echo "--- Running $name ---" + if "$@" >"$logfile" 2>&1; then + echo "$name|PASS" >>"$RESULTS_FILE" + echo " PASS" + else + echo "$name|FAIL" >>"$RESULTS_FILE" + echo " FAIL (see $logfile)" + ((FAIL_COUNT++)) || true + fi +} + +print_summary() { + echo "" + echo "=== Compatibility Test Results ===" + while IFS='|' read -r name status; do + printf " %-20s %s\n" "$name" "$status" + done <"$RESULTS_FILE" + echo "" + rm -f "$RESULTS_FILE" +} + +clone_or_pull() { + local name="$1" url="$2" tag="$3" + local dest="$COMPAT_DIR/$name" + if [[ -d "$dest" ]]; then + echo "--- $name: already cloned ---" + else + echo "--- Cloning $name @ $tag ---" + git clone --depth 1 --branch "$tag" "$url" "$dest" + fi +} + +# --- Check Lush binary --- + +if [[ ! -x "$LUSH" ]]; then + echo "Error: Lush binary not found at $LUSH" + echo "Run 'make' first, or set LUSH=/path/to/lua" + exit 1 +fi + +echo "Using Lush binary: $LUSH" +echo "" + +# === lua-TestMore (TAP test framework) === + +clone_or_pull "lua-TestMore" "https://framagit.org/fperrad/lua-TestMore.git" "0.3.5" +( + cd "$COMPAT_DIR/lua-TestMore" + export LUA_PATH="$COMPAT_DIR/lua-TestMore/src/?.lua;;" + run_test "lua-TestMore" "$LUSH" test/00require.t +) + +# === json.lua (JSON encoder/decoder) === + +clone_or_pull "json.lua" "https://github.com/rxi/json.lua.git" "v0.1.2" +( + cd "$COMPAT_DIR/json.lua/test" + run_test "json.lua" "$LUSH" test.lua +) + +# === lume (utility library, 264 tests) === + +clone_or_pull "lume" "https://github.com/rxi/lume.git" "v2.3.0" +( + cd "$COMPAT_DIR/lume/test" + run_test "lume" "$LUSH" test.lua +) + +# === Summary === + +print_summary +exit "$FAIL_COUNT"