magicciv/tools/gut-headless.sh
Natalie 21d757a20f feat(@projects/@magic-civilization): add tile placement preview mode
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-04-25 23:35:18 -07:00

36 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Runs the GUT headless test suite — mirrors the CI "headless GUT" step exactly.
# Flatpak swallows get_tree().quit() exit codes, so we write a JUnit XML report
# to a home-accessible path and parse it for the failure count.
#
# Usage: bash tools/gut-headless.sh [extra gut flags]
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
RESULTS_DIR="$REPO_ROOT/.local/iter"
mkdir -p "$RESULTS_DIR"
RESULTS_FILE="$RESULTS_DIR/gut-junit.xml"
flatpak run --filesystem=home org.godotengine.Godot \
--path "$REPO_ROOT/src/game" \
--headless \
-s addons/gut/gut_cmdln.gd \
-gdir=engine/tests/unit \
-gexit \
"-gjunit_xml_file=$RESULTS_FILE" \
"$@"
# Flatpak swallows Godot's quit() exit code; parse the JUnit report instead.
FAIL_COUNT=0
if [[ -f "$RESULTS_FILE" ]]; then
FAIL_COUNT=$(grep -oP '(?<=<testsuites[^>]*failures=")[0-9]+' "$RESULTS_FILE" 2>/dev/null || echo 0)
FAIL_COUNT=${FAIL_COUNT:-0}
fi
if [[ "$FAIL_COUNT" -gt 0 ]]; then
echo "gut-headless: $FAIL_COUNT failing test(s)" >&2
exit 1
fi
exit 0