From cf6cd0231f90be3f56913c585b8f60702da21289 Mon Sep 17 00:00:00 2001 From: Kevin Daudt Date: Mon, 11 Jan 2021 21:54:56 +0100 Subject: [PATCH] tests: verify subpkg dependencies don't influence main package Subpackages can declare their own dependencies, but these should not affect the main package. Add a test that verifies this behaviour. --- tests/abuild.bats | 23 ++++++++++++++- tests/helpers.bash | 15 ++++++++++ tests/testrepo/subpkg-dep-leak/APKBUILD | 29 +++++++++++++++++++ .../subpkg-dep-leak/main_dependencies | 2 ++ .../subpkg-dep-leak/subpkg_dependencies | 1 + 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/helpers.bash create mode 100644 tests/testrepo/subpkg-dep-leak/APKBUILD create mode 100644 tests/testrepo/subpkg-dep-leak/main_dependencies create mode 100644 tests/testrepo/subpkg-dep-leak/subpkg_dependencies diff --git a/tests/abuild.bats b/tests/abuild.bats index b3dd3ea..567c044 100644 --- a/tests/abuild.bats +++ b/tests/abuild.bats @@ -1,17 +1,25 @@ +load helpers + setup() { export ABUILD="$PWD/../abuild" export ABUILD_SHAREDIR="$PWD/.." export ABUILD_CONF=/dev/null tmpdir="$BATS_TMPDIR"/abuild export REPODEST="$tmpdir"/packages - mkdir -p $tmpdir export CLEANUP="srcdir bldroot pkgdir deps" + export WORKDIR="$tmpdir"/work + + mkdir -p "$tmpdir" "$WORKDIR" } teardown() { rm -rf "$tmpdir" } +build_repo() { + : +} + @test "abuild: help text" { $ABUILD -h } @@ -128,3 +136,16 @@ teardown() { run $ABUILD sanitycheck [[ $output[1] == *WARNING*dbg* ]] } + +@test "abuild: verify main package does not inherit subpackage dependencies" { + cd testrepo/subpkg-dep-leak/ + + $ABUILD + + pkg_field subpkg-dep-leak-1.0-r0 depend >"$WORKDIR"/actual_main_dependencies + pkg_field subpkg-dep-leak-subpkg-1.0-r0 depend >"$WORKDIR"/actual_subpkg_dependencies + + diff main_dependencies "$WORKDIR"/actual_main_dependencies + diff subpkg_dependencies "$WORKDIR"/actual_subpkg_dependencies + false +} diff --git a/tests/helpers.bash b/tests/helpers.bash new file mode 100644 index 0000000..01607a0 --- /dev/null +++ b/tests/helpers.bash @@ -0,0 +1,15 @@ +pkg_field() { + local pkg=$1 + local field=$2 + + tar xzf "$REPODEST"/testrepo/"$(arch)"/"$pkg".apk -O .PKGINFO | + awk "/^$field =/ { print \$3 }" | + sort +} + +has_dependency() { + local pkg=$1 + local dependency=$2 + + pkg_field "$pkg" depend | grep -qx "$dependency" +} diff --git a/tests/testrepo/subpkg-dep-leak/APKBUILD b/tests/testrepo/subpkg-dep-leak/APKBUILD new file mode 100644 index 0000000..43ba3ec --- /dev/null +++ b/tests/testrepo/subpkg-dep-leak/APKBUILD @@ -0,0 +1,29 @@ +# Maintainer: Natanael Copa + +# test package +pkgname="subpkg-dep-leak" +pkgver="1.0" +pkgrel=0 +pkgdesc="Dummy test package with subpackages and dependencies" +url="https://gitlab.alpinelinux.org/alpine/aports" +arch="noarch" +depends="tar scanelf" +license="MIT" +subpackages="$pkgname-subpkg" + +prepare() { + mkdir -p "$builddir" +} + +check() { + true +} + +package() { + mkdir -p "$pkgdir" +} + +subpkg() { + depends="sed" + mkdir -p "$subpkgdir" +} diff --git a/tests/testrepo/subpkg-dep-leak/main_dependencies b/tests/testrepo/subpkg-dep-leak/main_dependencies new file mode 100644 index 0000000..09ad1be --- /dev/null +++ b/tests/testrepo/subpkg-dep-leak/main_dependencies @@ -0,0 +1,2 @@ +scanelf +tar diff --git a/tests/testrepo/subpkg-dep-leak/subpkg_dependencies b/tests/testrepo/subpkg-dep-leak/subpkg_dependencies new file mode 100644 index 0000000..5a12022 --- /dev/null +++ b/tests/testrepo/subpkg-dep-leak/subpkg_dependencies @@ -0,0 +1 @@ +sed