Files
rosetta/tools/test.sh
T

34 lines
1.7 KiB
Bash

#!/usr/bin/env bash
# Tests (bash tools/test.sh [filter]): generate the fixtures (tools/fixtures.py -> tests/gen), regenerate the registry,
# build both targets (tools/build.py), then run every tests/**/*.luau twice: under `luau --codegen -O2` (the source,
# through the .luaurc aliases) and under `luajit` (build/luajit/tests/**/*.lua, with the compat prelude), then the lint.
# A filter runs only the tests whose path contains it (and the fixture generators whose name contains it), and skips
# the lint. RUNTIMES="luau" or "luajit" runs one runtime only.
cd "$(dirname "$0")/.." || exit 1
LUAU=${LUAU:-$(command -v luau || nix shell nixpkgs#luau -c sh -c 'command -v luau')}
LUAJIT=${LUAJIT:-$(command -v luajit || nix shell nixpkgs#luajit -c sh -c 'command -v luajit')}
RUNTIMES=${RUNTIMES:-"luau luajit"}
LJPATH='package.path = "build/luajit/?.lua;build/luajit/?/init.lua;" .. package.path'
fail=0
python3 -I tools/fixtures.py $1 || { echo "FAILED: fixtures"; exit 1; }
python3 -I tools/gen_registry.py > /dev/null || { echo "FAILED: gen_registry"; exit 1; }
python3 -I tools/build.py || { echo "FAILED: build"; exit 1; }
passed=0
for t in $(find tests -name '*.luau' -not -path 'tests/gen/*' -not -path 'tests/fixtures/*' -not -name 'T.luau' | sort); do
[ -n "$1" ] && [[ "$t" != *$1* ]] && continue
for rt in $RUNTIMES; do
echo "== $t ($rt)"
if [ "$rt" = luau ]; then
"$LUAU" --codegen -O2 "$t" || { echo "FAILED: $t ($rt)"; fail=1; continue; }
else
"$LUAJIT" -e "$LJPATH" "build/luajit/${t%.luau}.lua" || { echo "FAILED: $t ($rt)"; fail=1; continue; }
fi
passed=$((passed + 1))
done
done
if [ -z "$1" ]; then
bash tools/lint.sh || fail=1
fi
[ $fail -eq 0 ] && echo "formats-luau: all tests passed ($passed runs)" || echo "formats-luau: FAILURES"
exit $fail