Files
hakorune/tools/hako_check/run_tests.sh

51 lines
1.4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
BIN="${NYASH_BIN:-$ROOT/target/release/hakorune}"
if [ ! -x "$BIN" ]; then
echo "[TEST] hakorune not built: $BIN" >&2
echo "Run: cargo build --release" >&2
exit 2
fi
TARGET_DIR="$ROOT/tools/hako_check/tests"
fail=0
run_case() {
local dir="$1"
local expected="$dir/expected.json"
local input_ok="$dir/ok.hako"
local input_ng="$dir/ng.hako"
if [ ! -f "$expected" ]; then echo "[TEST] skip (no expected): $dir"; return; fi
if [ ! -f "$input_ok" ] && [ ! -f "$input_ng" ]; then echo "[TEST] skip (no inputs): $dir"; return; fi
local tmp_out="/tmp/hako_test_$$.json"
NYASH_DISABLE_NY_COMPILER=1 HAKO_DISABLE_NY_COMPILER=1 \
NYASH_PARSER_STAGE3=1 HAKO_PARSER_STAGE3=1 NYASH_PARSER_SEAM_TOLERANT=1 HAKO_PARSER_SEAM_TOLERANT=1 \
NYASH_ENABLE_USING=1 HAKO_ENABLE_USING=1 NYASH_USING_AST=1 \
"$BIN" --backend vm "$ROOT/tools/hako_check/cli.hako" -- --format json-lsp ${input_ok:+"$input_ok"} ${input_ng:+"$input_ng"} \
>"$tmp_out" 2>/dev/null || true
if ! diff -u "$expected" "$tmp_out" >/dev/null; then
echo "[TEST/FAIL] $dir" >&2
diff -u "$expected" "$tmp_out" || true
fail=$((fail+1))
else
echo "[TEST/OK] $dir"
fi
rm -f "$tmp_out"
}
for d in "$TARGET_DIR"/*; do
[ -d "$d" ] || continue
run_case "$d"
done
if [ $fail -ne 0 ]; then
echo "[TEST/SUMMARY] failures=$fail" >&2
exit 1
fi
echo "[TEST/SUMMARY] all green"
exit 0