sots-engine/tests/game_sim/build_and_run.sh

37 lines
1.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# Build and run the game/sim unit tests with plain g++ (no CMake needed).
# tests/game_sim/build_and_run.sh # build + run all
# BUILD_DIR=/some/dir tests/game_sim/build_and_run.sh
# SOTS_SAVES_JSON=/path/save.json tests/game_sim/build_and_run.sh # also runs the smoke test on real data
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
root="$(cd "$here/../.." && pwd)"
build="${BUILD_DIR:-$(mktemp -d "${TMPDIR:-/tmp}/sots-game-sim.XXXXXX")}"
mkdir -p "$build"
CXX="${CXX:-g++}"
CXXFLAGS="${CXXFLAGS:--std=c++17 -O1 -g -Wall -Wextra -Werror -pedantic}"
srcs=("$root"/src/game/sim/economy.cpp "$root"/src/game/sim/research.cpp \
"$root"/src/game/sim/colony.cpp "$root"/src/game/sim/movement.cpp)
objs=()
for s in "${srcs[@]}"; do
o="$build/$(basename "${s%.cpp}").o"
$CXX $CXXFLAGS -I"$root/src" -c "$s" -o "$o"
objs+=("$o")
done
status=0
for t in economy research colony movement; do
exe="$build/test_$t"
$CXX $CXXFLAGS -I"$root/src" -I"$here" "$here/test_$t.cpp" "${objs[@]}" -o "$exe"
if ! "$exe"; then status=1; fi
done
exe="$build/smoke_real_save"
$CXX $CXXFLAGS -I"$root/src" -I"$here" "$here/smoke_real_save.cpp" "${objs[@]}" -o "$exe"
if ! "$exe"; then status=1; fi
if [ $status -eq 0 ]; then echo "game_sim: all tests passed (build dir $build)"; else echo "game_sim: FAILURES (build dir $build)"; fi
exit $status