|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" |
| 5 | +source "$ROOT_DIR/lib/test_utils.sh" |
| 6 | + |
| 7 | +PASS_DIR="$ROOT_DIR/semantic/pass" |
| 8 | +FAIL_DIR="$ROOT_DIR/semantic/fail" |
| 9 | +TMP_DIR="${TMP_DIR:-$ROOT_DIR/../build/test-tmp}" |
| 10 | +mkdir -p "$TMP_DIR" |
| 11 | + |
| 12 | +pass_count=0 |
| 13 | +fail_count=0 |
| 14 | + |
| 15 | +echo "[Semantic] Rodando PASS (C -> Lua -> exec) ..." |
| 16 | +for cfile in "$PASS_DIR"/*.c; do |
| 17 | + [ -e "$cfile" ] || continue |
| 18 | + base="$(basename "$cfile" .c)" |
| 19 | + luafile="$PASS_DIR/$base.lua" |
| 20 | + outlua="$TMP_DIR/$base.out.lua" |
| 21 | + outlog="$TMP_DIR/$base.run.log" |
| 22 | + |
| 23 | + # Compila C->Lua |
| 24 | + "$C2LUA" "$cfile" > "$outlua" |
| 25 | + |
| 26 | + # Checa sintaxe Lua |
| 27 | + check_lua_syntax "$outlua" |
| 28 | + |
| 29 | + # Executa Lua |
| 30 | + if ! "$LUA_BIN" "$outlua" > "$outlog" 2>&1; then |
| 31 | + echo "FAIL (exec): $base" |
| 32 | + cat "$outlog" |
| 33 | + ((fail_count++)) || true |
| 34 | + continue |
| 35 | + fi |
| 36 | + |
| 37 | + # Compara com Lua esperado (semântica igual) |
| 38 | + if ! diff_golden "$outlua" "$luafile"; then |
| 39 | + echo "FAIL (lua mismatch): $base" |
| 40 | + ((fail_count++)) || true |
| 41 | + continue |
| 42 | + fi |
| 43 | + |
| 44 | + echo "PASS: $base" |
| 45 | + ((pass_count++)) || true |
| 46 | +done |
| 47 | + |
| 48 | +echo |
| 49 | +echo "[Semantic] Rodando FAIL (erros devem coincidir com golden .err) ..." |
| 50 | +for cfile in "$FAIL_DIR"/*.c; do |
| 51 | + [ -e "$cfile" ] || continue |
| 52 | + base="$(basename "$cfile" .c)" |
| 53 | + errfile="$FAIL_DIR/$base.err" |
| 54 | + goterr="$TMP_DIR/$base.got.err" |
| 55 | + |
| 56 | + # Espera falha: captura stderr e stdout |
| 57 | + set +e |
| 58 | + "$C2LUA" "$cfile" > /dev/null 2> "$goterr.raw" |
| 59 | + status=$? |
| 60 | + set -e |
| 61 | + |
| 62 | + if [ $status -eq 0 ]; then |
| 63 | + echo "FAIL (esperava erro, compilou com sucesso): $base" |
| 64 | + ((fail_count++)) || true |
| 65 | + continue |
| 66 | + fi |
| 67 | + |
| 68 | + normalize_err < "$goterr.raw" > "$goterr" |
| 69 | + |
| 70 | + if ! diff_golden "$goterr" "$errfile"; then |
| 71 | + echo "FAIL (mensagem diferente): $base" |
| 72 | + ((fail_count++)) || true |
| 73 | + continue |
| 74 | + fi |
| 75 | + |
| 76 | + echo "PASS (erro): $base" |
| 77 | + ((pass_count++)) || true |
| 78 | +done |
| 79 | + |
| 80 | +echo |
| 81 | +echo "Resumo: $pass_count PASS, $fail_count FAIL" |
| 82 | +exit $([ $fail_count -eq 0 ]) |
0 commit comments