sots-engine/tests/mars_text/build_and_run.sh

61 lines
2.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Self-contained build + test for src/mars/text (no root CMake needed).
# tests/mars_text/build_and_run.sh unit tests (+ real-data tests if SOTS_DATA_DIR is set)
# Env:
# SOTS_DATA_DIR extracted game text tree; unset -> real-data tests SKIP
# SOTS_RE_PARSERS dir with the Python reference readers (default ~/sots-re/verify/parsers);
# missing -> oracle cross-check SKIP
# CXX compiler (default g++)
set -euo pipefail
here="$(cd "$(dirname "$0")" && pwd)"
root="$(cd "$here/../.." && pwd)"
src="$root/src/mars/text"
build="${BUILD_DIR:-$here/build}"
mkdir -p "$build"
CXX="${CXX:-g++}"
flags=(-std=c++17 -Wall -Wextra -Werror -O1 -I"$root/src")
lib=("$src/value.cpp" "$src/flat_kv.cpp" "$src/manifest.cpp" "$src/csv.cpp")
echo "== build ($CXX)"
"$CXX" "${flags[@]}" "${lib[@]}" "$here/unit_tests.cpp" -o "$build/unit_tests"
"$CXX" "${flags[@]}" "${lib[@]}" "$here/dump_json.cpp" -o "$build/dump_json"
"$CXX" "${flags[@]}" "${lib[@]}" "$here/realdata_test.cpp" -o "$build/realdata_test"
echo "== unit tests"
"$build/unit_tests"
echo "== real-data facts"
"$build/realdata_test"
echo "== oracle cross-check"
if [ -z "${SOTS_DATA_DIR:-}" ]; then
echo "oracle: SKIP (SOTS_DATA_DIR not set)"
exit 0
fi
parsers="${SOTS_RE_PARSERS:-$HOME/sots-re/verify/parsers}"
if [ ! -f "$parsers/flat_kv.py" ]; then
echo "oracle: SKIP (reference readers not found at $parsers; set SOTS_RE_PARSERS)"
exit 0
fi
export SOTS_RE_PARSERS="$parsers"
py="${PYTHON:-/usr/bin/python3}"
out="$build/oracle"
rm -rf "$out"; mkdir -p "$out"
total=0; agree=0; failed=()
while IFS=$'\t' read -r kind rel; do
total=$((total + 1))
safe="$(echo "$rel" | tr '/ ' '__')"
"$build/dump_json" "$kind" "$SOTS_DATA_DIR/$rel" > "$out/$safe.ours.json"
"$py" "$here/oracle/dump.py" "$kind" "$SOTS_DATA_DIR/$rel" > "$out/$safe.oracle.json"
if "$py" "$here/oracle/compare.py" "$out/$safe.ours.json" "$out/$safe.oracle.json" "$kind $rel"; then
agree=$((agree + 1))
else
failed+=("$rel")
fi
done < <("$py" "$here/oracle/dump.py" list "$SOTS_DATA_DIR")
echo "oracle: $agree / $total files agree"
if [ "$agree" -ne "$total" ]; then
printf 'disagree: %s\n' "${failed[@]}"
exit 1
fi