Ask pacman only for the packages pkg-add finds missing
This commit is contained in:
1 parent
a3e40cb8b0
commit
a77c246d38
2 files changed
+48
-3
No files matched your search
@@ -0,0 +1,39 @@
|
||||
#!/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"
|
||||
Reference in new issue
Block a user