Files
MusicPlayer/run_tests.sh
T
Sansan 92e3a66075
Build / test (push) Successful in 45s
Build / build (push) Successful in 1m20s
Save the quiz settings to the config folder
The quiz card's settings are saved to quiz_settings.cfg in OS.get_config_dir()
on every change and loaded at start. Debug builds use their own file, and
MUSICPLAYER_CONFIG_DIR moves the file elsewhere so tests never touch it.

Count plays in statistics and Prefer less played soundtracks are not saved and
move from the quiz card to the Settings popup.
2026-10-07 18:13:00 +02:00

64 lines
1.8 KiB
Bash
Executable File

#!/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