123 lines
4.1 KiB
Bash
Executable File
123 lines
4.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ABOUT ME
|
|
# Tests install.sh's discovery of the Cosmoteer Mods folder.
|
|
#
|
|
# Why it exists: the Mods folder sits inside a Proton prefix under whichever
|
|
# Steam library the game was installed to, and that library can live anywhere.
|
|
# Guessing paths misses real installs, so discovery reads Steam's own
|
|
# libraryfolders.vdf. These tests build fake Steam trees and check that the
|
|
# discovery finds the Mods folder in each layout.
|
|
#
|
|
# Usage: ./tests/test_install.sh
|
|
|
|
set -uo pipefail
|
|
|
|
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
APPID=799600
|
|
PROFILE=76561198000495479
|
|
|
|
# Sourcing install.sh must define the functions without installing anything.
|
|
source "$REPO_DIR/install.sh"
|
|
|
|
failures=0
|
|
tmp_root="$(mktemp -d)"
|
|
trap 'rm -rf "$tmp_root"' EXIT
|
|
|
|
check() {
|
|
# check <name> <expected> <actual>
|
|
if [ "$2" = "$3" ]; then
|
|
echo "PASS: $1"
|
|
else
|
|
echo "FAIL: $1"
|
|
echo " expected: $2"
|
|
echo " actual: $3"
|
|
failures=$((failures + 1))
|
|
fi
|
|
}
|
|
|
|
# Builds a Steam client dir at <root>/.local/share/Steam whose
|
|
# libraryfolders.vdf lists every library path passed after the root.
|
|
make_steam_home() {
|
|
local home="$1"
|
|
shift
|
|
local vdf="$home/.local/share/Steam/steamapps/libraryfolders.vdf"
|
|
mkdir -p "$(dirname "$vdf")"
|
|
{
|
|
echo '"libraryfolders"'
|
|
echo '{'
|
|
local i=0
|
|
for lib in "$@"; do
|
|
printf '\t"%s"\n\t{\n\t\t"path"\t\t"%s"\n\t}\n' "$i" "$lib"
|
|
i=$((i + 1))
|
|
done
|
|
echo '}'
|
|
} >"$vdf"
|
|
}
|
|
|
|
# Creates the Proton-prefix Mods folder for Cosmoteer inside a library root.
|
|
make_proton_mods() {
|
|
local lib="$1"
|
|
local mods="$lib/steamapps/compatdata/$APPID/pfx/drive_c/users/steamuser/Saved Games/Cosmoteer/$PROFILE/Mods"
|
|
mkdir -p "$mods"
|
|
printf '%s\n' "$mods"
|
|
}
|
|
|
|
# 1. The game lives in a secondary library on another disk, which is the case
|
|
# whenever Steam is told to install to a second drive.
|
|
case1="$tmp_root/case1"
|
|
mkdir -p "$case1/home"
|
|
lib="$case1/disk2/steamapps"
|
|
make_steam_home "$case1/home" "$case1/home/.local/share/Steam" "$lib"
|
|
expected="$(make_proton_mods "$lib")"
|
|
actual="$(HOME="$case1/home" find_mods_dir)"
|
|
check "finds Mods in a secondary library from libraryfolders.vdf" "$expected" "$actual"
|
|
|
|
# 2. The game lives in the default library inside the Steam client dir.
|
|
case2="$tmp_root/case2"
|
|
mkdir -p "$case2/home"
|
|
make_steam_home "$case2/home" "$case2/home/.local/share/Steam"
|
|
expected="$(make_proton_mods "$case2/home/.local/share/Steam")"
|
|
actual="$(HOME="$case2/home" find_mods_dir)"
|
|
check "finds Mods in the default Steam library" "$expected" "$actual"
|
|
|
|
# 3. Library paths may contain spaces, so discovery must not word-split them.
|
|
case3="$tmp_root/case3"
|
|
mkdir -p "$case3/home"
|
|
lib="$case3/my games/steamapps"
|
|
make_steam_home "$case3/home" "$case3/home/.local/share/Steam" "$lib"
|
|
expected="$(make_proton_mods "$lib")"
|
|
actual="$(HOME="$case3/home" find_mods_dir)"
|
|
check "finds Mods under a library path containing spaces" "$expected" "$actual"
|
|
|
|
# 4. A Windows-style profile in the user's home, for a non-Proton install.
|
|
case4="$tmp_root/case4"
|
|
mkdir -p "$case4/home/Saved Games/Cosmoteer/$PROFILE/Mods"
|
|
expected="$case4/home/Saved Games/Cosmoteer/$PROFILE/Mods"
|
|
actual="$(HOME="$case4/home" find_mods_dir)"
|
|
check "finds Mods in the home Saved Games folder" "$expected" "$actual"
|
|
|
|
# 5. Nothing installed at all: discovery reports failure instead of guessing.
|
|
case5="$tmp_root/case5"
|
|
mkdir -p "$case5/home"
|
|
actual="$(HOME="$case5/home" find_mods_dir)"
|
|
status=$?
|
|
check "reports no Mods folder when there is no install" "" "$actual"
|
|
check "exits non-zero when there is no install" "1" "$status"
|
|
|
|
# 6. COSMOTEER_MODS_DIR overrides discovery, so an unusual install can be
|
|
# pointed at by hand.
|
|
case6="$tmp_root/case6"
|
|
mkdir -p "$case6/elsewhere/Mods"
|
|
make_steam_home "$case6/home" "$case6/home/.local/share/Steam"
|
|
make_proton_mods "$case6/home/.local/share/Steam" >/dev/null
|
|
actual="$(HOME="$case6/home" COSMOTEER_MODS_DIR="$case6/elsewhere/Mods" resolve_mods_dir)"
|
|
check "COSMOTEER_MODS_DIR overrides discovery" "$case6/elsewhere/Mods" "$actual"
|
|
|
|
echo
|
|
if [ "$failures" -eq 0 ]; then
|
|
echo "All install.sh discovery tests passed."
|
|
else
|
|
echo "$failures test(s) failed."
|
|
exit 1
|
|
fi
|