#!/usr/bin/env bash # Runs the GdUnit4 test suite headless. # # Usage: ./run_tests.sh [test path ...] # ./run_tests.sh all tests # ./run_tests.sh res://tests/unit only unit tests # ./run_tests.sh res://tests/unit/test_search.gd a single suite # # Godot is taken from $GODOT, then `godot` on PATH, then the macOS app bundles. set -euo pipefail cd "$(dirname "$0")" find_godot() { if [[ -n "${GODOT:-}" ]]; then echo "$GODOT" return fi if command -v godot > /dev/null; then command -v godot return fi for app in /Applications/Godot.app /Applications/Godot_mono.app; do if [[ -x "$app/Contents/MacOS/Godot" ]]; then echo "$app/Contents/MacOS/Godot" return fi done echo "Godot not found. Install Godot 4.7 or set GODOT=/path/to/godot" >&2 exit 1 } godot_bin="$(find_godot)" # Keeps the tests away from the real quiz settings file, see Settings.CONFIG_DIR_ENV MUSICPLAYER_CONFIG_DIR="$(mktemp -d)" export MUSICPLAYER_CONFIG_DIR trap 'rm -rf "$MUSICPLAYER_CONFIG_DIR"' EXIT paths=("$@") if [[ ${#paths[@]} -eq 0 ]]; then paths=(res://tests/unit res://tests/integration) fi test_args=() for path in "${paths[@]}"; do test_args+=(-a "$path") done # Builds the class cache so class_name types resolve; fast when nothing changed "$godot_bin" --headless --path . --import > /dev/null 2>&1 set +e "$godot_bin" --headless --path . \ -s addons/gdUnit4/bin/GdUnitCmdTool.gd --ignoreHeadlessMode "${test_args[@]}" exit_code=$? set -e # GdUnit4 exits with 101 when tests pass but report warnings (e.g. orphan nodes) if [[ $exit_code -eq 101 ]]; then echo "Tests passed with warnings, see the report above." exit 0 fi exit $exit_code