Skip to content

Commit

Permalink
chore(test: helpers, fake_makepkg, test_sysupgrade): now even in down…
Browse files Browse the repository at this point in the history
…grade-related tests try to use even more mocked up makepkg to speed up the tests even further
  • Loading branch information
actionless committed Sep 5, 2024
1 parent 9ae4ed9 commit a489bde
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
44 changes: 33 additions & 11 deletions pikaur_test/fake_makepkg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
# shellcheck disable=SC2016
# shellcheck disable=SC2206

# Licensed under GPLv3, see https://www.gnu.org/licenses/

Expand All @@ -11,6 +12,26 @@ if [[ ! "$(grep pikaur_fake_makepkg_package PKGBUILD)" ]] && [[ ! "$(grep pikau
echo -e "$line {\n echo \"fake_$line\"\n }" >> PKGBUILD
done

filter_arg="--force-version"
forced_version=
args=($*)
new_args=()

echo "Orig args: ${args[*]}"

for arg in "${args[@]}" ; do
if grep -q -- "$filter_arg" <<< "$arg" ; then
forced_version="$(echo "$arg" | cut -d= -f2-999)"
else
new_args+=("$arg")
fi
done

echo "New args: ${new_args[*]}"
if test -n "$forced_version" ; then
echo "Forced version: $forced_version"
fi

source ./PKGBUILD
echo '
Expand All @@ -28,25 +49,26 @@ check() {
echo "======= Fake check() ======="
echo "pikaur_fake_makepkg_check"
}
source=(
"http://example.com"
)
b2sums=(
"SKIP"
)
' >> ./PKGBUILD

if echo "$@" | grep -q "noprogressbar" ; then
true
else

if grep -q "git" <<< "$pkgname" ; then
echo '
pkgver() {
echo 99999.1.2.3
echo '"${forced_version:-99999.1.2.3}"'
}
source=(
"http://example.com"
)
b2sums=(
"SKIP"
)
' >> ./PKGBUILD
fi


# shellcheck disable=SC2154
if [ "${#pkgname[@]}" -eq 1 ] ; then
echo "
Expand All @@ -69,4 +91,4 @@ fi

fi
# shellcheck disable=SC2068
/usr/bin/makepkg $@
/usr/bin/makepkg "${new_args[@]}"
18 changes: 9 additions & 9 deletions pikaur_test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def pikaur(
print_on_fails: bool = True,
fake_makepkg: bool = False,
fake_makepkg_noextract: bool = True,
fake_makepkg_download: bool = False,
fake_makepkg_version: str | None = None,
) -> CmdResult:

PackageDB.discard_local_cache()
Expand All @@ -207,8 +207,8 @@ def pikaur(
]
if fake_makepkg_noextract:
mflags.append("--noextract")
if fake_makepkg_download:
mflags.append("--noprogressbar")
if fake_makepkg_version:
mflags.append(f"--force-version={fake_makepkg_version}")
if skippgpcheck or fake_makepkg:
mflags.append("--skippgpcheck")
if "--mflags" in cmd:
Expand Down Expand Up @@ -259,8 +259,8 @@ def pikaur(
return result


def fake_pikaur(cmd_args: str, *, download: bool = False, **kwargs: "Any") -> CmdResult:
return pikaur(cmd_args, fake_makepkg=True, fake_makepkg_download=download, **kwargs)
def fake_pikaur(cmd_args: str, **kwargs: "Any") -> CmdResult:
return pikaur(cmd_args, fake_makepkg=True, **kwargs)


def pacman(cmd: str) -> CmdResult:
Expand Down Expand Up @@ -389,7 +389,7 @@ def downgrade_repo_pkg(
repo_pkg_name: str,
*,
fake_makepkg: bool = False,
fake_makepkg_download: bool = False,
fake_makepkg_version: str | None = None,
skippgpcheck: bool = False,
count: int = 10,
build_root: str = ".",
Expand All @@ -413,7 +413,7 @@ def downgrade_repo_pkg(
"-P -i --noconfirm "
f"{build_dir}/PKGBUILD",
fake_makepkg=fake_makepkg,
fake_makepkg_download=fake_makepkg_download,
fake_makepkg_version=fake_makepkg_version,
skippgpcheck=skippgpcheck,
)
self.assertInstalled(repo_pkg_name)
Expand All @@ -423,7 +423,7 @@ def downgrade_aur_pkg(
self, aur_pkg_name: str,
*,
fake_makepkg: bool = False,
fake_makepkg_download: bool = False,
fake_makepkg_version: str | None = None,
skippgpcheck: bool = False,
count: int = 1,
build_root: str = ".",
Expand Down Expand Up @@ -452,7 +452,7 @@ def downgrade_aur_pkg(
"-P -i --noconfirm "
f"{build_dir}/PKGBUILD",
fake_makepkg=fake_makepkg,
fake_makepkg_download=fake_makepkg_download,
fake_makepkg_version=fake_makepkg_version,
skippgpcheck=skippgpcheck,
)
self.assertInstalled(aur_pkg_name)
Expand Down
2 changes: 1 addition & 1 deletion pikaur_test/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_explicit_pkgs_not_becoming_deps(self):

self.remove_if_installed(aur_pkg_name, explicitly_installed_dep_name)
explicitly_installed_dep_old_version = self.downgrade_aur_pkg(
explicitly_installed_dep_name, fake_makepkg=True, fake_makepkg_download=True,
explicitly_installed_dep_name, fake_makepkg=True, fake_makepkg_version="888.8.8",
)
self.assertInstalled(explicitly_installed_dep_name)
self.assertEqual(
Expand Down
10 changes: 5 additions & 5 deletions pikaur_test/test_sysupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,29 @@ def setUp(self):
def downgrade_repo1_pkg(self) -> None:
self.repo_old_version = self.downgrade_repo_pkg(
self.repo_pkg_name,
fake_makepkg=True, fake_makepkg_download=True,
fake_makepkg=True, fake_makepkg_version="888.8.8",
)

def downgrade_repo2_pkg(self) -> None:
self.repo2_old_version = self.downgrade_repo_pkg(
self.repo2_pkg_name,
count=2,
fake_makepkg=True, fake_makepkg_download=True,
fake_makepkg=True, fake_makepkg_version="888.8.8",
)

def downgrade_aur1_pkg(self) -> None:
self.aur_old_version = self.downgrade_aur_pkg(
self.aur_pkg_name,
count=2,
skippgpcheck=True,
fake_makepkg=True, fake_makepkg_download=True,
fake_makepkg=True, fake_makepkg_version="888.8.8",
)

def downgrade_aur2_pkg(self) -> None:
self.aur2_old_version = self.downgrade_aur_pkg(
self.aur2_pkg_name,
count=3,
fake_makepkg=True, fake_makepkg_download=True,
fake_makepkg=True, fake_makepkg_version="888.8.8",
)

def downgrade_dev_pkg(self) -> None:
Expand All @@ -83,7 +83,7 @@ def downgrade_dev_pkg(self) -> None:
])
pikaur(
f"-P -i --noconfirm ./{self.dev_pkg_name}/PKGBUILD_prev --print-commands",
fake_makepkg=True, fake_makepkg_noextract=False, fake_makepkg_download=True,
fake_makepkg=True, fake_makepkg_noextract=False, fake_makepkg_version="888.8.8",
)
self.assertInstalled(self.dev_pkg_name)
self.dev_old_version = PackageDB.get_local_dict()[self.dev_pkg_name].version
Expand Down

0 comments on commit a489bde

Please sign in to comment.