`coredesktop-dev smoketest run --with HamPack` installs HamPack on a VM with CoreDesktop and checks a fresh install, an update with nothing to do, a one-app rebuild, a failing build and hampackremove, with smoketest/health checking every package, Flatpak and app is in place. HAMPACK_SKIP_WINDOWS_APPS skips the Windows installers, which the test VMs' desktop would start with no one to click through them; smoketest/setup sets it in each VM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
3.8 KiB
Bash
109 lines
3.8 KiB
Bash
# Shared setup for HamPack's bats tests. Each test gets a fake $HOME, and
|
|
# commands that would touch the system (sudo, pacman, flatpak, systemctl...) are
|
|
# replaced by stubs that log their arguments to $STUB_LOG.
|
|
|
|
REPO="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
|
|
|
|
setup_fake_home() {
|
|
export HOME="$BATS_TEST_TMPDIR/home"
|
|
export USER="${USER:-tester}"
|
|
export TMPDIR="$BATS_TEST_TMPDIR/tmp"
|
|
export HAMPACK_DIR="$REPO"
|
|
export HAMPACK_STATE="$HOME/.local/state/HamPack"
|
|
export STUB_DIR="$BATS_TEST_TMPDIR/stubs"
|
|
export STUB_LOG="$BATS_TEST_TMPDIR/stub.log"
|
|
# Fake pacman database: one file per installed package; a file containing
|
|
# "dep" means it was installed as a dependency
|
|
export FAKE_PACMAN_DB="$BATS_TEST_TMPDIR/pacman-db"
|
|
export FAKE_FLATPAKS="$BATS_TEST_TMPDIR/flatpaks"
|
|
unset DISPLAY WAYLAND_DISPLAY WINEPREFIX HAMPACK_SKIP_WINDOWS_APPS
|
|
mkdir -p "$HOME/.local/bin" "$TMPDIR" "$STUB_DIR" "$FAKE_PACMAN_DB" "$FAKE_FLATPAKS"
|
|
: > "$STUB_LOG"
|
|
PATH="$STUB_DIR:$PATH"
|
|
|
|
# Commands that just log and succeed
|
|
local cmd
|
|
for cmd in systemctl udevadm groupadd yay update-desktop-database update-mime-database \
|
|
xdg-icon-resource xdg-desktop-menu wine wineboot winetricks xdotool; do
|
|
stub "$cmd" 'exit 0'
|
|
done
|
|
|
|
# sudo runs stubbed commands and only logs the rest, so tests never change the system
|
|
stub sudo '
|
|
case "$1" in -v|-n) exit 0 ;; esac
|
|
if [ -x "$STUB_DIR/$1" ]; then "$@"; else exit 0; fi'
|
|
|
|
stub pacman '
|
|
case "$1" in
|
|
-Qi|-Q|-Qq)
|
|
shift; status=0
|
|
for p in "$@"; do
|
|
if [ -f "$FAKE_PACMAN_DB/$p" ]; then [ "$1" = -Qi ] || echo "$p"; else status=1; fi
|
|
done
|
|
exit $status ;;
|
|
-Qg) exit 1 ;;
|
|
-Qdq)
|
|
shift; for p in "$@"; do grep -qx dep "$FAKE_PACMAN_DB/$p" 2>/dev/null && echo "$p"; done; exit 0 ;;
|
|
-Qdtq)
|
|
for f in "$FAKE_PACMAN_DB"/*; do
|
|
[ -f "$f" ] || continue
|
|
p="$(basename "$f")"
|
|
grep -qx dep "$f" && ! grep -qx "$p" "$FAKE_PACMAN_DB"/.required 2>/dev/null && echo "$p"
|
|
done; exit 0 ;;
|
|
-D)
|
|
mode="$2"; shift 2
|
|
for p in "$@"; do
|
|
if [ "$mode" = --asdeps ]; then echo dep > "$FAKE_PACMAN_DB/$p"; else : > "$FAKE_PACMAN_DB/$p"; fi
|
|
done ;;
|
|
-Rns)
|
|
shift; for p in "$@"; do [ "$p" = --noconfirm ] || rm -f "$FAKE_PACMAN_DB/$p"; done ;;
|
|
esac
|
|
exit 0'
|
|
|
|
stub flatpak '
|
|
case "$1" in
|
|
info) [ -f "$FAKE_FLATPAKS/$2" ] ;;
|
|
install) for p in "$@"; do :; done; touch "$FAKE_FLATPAKS/$p" ;;
|
|
uninstall) for p in "$@"; do rm -f "$FAKE_FLATPAKS/$p"; done ;;
|
|
esac'
|
|
}
|
|
|
|
# Create a stub command: stub NAME BODY. Every call is logged as "NAME ARGS".
|
|
stub() {
|
|
printf '#!/bin/bash\necho "%s $*" >> "$STUB_LOG"\n%s\n' "$1" "$2" > "$STUB_DIR/$1"
|
|
chmod +x "$STUB_DIR/$1"
|
|
}
|
|
|
|
# A minimal CoreDesktop: the utils.sh functions HamPack uses, backed by the fake pacman
|
|
fake_coredesktop() {
|
|
local cd="$HOME/.local/share/coredesktop"
|
|
mkdir -p "$cd"
|
|
printf 'SYSTEM_UTILS=(\n coredesktop-pkg\n)\n' > "$cd/packages.conf"
|
|
cat > "$cd/utils.sh" << 'EOF'
|
|
is_installed() { [ -f "$FAKE_PACMAN_DB/$1" ]; }
|
|
without_skipped() { printf '%s\n' "$@"; }
|
|
install_packages() {
|
|
local p
|
|
for p in "$@"; do
|
|
[ -f "$FAKE_PACMAN_DB/$p" ] || { echo "yay -S $p" >> "$STUB_LOG"; : > "$FAKE_PACMAN_DB/$p"; }
|
|
done
|
|
}
|
|
enable_services() { echo "enable_services $*" >> "$STUB_LOG"; }
|
|
install_script() { cp "$1" "$2" && chmod 755 "$2"; }
|
|
remove_flatpaks() { local p; for p in "$@"; do echo "remove_flatpaks $p" >> "$STUB_LOG"; rm -f "$FAKE_FLATPAKS/$p"; done; }
|
|
EOF
|
|
}
|
|
|
|
mark_installed() {
|
|
local p
|
|
for p in "$@"; do : > "$FAKE_PACMAN_DB/$p"; done
|
|
}
|
|
|
|
# All packages and Flatpaks in packages.conf
|
|
all_hampack_packages() {
|
|
(source "$REPO/packages.conf"; printf '%s\n' "${UTILITIES[@]}" "${APPLICATIONS[@]}")
|
|
}
|
|
all_hampack_flatpaks() {
|
|
(source "$REPO/packages.conf"; printf '%s\n' "${FLATPAKS[@]}")
|
|
}
|