86 lines
2.7 KiB
Bash
86 lines
2.7 KiB
Bash
#!/usr/bin/env bash
|
|||
|
|
#
|
||
|
|
# Run the accessibility testbed against a clean save, WITHOUT destroying the
|
||
|
|
# player's real one.
|
||
|
|
#
|
||
|
|
# The testbed drives a fresh playthrough from the main menu, so it needs the
|
||
|
|
# LOVE save directory empty -- otherwise "Continue" appears, the new-game flow
|
||
|
|
# differs, and the prologue it navigates has already happened. That clean-out
|
||
|
|
# used to be a bare `rm -rf` in the docs, which silently ate a real save every
|
||
|
|
# time someone ran the tests.
|
||
|
|
#
|
||
|
|
# This cannot be done from inside the mod: love.load() reads config, keybindings
|
||
|
|
# and user data long before main.lua reaches our entry point, so by the time any
|
||
|
|
# Lua of ours runs the save directory has already been read. It has to happen
|
||
|
|
# around the process.
|
||
|
|
#
|
||
|
|
# So: MOVE the save aside (never delete it), run, then move it back. The test
|
||
|
|
# run's own save directory is discarded, leaving the tree exactly as it was.
|
||
|
|
#
|
||
|
|
# Usage: accessibility/tests/run-testbed.sh [extra love args...]
|
||
|
|
|
||
|
|
set -uo pipefail
|
||
|
|
|
||
|
|
LOVE="${LOVE:-C:/Program Files/LOVE/lovec.exe}"
|
||
|
|
GAME_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||
|
|
|
||
|
|
# LOVE writes to <appdata>/LOVE/<t.identity>; conf.lua sets identity "Alchemist".
|
||
|
|
SAVE_DIR="${APPDATA:-$HOME/AppData/Roaming}/LOVE/Alchemist"
|
||
|
|
BACKUP_DIR="${SAVE_DIR}.a11y-backup.$$"
|
||
|
|
|
||
|
|
restored=0
|
||
|
|
|
||
|
|
restore() {
|
||
|
|
# Idempotent: this runs from the EXIT trap and possibly from a signal trap.
|
||
|
|
if [ "$restored" -eq 1 ]; then
|
||
|
|
return
|
||
|
|
fi
|
||
|
|
restored=1
|
||
|
|
|
||
|
|
# Throw away whatever the test run created, but only if we know it is ours
|
||
|
|
# (i.e. we successfully moved the real save out of the way first).
|
||
|
|
if [ -d "$BACKUP_DIR" ]; then
|
||
|
|
rm -rf "$SAVE_DIR"
|
||
|
|
if mv "$BACKUP_DIR" "$SAVE_DIR"; then
|
||
|
|
echo "[testbed] real save restored to $SAVE_DIR"
|
||
|
|
else
|
||
|
|
# Loud, and non-destructive: the save is still on disk, just parked.
|
||
|
|
echo "[testbed] !! COULD NOT RESTORE YOUR SAVE." >&2
|
||
|
|
echo "[testbed] !! It is safe at: $BACKUP_DIR" >&2
|
||
|
|
echo "[testbed] !! Move it back to: $SAVE_DIR" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
else
|
||
|
|
# There was no save to begin with; don't leave the test run's one behind
|
||
|
|
# to be mistaken for a real save later.
|
||
|
|
rm -rf "$SAVE_DIR"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
# Checked BEFORE anything is moved, so a bad LOVE path can't leave the save
|
||
|
|
# parked under a backup name.
|
||
|
|
if [ ! -f "$LOVE" ]; then
|
||
|
|
echo "[testbed] LOVE not found at: $LOVE" >&2
|
||
|
|
echo "[testbed] set LOVE=/path/to/lovec.exe" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
trap restore EXIT
|
||
|
|
trap 'restore; exit 130' INT TERM
|
||
|
|
|
||
|
|
if [ -e "$SAVE_DIR" ]; then
|
||
|
|
if ! mv "$SAVE_DIR" "$BACKUP_DIR"; then
|
||
|
|
echo "[testbed] could not move the save aside; refusing to run rather than" >&2
|
||
|
|
echo "[testbed] risk your save. Is the game still open?" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
echo "[testbed] real save parked at $BACKUP_DIR"
|
||
|
|
else
|
||
|
|
echo "[testbed] no existing save to protect"
|
||
|
|
fi
|
||
|
|
|
||
|
|
"$LOVE" "$GAME_DIR" --a11y-test "$@"
|
||
|
|
status=$?
|
||
|
|
|
||
|
|
exit $status
|