Files
cthulhu/tests/test_arch_pkgbuild_optional_wine.py

148 lines
6.4 KiB
Python

import re
import unittest
from pathlib import Path
class ArchPkgbuildOptionalWineTests(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
repository = Path(__file__).resolve().parents[1]
cls.repository = repository
versionContents = (
repository / "src" / "cthulhu" / "cthulhuVersion.py"
).read_text(encoding="utf-8")
versionMatch = re.search(r'(?m)^version = "([^"]+)"$', versionContents)
if versionMatch is None:
raise AssertionError("Unable to read the current Cthulhu version")
cls.releaseVersion = versionMatch.group(1)
cls.pkgbuilds = [
repository / "distro-packages" / "Arch-Linux" / name / "PKGBUILD"
for name in ("cthulhu", "cthulhu-git")
]
cls.helperPkgbuilds = [
repository / "distro-packages" / "Arch-Linux" / name / "PKGBUILD"
for name in ("cthulhu-wine-access", "cthulhu-wine-access-git")
]
@staticmethod
def _array_contents(contents: str, arrayName: str) -> str:
return contents.split(f"{arrayName}=(", 1)[1].split(")", 1)[0]
def test_main_packages_disable_wine_helper_build(self) -> None:
for pkgbuild in self.pkgbuilds:
with self.subTest(pkgbuild=pkgbuild):
contents = pkgbuild.read_text(encoding="utf-8")
self.assertIn("-Dwine-access=disabled", contents)
def test_main_packages_do_not_depend_on_wine(self) -> None:
for pkgbuild in self.pkgbuilds:
with self.subTest(pkgbuild=pkgbuild):
contents = pkgbuild.read_text(encoding="utf-8")
dependencySection = contents.split("source=(", 1)[0]
dependencyLines = {
line.strip().strip("'")
for line in dependencySection.splitlines()
if line.strip() and not line.lstrip().startswith("#")
}
self.assertNotIn("wine", dependencyLines)
def test_main_packages_advertise_interchangeable_optional_helper(self) -> None:
helperDescription = (
"'cthulhu-wine-access: Wine, Proton, NVDA Controller, and Tolk integration'"
)
for pkgbuild in self.pkgbuilds:
with self.subTest(pkgbuild=pkgbuild):
contents = pkgbuild.read_text(encoding="utf-8")
self.assertIn(
helperDescription,
self._array_contents(contents, "optdepends_x86_64"),
)
self.assertNotIn(
"cthulhu-wine-access",
self._array_contents(contents, "optdepends"),
)
def test_stable_packages_use_current_release_version(self) -> None:
for pkgbuild in (self.pkgbuilds[0], self.helperPkgbuilds[0]):
with self.subTest(pkgbuild=pkgbuild):
contents = pkgbuild.read_text(encoding="utf-8")
self.assertRegex(
contents,
rf"(?m)^pkgver={re.escape(self.releaseVersion)}$",
)
def test_release_metadata_uses_current_release_version(self) -> None:
mesonContents = (self.repository / "meson.build").read_text(encoding="utf-8")
self.assertRegex(
mesonContents,
rf"(?m)^ version: '{re.escape(self.releaseVersion)}(?:-[^']+)?',$",
)
expectedSlackwareVersion = f"VERSION=${{VERSION:-{self.releaseVersion}}}"
for relativePath in (
("distro-packages", "Slackware", "cthulhu.SlackBuild"),
("distro-packages", "Slint", "cthulhu.SlackBuild"),
):
with self.subTest(relativePath=relativePath):
contents = self.repository.joinpath(*relativePath).read_text(
encoding="utf-8"
)
self.assertIn(expectedSlackwareVersion, contents)
slintInfo = (
self.repository / "distro-packages" / "Slint" / "cthulhu-info"
).read_text(encoding="utf-8")
self.assertRegex(
slintInfo,
rf'(?m)^VERSION="{re.escape(self.releaseVersion)}"$',
)
def test_stable_helper_has_release_contract(self) -> None:
contents = self.helperPkgbuilds[0].read_text(encoding="utf-8")
self.assertRegex(contents, r"(?m)^arch=\(x86_64\)$")
def test_optional_helpers_do_not_depend_on_main_package(self) -> None:
for pkgbuild in self.helperPkgbuilds:
with self.subTest(pkgbuild=pkgbuild):
contents = pkgbuild.read_text(encoding="utf-8")
dependencies = self._array_contents(contents, "depends")
self.assertNotRegex(
dependencies,
r"(?m)^\s*['\"]?cthulhu(?:-git)?(?:[<>=].*)?['\"]?\s*$",
)
def test_git_helper_provides_stable_helper_name(self) -> None:
contents = self.helperPkgbuilds[1].read_text(encoding="utf-8")
self.assertRegex(contents, r"(?m)^provides=\(cthulhu-wine-access\)$")
self.assertRegex(contents, r"(?m)^conflicts=\(cthulhu-wine-access\)$")
def test_optional_helper_packages_build_only_the_helper(self) -> None:
for pkgbuild in self.helperPkgbuilds:
with self.subTest(pkgbuild=pkgbuild):
contents = pkgbuild.read_text(encoding="utf-8")
self.assertIn('/scripts/build-wine-access.sh"', contents)
self.assertNotIn("arch-meson", contents)
self.assertRegex(contents, r"(?m)^ wine$")
makeDependencies = self._array_contents(contents, "makedepends")
self.assertNotRegex(makeDependencies, r"(?m)^\s*meson\s*$")
def test_optional_helper_packages_disable_lto(self) -> None:
for pkgbuild in self.helperPkgbuilds:
with self.subTest(pkgbuild=pkgbuild):
contents = pkgbuild.read_text(encoding="utf-8")
self.assertRegex(contents, r"(?m)^options=\(!lto\)$")
def test_git_sources_declare_git_as_a_build_dependency(self) -> None:
for pkgbuild in self.pkgbuilds + self.helperPkgbuilds:
with self.subTest(pkgbuild=pkgbuild):
contents = pkgbuild.read_text(encoding="utf-8")
self.assertIn("git+", contents)
makeDependencies = contents.split("makedepends=(", 1)[1].split(
")", 1
)[0]
self.assertRegex(makeDependencies, r"(?m)^ git$")
if __name__ == "__main__":
unittest.main()