66 lines
2.6 KiB
Bash
Executable file
66 lines
2.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Self-contained build + test for src/game/data (plain g++, no CMake needed).
|
|
#
|
|
# tests/game_data/build_and_run.sh
|
|
#
|
|
# Always builds and runs the unit tests. When SOTS_DATA_DIR points at an
|
|
# extracted sots.gob (+ sots_local_en.gob) tree it also runs the real-data
|
|
# facts test, dumps the whole catalog and, if the reference catalogs are
|
|
# reachable (SOTS_ORACLE_DIR, default ~/sots-re/verify/results/data-catalogs),
|
|
# compares field by field with oracle/compare.py.
|
|
#
|
|
# Env: CXX (g++), PYTHON (python3), BUILD_DIR (tests/game_data/build),
|
|
# SOTS_DATA_DIR, SOTS_ORACLE_DIR.
|
|
set -euo pipefail
|
|
|
|
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
ROOT=$(cd "$HERE/../.." && pwd)
|
|
BUILD=${BUILD_DIR:-$HERE/build}
|
|
CXX=${CXX:-g++}
|
|
PYTHON=${PYTHON:-python3}
|
|
FLAGS=(-std=c++17 -O2 -Wall -Wextra -Wpedantic -Werror -I"$ROOT/src" -I"$HERE")
|
|
LIB=(
|
|
"$ROOT/src/mars/parse/blocks.cpp" "$ROOT/src/mars/parse/value.cpp"
|
|
"$ROOT/src/mars/text/value.cpp" "$ROOT/src/mars/text/flat_kv.cpp"
|
|
"$ROOT/src/mars/text/manifest.cpp" "$ROOT/src/mars/text/csv.cpp"
|
|
"$ROOT/src/game/data/common.cpp" "$ROOT/src/game/data/block.cpp"
|
|
"$ROOT/src/game/data/weapon.cpp" "$ROOT/src/game/data/shipsection.cpp"
|
|
"$ROOT/src/game/data/turrets.cpp" "$ROOT/src/game/data/techtree.cpp"
|
|
"$ROOT/src/game/data/strings.cpp" "$ROOT/src/game/data/catalog.cpp"
|
|
)
|
|
|
|
mkdir -p "$BUILD"
|
|
|
|
echo "== building unit tests"
|
|
"$CXX" "${FLAGS[@]}" "${LIB[@]}" "$HERE/test_main.cpp" "$HERE/test_weapon.cpp" "$HERE/test_shipsection.cpp" \
|
|
"$HERE/test_turrets.cpp" "$HERE/test_techtree.cpp" "$HERE/test_catalog.cpp" -o "$BUILD/unit_tests"
|
|
echo "== running unit tests"
|
|
"$BUILD/unit_tests"
|
|
|
|
if [ -z "${SOTS_DATA_DIR:-}" ]; then
|
|
echo "== SOTS_DATA_DIR not set: skipping real-data tests"
|
|
exit 0
|
|
fi
|
|
if [ ! -d "$SOTS_DATA_DIR" ]; then
|
|
echo "== SOTS_DATA_DIR=$SOTS_DATA_DIR is not a directory" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "== building real-data tools"
|
|
"$CXX" "${FLAGS[@]}" "${LIB[@]}" "$HERE/realdata_test.cpp" -o "$BUILD/realdata_test"
|
|
"$CXX" "${FLAGS[@]}" "${LIB[@]}" "$HERE/dump_catalog.cpp" -o "$BUILD/dump_catalog"
|
|
|
|
echo "== real-data facts"
|
|
"$BUILD/realdata_test"
|
|
|
|
echo "== dumping catalog"
|
|
"$BUILD/dump_catalog" "$SOTS_DATA_DIR" "$BUILD/catalog.json"
|
|
|
|
ORACLE=${SOTS_ORACLE_DIR:-$HOME/sots-re/verify/results/data-catalogs}
|
|
if [ ! -f "$ORACLE/weapons.json" ]; then
|
|
echo "== oracle catalogs not found at $ORACLE (set SOTS_ORACLE_DIR): skipping comparison"
|
|
exit 0
|
|
fi
|
|
echo "== comparing with the oracle catalogs"
|
|
read -ra PY <<< "$PYTHON" # PYTHON may be a command with arguments ("uv run python3")
|
|
exec "${PY[@]}" "$HERE/oracle/compare.py" "$BUILD/catalog.json" "$ORACLE"
|