From a489bde6f89e16b57b470535f7a4251acd7dfaf7 Mon Sep 17 00:00:00 2001 From: actionless Date: Thu, 5 Sep 2024 02:13:02 +0200 Subject: [PATCH] chore(test: helpers, fake_makepkg, test_sysupgrade): now even in downgrade-related tests try to use even more mocked up makepkg to speed up the tests even further --- pikaur_test/fake_makepkg | 44 ++++++++++++++++++++++++--------- pikaur_test/helpers.py | 18 +++++++------- pikaur_test/test_regressions.py | 2 +- pikaur_test/test_sysupgrade.py | 10 ++++---- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/pikaur_test/fake_makepkg b/pikaur_test/fake_makepkg index 377717756..960cc0ba7 100755 --- a/pikaur_test/fake_makepkg +++ b/pikaur_test/fake_makepkg @@ -1,5 +1,6 @@ #!/bin/bash # shellcheck disable=SC2016 +# shellcheck disable=SC2206 # Licensed under GPLv3, see https://www.gnu.org/licenses/ @@ -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 ' @@ -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 " @@ -69,4 +91,4 @@ fi fi # shellcheck disable=SC2068 -/usr/bin/makepkg $@ +/usr/bin/makepkg "${new_args[@]}" diff --git a/pikaur_test/helpers.py b/pikaur_test/helpers.py index 954b8a853..ea890b05f 100644 --- a/pikaur_test/helpers.py +++ b/pikaur_test/helpers.py @@ -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() @@ -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: @@ -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: @@ -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 = ".", @@ -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) @@ -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 = ".", @@ -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) diff --git a/pikaur_test/test_regressions.py b/pikaur_test/test_regressions.py index 1c4a3a67d..4c1aa1c27 100644 --- a/pikaur_test/test_regressions.py +++ b/pikaur_test/test_regressions.py @@ -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( diff --git a/pikaur_test/test_sysupgrade.py b/pikaur_test/test_sysupgrade.py index a75782150..50e641184 100644 --- a/pikaur_test/test_sysupgrade.py +++ b/pikaur_test/test_sysupgrade.py @@ -40,14 +40,14 @@ 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: @@ -55,14 +55,14 @@ def downgrade_aur1_pkg(self) -> None: 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: @@ -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