Files
omarchy/test/shell.d/pkg-add-test.sh
T

40 lines
1.3 KiB
Bash

#!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
mock_path="$test_tmp/bin"
mkdir -p "$mock_path"
cat >"$mock_path/pacman" <<'MOCK'
#!/bin/bash
if [[ $1 == "-Q" ]]; then
[[ " $TEST_INSTALLED " == *" $3 "* ]]
exit
fi
printf '%s\n' "$*" >>"$TEST_TMP/pacman-sync"
for arg in "$@"; do
[[ $arg == -* ]] || TEST_INSTALLED+=" $arg"
done
printf '%s\n' "$TEST_INSTALLED" >"$TEST_TMP/installed"
MOCK
cat >"$mock_path/sudo" <<'MOCK'
#!/bin/bash
exec "$@"
MOCK
chmod +x "$mock_path"/*
export PATH="$mock_path:$ROOT/bin:$PATH" TEST_TMP="$test_tmp"
TEST_INSTALLED="local-only fcitx5" "$ROOT/bin/omarchy-pkg-add" fcitx5-rime local-only opencc >/dev/null 2>&1 || true
[[ $(<"$test_tmp/pacman-sync") == "-S --noconfirm --needed -- fcitx5-rime opencc" ]] ||
fail "pkg-add asks pacman only for the missing packages" "$(<"$test_tmp/pacman-sync")"
pass "an installed package from no repository is left out of the pacman -S call"
rm -f "$test_tmp/pacman-sync"
TEST_INSTALLED="local-only fcitx5" "$ROOT/bin/omarchy-pkg-add" local-only fcitx5
[[ ! -e $test_tmp/pacman-sync ]] || fail "pkg-add runs no transaction when nothing is missing" "$(<"$test_tmp/pacman-sync")"
pass "pkg-add runs no transaction when everything is installed"