From 64cb213213b97e51c57a6b7df24cff99ccc3b28e Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 19 May 2024 20:06:16 +0200 Subject: [PATCH] tests: add some tests for makepkg This adds some git source related regression tests for #142 and #143. Creates temporary git repos and PKGBUILDs and builds packages. This requires git to be available and since makepkg refuses to be run as root, the tests fail if run as root. --- meson.build | 1 + test/makepkg/makepkg-build-git-head-twice.sh | 48 ++++++++++++++++ .../makepkg-checkout-dir-matches-branch.sh | 57 +++++++++++++++++++ test/makepkg/meson.build | 9 +++ 4 files changed, 115 insertions(+) create mode 100644 test/makepkg/makepkg-build-git-head-twice.sh create mode 100644 test/makepkg/makepkg-checkout-dir-matches-branch.sh create mode 100644 test/makepkg/meson.build diff --git a/meson.build b/meson.build index bc2ef468..4bf1ef41 100644 --- a/meson.build +++ b/meson.build @@ -458,6 +458,7 @@ TEST_ENV.set('PMTEST_SCRIPT_DIR', join_paths(meson.project_build_root(), 'script subdir('test/pacman') subdir('test/scripts') subdir('test/util') +subdir('test/makepkg') message('\n '.join([ '@0@ @1@'.format(meson.project_name(), meson.project_version()), diff --git a/test/makepkg/makepkg-build-git-head-twice.sh b/test/makepkg/makepkg-build-git-head-twice.sh new file mode 100644 index 00000000..1afada83 --- /dev/null +++ b/test/makepkg/makepkg-build-git-head-twice.sh @@ -0,0 +1,48 @@ +#!/usr/bin/bash + +set -e + +tempdir=$(mktemp -d) +cleanup() { rm -rf "$tempdir"; } +trap cleanup EXIT + +export MAKEPKG_LIBRARY="${PMTEST_LIBMAKEPKG_DIR}" +export MAKEPKG_CONF="${PMTEST_UTIL_DIR}/makepkg.conf" +export PACMAN="${PMTEST_UTIL_DIR}/pacman" +MAKEPKG="${PMTEST_SCRIPT_DIR}/makepkg" + +# https://gitlab.archlinux.org/pacman/pacman/-/issues/142 +# Running makepkg twice if the source is git without a fragment +# should not fail. +test() { + # Dummy git repo + export GIT_COMMITTER_NAME="Test User" + export GIT_COMMITTER_EMAIL="test@example.com" + export GIT_AUTHOR_NAME="$GIT_COMMITTER_NAME" + export GIT_AUTHOR_EMAIL="$GIT_COMMITTER_EMAIL" + local gitrepo="$tempdir/gitrepo" + mkdir -p $gitrepo && cd $gitrepo + git init . + git checkout -b main + git commit --allow-empty -m "test" + + # Dummy PKGBUILD + local pkgbuild_content=$(cat < "PKGBUILD" + + "$MAKEPKG" + "$MAKEPKG" -f +} + +test; diff --git a/test/makepkg/makepkg-checkout-dir-matches-branch.sh b/test/makepkg/makepkg-checkout-dir-matches-branch.sh new file mode 100644 index 00000000..47024d0a --- /dev/null +++ b/test/makepkg/makepkg-checkout-dir-matches-branch.sh @@ -0,0 +1,57 @@ +#!/usr/bin/bash + +set -e + +tempdir=$(mktemp -d) +cleanup() { rm -rf "$tempdir"; } +trap cleanup EXIT + +export MAKEPKG_LIBRARY="${PMTEST_LIBMAKEPKG_DIR}" +export MAKEPKG_CONF="${PMTEST_UTIL_DIR}/makepkg.conf" +export PACMAN="${PMTEST_UTIL_DIR}/pacman" +MAKEPKG="${PMTEST_SCRIPT_DIR}/makepkg" + +# https://gitlab.archlinux.org/pacman/pacman/-/issues/143 +# Always check out the default branch, and not a branch matching +# the directory name. +test() { + # Dummy git repo + export GIT_COMMITTER_NAME="Test User" + export GIT_COMMITTER_EMAIL="test@example.com" + export GIT_AUTHOR_NAME="$GIT_COMMITTER_NAME" + export GIT_AUTHOR_EMAIL="$GIT_COMMITTER_EMAIL" + + local gitrepo="$tempdir/gitrepo" + mkdir -p $gitrepo && cd $gitrepo + git init --initial-branch=main + git checkout -b main + touch good + git add good + git commit -m "good" + git checkout -b somebranch + git rm good + git commit -m "bad" + git checkout main + + # Dummy PKGBUILD + local pkgbuild_content=$(cat < "PKGBUILD" + + "$MAKEPKG" +} + +test; diff --git a/test/makepkg/meson.build b/test/makepkg/meson.build new file mode 100644 index 00000000..7ab1058c --- /dev/null +++ b/test/makepkg/meson.build @@ -0,0 +1,9 @@ +find_program('git', required: true) + +test('makepkg-build-git-head-twice', + find_program('makepkg-build-git-head-twice.sh'), + env: TEST_ENV) + +test('makepkg-checkout-dir-matches-branch', + find_program('makepkg-checkout-dir-matches-branch.sh'), + env: TEST_ENV)