aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorMattia Rizzolo <mattia@mapreri.org>2015-10-13 10:26:06 +0000
committerMattia Rizzolo <mattia@mapreri.org>2015-10-13 10:26:06 +0000
commit72075b8430b826d7dd489765c1004e4161479fa2 (patch)
tree682a8d69bcc478082f1805859eb72445e8b6cf42 /t
parent524cde2e544f40dc2056d2a4c4265ddc4160784d (diff)
downloadpbuilder-72075b8430b826d7dd489765c1004e4161479fa2.tar
pbuilder-72075b8430b826d7dd489765c1004e4161479fa2.tar.gz
move all tests under a t/ directory
Diffstat (limited to 't')
-rwxr-xr-xt/test_pbuilder-apt-config183
-rwxr-xr-xt/test_pbuilder-buildpackage-funcs137
-rwxr-xr-xt/test_pbuilder-checkparams34
-rwxr-xr-xt/test_pbuilder-modules44
-rwxr-xr-xt/test_pbuilder-satisfydepends-checkparams51
-rwxr-xr-xt/test_pbuilder-satisfydepends-classic116
-rwxr-xr-xt/test_pbuilder-satisfydepends-funcs202
-rwxr-xr-xt/test_testlib.sh34
-rw-r--r--t/testlib.sh158
9 files changed, 959 insertions, 0 deletions
diff --git a/t/test_pbuilder-apt-config b/t/test_pbuilder-apt-config
new file mode 100755
index 0000000..e00730e
--- /dev/null
+++ b/t/test_pbuilder-apt-config
@@ -0,0 +1,183 @@
+#!/bin/bash
+
+set -e
+
+self="$(basename "$0")"
+
+TD="$(dirname "$0")"
+if [ -n "$PBUILDER_CHECKOUT" ]; then
+ . "$TD/testlib.sh"
+ PBUILDER_APT_CONFIG="$PBUILDER_CHECKOUT/pbuilder-apt-config"
+else
+ . "$TD/testlib.sh"
+ PBUILDER_APT_CONFIG="$PBUILDER_TEST_PKGLIBDIR/pbuilder-apt-config"
+fi
+
+mirror_map=""
+
+cleanup() {
+ if [ -n "$mirror_map" ]; then
+ rm -f "$mirror_map"
+ fi
+}
+
+mirror_map="$(mktemp -t "$self.XXXXXXXXXX")"
+cat >"$mirror_map" <<EOF
+archive archive-mirror
+ubuntu ubuntu-mirror
+ubuntu-ports ubuntu-ports-mirror
+ubuntu-security ubuntu-security-mirror
+nomirror
+
+ppa:people ppa-people-ppa
+ppa:people/otherppa ppa-people-otherppa
+
+# no mirror
+debian-archive
+EOF
+
+run_suite_mode() {
+ "$PBUILDER_APT_CONFIG" --mirror-map="$mirror_map" --with-sources=no --mirror mirror --suite hamm --components component apt-sources "$@"
+}
+
+debootstrap_suite() {
+ "$PBUILDER_APT_CONFIG" --mirror-map="$mirror_map" --with-sources=no --mirror mirror --components component debootstrap-suite "$@"
+}
+
+debootstrap_mirror() {
+ "$PBUILDER_APT_CONFIG" --mirror-map="$mirror_map" --with-sources=no --components component debootstrap-mirror "$@"
+}
+
+test_components() {
+ run_suite_mode --components comp1
+ run_suite_mode --components comp1,comp2,comp3
+ run_suite_mode --components "comp1 comp2 comp3"
+}
+
+test_pockets() {
+ run_suite_mode --pockets ""
+ echo
+ run_suite_mode --pockets pocket1
+ echo
+ run_suite_mode --pockets pocket1,pocket2,pocket3
+ echo
+ run_suite_mode --pockets "pocket1 pocket2 pocket3"
+}
+
+strip_mirror() {
+ local deb mirror eol
+
+ while read deb mirror eol; do
+ echo "$deb $eol"
+ done
+}
+
+test_profile() {
+ local profile="$1"
+ "$PBUILDER_APT_CONFIG" --with-sources=no --profile "$profile" --components comp1 apt-sources | strip_mirror
+}
+
+test_fail() {
+ exit 1
+}
+
+test_options() {
+ echo "$@"
+ exit 1
+}
+
+expect_output "deb mirror hamm component" run_suite_mode --suite hamm
+
+expect_output "deb archive-mirror hamm component" run_suite_mode --mirror "" --archive archive
+expect_fail run_suite_mode --mirror "" --archive nomirror
+expect_output "deb http://archive.debian.org/debian/ bo component" run_suite_mode --mirror "" --suite bo
+
+expect_output "deb ubuntu-mirror lucid component" run_suite_mode --mirror "" --suite lucid --arch i386
+expect_output "deb ubuntu-ports-mirror lucid component" run_suite_mode --mirror "" --suite lucid --arch armel
+
+expect_output "deb mirror hamm comp1
+deb mirror hamm comp1 comp2 comp3
+deb mirror hamm comp1 comp2 comp3" test_components
+
+expect_output "deb mirror hamm component
+
+deb mirror hamm component
+deb mirror hamm-pocket1 component
+
+deb mirror hamm component
+deb mirror hamm-pocket1 component
+deb mirror hamm-pocket2 component
+deb mirror hamm-pocket3 component
+
+deb mirror hamm component
+deb mirror hamm-pocket1 component
+deb mirror hamm-pocket2 component
+deb mirror hamm-pocket3 component" test_pockets
+
+expect_output "deb unstable comp1" test_profile unstable
+expect_output "deb sid comp1" test_profile sid
+expect_output "deb unstable comp1
+deb experimental comp1" test_profile experimental
+expect_output "deb squeeze comp1
+deb squeeze/updates comp1" test_profile squeeze/updates
+expect_output "deb squeeze comp1
+deb squeeze-proposed-updates comp1" test_profile squeeze-proposed-updates
+expect_output "deb squeeze comp1
+deb squeeze-backports comp1" test_profile squeeze-backports
+expect_output "deb squeeze comp1
+deb squeeze/volatile comp1" test_profile squeeze/volatile
+expect_output "deb squeeze comp1
+deb squeeze/volatile comp1
+deb squeeze/volatile-sloppy comp1" test_profile squeeze/volatile-sloppy
+expect_output "deb squeeze comp1
+deb squeeze/volatile comp1
+deb squeeze-proposed-updates/volatile comp1" test_profile squeeze-proposed-updates/volatile
+expect_output "deb bo comp1" test_profile bo
+
+expect_output "deb lucid comp1" test_profile lucid
+expect_output "deb lucid comp1
+deb lucid-security comp1
+deb lucid-security comp1" test_profile lucid-security
+expect_output "deb lucid comp1
+deb lucid-security comp1
+deb lucid-updates comp1
+deb lucid-security comp1" test_profile lucid-updates
+expect_output "deb lucid comp1
+deb lucid-security comp1
+deb lucid-updates comp1
+deb lucid-backports comp1
+deb lucid-security comp1" test_profile lucid-backports
+expect_output "deb lucid comp1
+deb lucid-security comp1
+deb lucid-updates comp1
+deb lucid-proposed comp1
+deb lucid-security comp1" test_profile lucid-proposed
+
+expect_output "deb mirror hamm component
+deb-src mirror hamm component" run_suite_mode --with-sources=yes
+expect_output "deb mirror hamm component
+deb-src mirror hamm component" run_suite_mode --with-sources=
+expect_output "deb mirror hamm component
+#deb-src mirror hamm component" run_suite_mode --with-sources=disabled
+expect_output "deb mirror hamm component" run_suite_mode --with-sources=no
+
+expect_output "deb ubuntu-mirror hamm component" run_suite_mode --mirror "" --archive ubuntu
+expect_output "deb ubuntu-ports-mirror hamm component" run_suite_mode --arch armel --mirror "" --archive ubuntu-ports
+expect_fail run_hamm_mode --arch armel --mirror "" --archive otherarchive
+expect_success run_suite_mode --mirror "" --suite lucid
+expect_fail run_suite_mode --mirror "" --suite suite
+expect_success run_suite_mode --mirror "" --suite suite --archive ubuntu
+expect_output "deb ppa-people-ppa suite component" run_suite_mode --mirror "" --suite suite --archive ppa:people
+expect_output "deb ppa-people-otherppa suite component" run_suite_mode --mirror "" --suite suite --archive ppa:people/otherppa
+
+expect_output "hamm" debootstrap_suite --suite hamm
+expect_output "sid" debootstrap_suite --suite sid
+expect_output "sid" debootstrap_suite --suite unstable
+expect_output "mirror" debootstrap_mirror --suite sid --mirror mirror
+
+expect_output "sid" debootstrap_suite --profile sid
+expect_output "sid" debootstrap_suite --profile unstable
+expect_output "ubuntu-mirror" debootstrap_mirror --profile lucid --arch amd64
+expect_output "ubuntu-ports-mirror" debootstrap_mirror --profile lucid --arch armel
+
+testlib_summary
diff --git a/t/test_pbuilder-buildpackage-funcs b/t/test_pbuilder-buildpackage-funcs
new file mode 100755
index 0000000..80372f1
--- /dev/null
+++ b/t/test_pbuilder-buildpackage-funcs
@@ -0,0 +1,137 @@
+#!/bin/bash
+#
+# This file is part of pbuilder -- personal Debian package builder
+#
+# Copyright © 2015 Mattia Rizzolo <mattia@mapreri.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+# On Debian systems, the full text of the GNU General Public
+# License version 2 can be found in the file
+# `/usr/share/common-licenses/GPL-2'.
+
+
+# testsuite to test pbuilder-satisfydepends-funcs.
+
+TD="$(dirname "$0")"
+if [ -n "$PBUILDER_CHECKOUT" ]; then
+ . "$TD/testlib.sh"
+ . "$PBUILDER_CHECKOUT/pbuilder-buildpackage-funcs"
+else
+ . "$TD/testlib.sh"
+ . "$PBUILDER_TEST_PKGLIBDIR/pbuilder-buildpackage-funcs"
+fi
+
+DEBIAN_CONTROL=""
+
+cleanup() {
+ if [ -n "$DEBIAN_CONTROL" ]; then
+ rm -f "$DEBIAN_CONTROL"
+ fi
+}
+
+test_getdscfilesNormal () {
+
+ cat > "$DEBIAN_CONTROL" << EOF
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+Format: 3.0 (quilt)
+Source: libeatmydata
+Binary: eatmydata, libeatmydata1
+Architecture: any all
+Version: 82-6
+Maintainer: Modestas Vainius <modax@debian.org>
+Uploaders: Mattia Rizzolo <mattia@mapreri.org>
+Homepage: https://launchpad.net/libeatmydata
+Standards-Version: 3.9.6
+Vcs-Browser: https://anonscm.debian.org/cgit/collab-maint/libeatmydata.git
+Vcs-Git: git://anonscm.debian.org/collab-maint/libeatmydata.git
+Build-Depends: autotools-dev, debhelper (>= 9), strace [!hurd-any !kfreebsd-any]
+Package-List:
+ eatmydata deb utils optional arch=all
+ libeatmydata1 deb utils optional arch=any
+Checksums-Sha1:
+ c8d3cd2d9a872302c8a1494813565639bd4c2aa8 407977 libeatmydata_82.orig.tar.gz
+ 4a76697591072662acee1e25d7f86c1f6ac503dd 43484 libeatmydata_82-6.debian.tar.xz
+Checksums-Sha256:
+ 0b675f58069f912727cee5eb75f9ff1a6a8300fe7e3fe4fc6bdd03b7c2c15b29 407977 libeatmydata_82.orig.tar.gz
+ 3b5aede6617ed161211aee6f421d6af3c1ae22a4f4d11dc6545138359d7eea2c 43484 libeatmydata_82-6.debian.tar.xz
+Files:
+ 56a4d342f209ab75a9ee360236e3e5bc 407977 libeatmydata_82.orig.tar.gz
+ 06c197d3d4142b546e836d72fbe4b895 43484 libeatmydata_82-6.debian.tar.xz
+
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.12 (GNU/Linux)
+
+iD8DBQFUfLA320zMSyow1ykRAkRxAJ4zYyuUByiYq31sxbrB902PybqADwCfd/Gd
+SPXUusVdt4obPwG2sauWLlc=
+=e9Vj
+-----END PGP SIGNATURE-----
+EOF
+ getdscfiles "$DEBIAN_CONTROL"
+}
+
+test_getdscfilesWithoutNL () {
+
+ cat > "$DEBIAN_CONTROL" << EOF
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA256
+
+Format: 3.0 (quilt)
+Source: golang-xmpp-dev
+Binary: golang-xmpp-dev
+Architecture: all
+Version: 0.0~git20140304-1
+Maintainer: Jacob Appelbaum <jacob@appelbaum.net>
+Homepage: https://www.github.com/agl/xmpp
+Standards-Version: 3.9.5
+Build-Depends: debhelper (>= 9)
+Package-List:
+ golang-xmpp-dev deb devel extra
+Checksums-Sha1:
+ 2175fd06e8fcf9787044036837f21b7e6c3d2ceb 10040 golang-xmpp-dev_0.0~git20140304.orig.tar.gz
+ 72b5180710909e30208627bd77dd899751475309 2208 golang-xmpp-dev_0.0~git20140304-1.debian.tar.xz
+Checksums-Sha256:
+ 41805d983433423eb967628c43f033a19f6c8363c3d40a5931a5eb28f4e9133c 10040 golang-xmpp-dev_0.0~git20140304.orig.tar.gz
+ 54f49f52c2c1399c8262afc582e1ce38ef99cd4d95cd06f9350a91960176a925 2208 golang-xmpp-dev_0.0~git20140304-1.debian.tar.xz
+Files:
+ a00613a2e965c11c9713268c25486a1b 10040 golang-xmpp-dev_0.0~git20140304.orig.tar.gz
+ e5bc6c49ca86922344531418dee9e5dd 2208 golang-xmpp-dev_0.0~git20140304-1.debian.tar.xz
+-----BEGIN PGP SIGNATURE-----
+
+iQGVAwUBUxYUR1kMfZESRfeDAQgvCwv8CM7a+LcQQnk5Gil3jHHlr4EO6NvuDMpW
+4+yviAFZCmOVq3poUKYpojNNtIBPSGh2+POEOZu+6h1rQxQpPeiqrIteS4pMhR7s
+bptUqqAbRH/Yy9pcmPOf+yDeeGAr/xaga9vvankdn60Q5D7Xk85Bhl6a3KucCwGA
+h5s/ywDXZVOtjqywoB+zR5Jd2kuhjJUUdnUxTvVrw+rZXaKcwgAM1zUv6Tqkdkij
+NRJFW5p17c1gg0v7KvWcCJoNcF5Mn1avnTF7OhZm5ODreM9kgpcd+8yuG3n6j/Ey
+o4E6p2Tf5wTQ2t44OaU1uu8+0mjPhDxfEjGKcdThWQyrqO0hkGAfLkubLGRB4EZo
+dcWK+KNxOR5HzgQGJw+rEGn/x7kcQtdDeXn3EsHeAhJscicdbJW9nCM47+PLM7Pn
+B3WfTzfwrzVC/IcSM1303chIW0dfsMTCP0ubFZOqoMMflSKRPiJ3vPvJFFzmrS31
+M4EDxlS+nvAHZbzQ49QGnU/dMocDzvAH
+=XSwB
+-----END PGP SIGNATURE-----
+EOF
+ getdscfiles "$DEBIAN_CONTROL"
+
+}
+
+trap cleanup sigpipe sighup exit
+
+# FIXME move to build dir also because we have to hardoce /tmp/ on the result below
+DEBIAN_CONTROL="$(tempfile)"
+
+expect_output "$DEBIAN_CONTROL /tmp/libeatmydata_82.orig.tar.gz /tmp/libeatmydata_82-6.debian.tar.xz" test_getdscfilesNormal
+expect_output "$DEBIAN_CONTROL /tmp/golang-xmpp-dev_0.0~git20140304.orig.tar.gz /tmp/golang-xmpp-dev_0.0~git20140304-1.debian.tar.xz" test_getdscfilesWithoutNL
+
+testlib_summary
diff --git a/t/test_pbuilder-checkparams b/t/test_pbuilder-checkparams
new file mode 100755
index 0000000..a81ae8d
--- /dev/null
+++ b/t/test_pbuilder-checkparams
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# testsuite for pbuilder-checkparams
+
+TD="$(dirname "$0")"
+if [ -n "$PBUILDER_CHECKOUT" ]; then
+ . "$TD/testlib.sh"
+ PBUILDER_CHECKPARAMS="$PBUILDER_CHECKOUT/pbuilder-checkparams"
+else
+ . "$TD/testlib.sh"
+ PBUILDER_CHECKPARAMS="$PBUILDER_TEST_PKGLIBDIR/pbuilder-checkparams"
+fi
+
+# setup a fake installed environment
+trap testlib_cleanup_env sigpipe sighup exit
+testlib_setup_env
+
+test_debuildopts() {
+ . "$PBUILDER_CHECKPARAMS"
+ echo "$DEBBUILDOPTS"
+}
+
+expect_output "" \
+ test_debuildopts foo.dsc
+expect_output "" \
+ test_debuildopts --debbuildopts "" foo.dsc
+expect_output "-v1.0 -efoo" \
+ test_debuildopts --debbuildopts "-v1.0 -efoo" foo.dsc
+expect_output "-v1.0 -efoo" \
+ test_debuildopts --debbuildopts -v1.0 --debbuildopts -efoo foo.dsc
+expect_output "-efoo" \
+ test_debuildopts --debbuildopts -v1.0 --debbuildopts "" --debbuildopts -efoo foo.dsc
+
+testlib_summary
diff --git a/t/test_pbuilder-modules b/t/test_pbuilder-modules
new file mode 100755
index 0000000..9e1f6e0
--- /dev/null
+++ b/t/test_pbuilder-modules
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+TD="$(dirname "$0")"
+if [ -n "$PBUILDER_CHECKOUT" ]; then
+ . "$TD/testlib.sh"
+ . "$PBUILDER_CHECKOUT/pbuilder-modules"
+else
+ . "$TD/testlib.sh"
+ . "$PBUILDER_TEST_PKGLIBDIR/pbuilder-modules"
+fi
+
+function test_information() {
+ log "I: test"
+ log "W: warning"
+ log "E: error"
+}
+expect_output "I: test
+W: warning
+E: error" test_information
+
+# test the non-copy case
+function test_conditional_cp_a() {
+ (
+ TEMPDIR=$(mktemp -d)
+ cd "${TEMPDIR}"
+ touch "hoge"
+ outdir=$(readlink -f "${TEMPDIR}/..")
+ conditional_cp_a "hoge" "${outdir}" echo
+ )
+}
+expect_output "I: file hoge is already in target, not copying." \
+ test_conditional_cp_a
+
+# test the copy case.
+function test_conditional_cp_a_copy() {
+ (
+ cd /tmp
+ outdir=/something-else
+ conditional_cp_a "hoge" "${outdir}" echo
+ )
+}
+expect_output "-a hoge /something-else" test_conditional_cp_a_copy
+
+testlib_summary
diff --git a/t/test_pbuilder-satisfydepends-checkparams b/t/test_pbuilder-satisfydepends-checkparams
new file mode 100755
index 0000000..ccb044d
--- /dev/null
+++ b/t/test_pbuilder-satisfydepends-checkparams
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+TD="$(dirname "$0")"
+if [ -n "$PBUILDER_CHECKOUT" ]; then
+ . "$TD/testlib.sh"
+ PBUILDER_SATISFYDEPENDS_CHECKPARAMS="$PBUILDER_CHECKOUT/pbuilder-satisfydepends-checkparams"
+else
+ . "$TD/testlib.sh"
+ PBUILDER_SATISFYDEPENDS_CHECKPARAMS="$PBUILDER_TEST_PKGLIBDIR/pbuilder-satisfydepends-checkparams"
+fi
+
+# testsuite to test pbuilder-satisfydepends-checkparams.
+
+# mock function
+checkbuilddep_internal() {
+ : # do nothing function
+}
+
+test_chrootexec2() {
+ set -- --internal-chrootexec 'chroot /tmp-hoge ' --chroot /tmp
+ . "$PBUILDER_SATISFYDEPENDS_CHECKPARAMS"
+}
+expect_fail test_chrootexec2
+
+test_chrootexec1() {
+ set -- --chroot /tmp --internal-chrootexec 'chroot /tmp-hoge '
+ . "$PBUILDER_SATISFYDEPENDS_CHECKPARAMS"
+}
+expect_success test_chrootexec1
+
+test_chrootexec_echo() {
+ set -- --echo --chroot /tmp
+ . "$PBUILDER_SATISFYDEPENDS_CHECKPARAMS"
+}
+expect_fail test_chrootexec_echo
+
+test_chrootexec_echo2() {
+ set -- --chroot /tmp --echo
+ . "$PBUILDER_SATISFYDEPENDS_CHECKPARAMS"
+ echo $CHROOTEXEC
+}
+expect_output "echo chroot /tmp" test_chrootexec_echo2
+
+test_chrootexec_expect() {
+ set -- --chroot /tmp --internal-chrootexec 'chroot /tmp-hoge '
+ . "$PBUILDER_SATISFYDEPENDS_CHECKPARAMS"
+ echo $CHROOTEXEC
+}
+expect_output "chroot /tmp-hoge" test_chrootexec_expect
+
+testlib_summary
diff --git a/t/test_pbuilder-satisfydepends-classic b/t/test_pbuilder-satisfydepends-classic
new file mode 100755
index 0000000..929699b
--- /dev/null
+++ b/t/test_pbuilder-satisfydepends-classic
@@ -0,0 +1,116 @@
+#!/bin/bash
+#for flavour in aptitude classic experimental gdebi; do
+# (. ./pbuilder-satisfydepends-"$flavour")
+#done
+
+TD="$(dirname "$0")"
+if [ -n "$PBUILDER_CHECKOUT" ]; then
+ . "$TD/testlib.sh"
+ PBUILDER_SATISFYDEPENDS_CLASSIC="$PBUILDER_CHECKOUT/pbuilder-satisfydepends-classic"
+else
+ . "$TD/testlib.sh"
+ PBUILDER_SATISFYDEPENDS_CLASSIC="$PBUILDER_TEST_PKGLIBDIR/pbuilder-satisfydepends-classic"
+fi
+
+DEBIAN_CONTROL=""
+
+cleanup() {
+ if [ -n "$DEBIAN_CONTROL" ]; then
+ rm -f "$DEBIAN_CONTROL"
+ fi
+ testlib_cleanup_env
+}
+
+trap cleanup sigpipe sighup exit
+
+# setup a fake installed environment
+testlib_setup_env
+
+if [ -n "$PBUILDER_CHECKOUT" ]; then
+ PBUILDER_SATISFYDEPENDS_CLASSIC="$PBUILDER_CHECKOUT/pbuilder-satisfydepends-classic"
+else
+ export PBUILDER_PKGLIBDIR="${PBUILDER_PKGLIBDIR:-$PBUILDER_ROOT/usr/lib/pbuilder}"
+ PBUILDER_SATISFYDEPENDS_CLASSIC="$PBUILDER_PKGLIBDIR/pbuilder-satisfydepends-classic"
+fi
+
+set -- --echo --control "$DEBIAN_CONTROL"
+# this is just to source the functions
+. "$PBUILDER_SATISFYDEPENDS_CLASSIC" >/dev/null 2>&1 || true
+
+DEBIAN_CONTROL="`mktemp -t`"
+cat >"$DEBIAN_CONTROL" <<EOF
+Build-Depends: debhelper (>= 5.0.0), gnome-pkg-tools, autotools-dev, cdbs, libglib2.0-dev (>= 2.12), libgtk2.0-dev (>= 2.10), libgnome2-dev (>= 2.16.0), libgnomeui-dev (>= 2.16.0), libglade2-dev, libgnomevfs2-dev (>= 2.9.2), libgconf2-dev, libxft-dev, libperl-dev, python-dev, tcl8.4-dev, libxml-parser-perl, libdbus-glib-1-dev (>= 0.60), libtool, scrollkeeper, libgnutls-dev, libnotify-dev (>= 0.3.2-0), libsexy-dev (>= 0.1.7), gnome-doc-utils, libssl-dev (>= 0.9.8b-1), liblaunchpad-integration-dev
+
+EOF
+
+test_split_deps() {
+ get_build_deps | split_deps
+}
+
+expect_output "debhelper/(>=/5.0.0)
+gnome-pkg-tools
+autotools-dev
+cdbs
+libglib2.0-dev/(>=/2.12)
+libgtk2.0-dev/(>=/2.10)
+libgnome2-dev/(>=/2.16.0)
+libgnomeui-dev/(>=/2.16.0)
+libglade2-dev
+libgnomevfs2-dev/(>=/2.9.2)
+libgconf2-dev
+libxft-dev
+libperl-dev
+python-dev
+tcl8.4-dev
+libxml-parser-perl
+libdbus-glib-1-dev/(>=/0.60)
+libtool
+scrollkeeper
+libgnutls-dev
+libnotify-dev/(>=/0.3.2-0)
+libsexy-dev/(>=/0.1.7)
+gnome-doc-utils
+libssl-dev/(>=/0.9.8b-1)
+liblaunchpad-integration-dev" test_split_deps
+
+expect_output "foo
+bar" split_alternates "foo | bar"
+
+expect_output "debhelper
+gnome-pkg-tools
+autotools-dev
+cdbs
+libglib2.0-dev
+libgtk2.0-dev
+libgnome2-dev
+libgnomeui-dev
+libglade2-dev
+libgnomevfs2-dev
+libgconf2-dev
+libxft-dev
+libperl-dev
+python-dev
+tcl8.4-dev
+libxml-parser-perl
+libdbus-glib-1-dev
+libtool
+scrollkeeper
+libgnutls-dev
+libnotify-dev
+libsexy-dev
+gnome-doc-utils
+libssl-dev
+liblaunchpad-integration-dev" get_pkg_name "`test_split_deps`"
+
+expect_output ">= 5.0.0
+>= 2.12
+>= 2.10
+>= 2.16.0
+>= 2.16.0
+>= 2.9.2
+>= 0.60
+>= 0.3.2-0
+>= 0.1.7
+>= 0.9.8b-1" get_dep_op_and_ver "`test_split_deps`"
+
+testlib_summary
diff --git a/t/test_pbuilder-satisfydepends-funcs b/t/test_pbuilder-satisfydepends-funcs
new file mode 100755
index 0000000..5aaee9b
--- /dev/null
+++ b/t/test_pbuilder-satisfydepends-funcs
@@ -0,0 +1,202 @@
+#!/bin/bash
+
+# testsuite to test pbuilder-satisfydepends-funcs.
+
+TD="$(dirname "$0")"
+if [ -n "$PBUILDER_CHECKOUT" ]; then
+ . "$TD/testlib.sh"
+ . "$PBUILDER_CHECKOUT/pbuilder-satisfydepends-funcs"
+else
+ . "$TD/testlib.sh"
+ . "$PBUILDER_TEST_PKGLIBDIR/pbuilder-satisfydepends-funcs"
+fi
+
+DEBIAN_CONTROL=""
+
+cleanup() {
+ if [ -n "$DEBIAN_CONTROL" ]; then
+ rm -f "$DEBIAN_CONTROL"
+ fi
+}
+
+test_get_build_deps() {
+ local BINARY_ARCH
+
+ BINARY_ARCH="$1"
+
+ cat <<EOF >"$DEBIAN_CONTROL"
+Source: amule
+XXXX:
+Build-Depends:
+ autotools-dev ( >= 1.2 ) ,
+ debhelper ,
+ quilt(<<12:0),
+##
+ libwxgtk2.8-dev
+Build-Depends-Indep: test [ amd64 i386 ], test1,
+ test2[!i386 ! amd64], test3 |
+ test4, test5
+Misc: test
+
+Build-Depends: wrong build depends, line
+Description: test
+ other things
+ wow
+EOF
+ get_build_deps
+}
+
+test_get_build_deps_dsc() {
+ cat <<EOF >"$DEBIAN_CONTROL"
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA256
+
+Format: 1.0
+Source: hello-debhelper
+Build-Depends: debhelper (>= 7)
+Checksums-Sha1:
+ fcbf0264928900adf03a7797474375e1a6fa3836 499638 hello-debhelper_2.4.orig.tar.gz
+ 0ea70eb46b4c90a8dbefbe60bebe4b9f9abb2733 5308 hello-debhelper_2.4-3.diff.gz
+
+
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.9 (GNU/Linux)
+
+iQEcBAEBCAAGBQJKml74AAoJEEHOfwufG4sysC4H/26EikyIgIqRuSXMiykc1hmd
+97id9nWl+QzgCpUEg/+uDqEW+Bl6291FstGvzTFCwmB5JjH9ErH1LsyG1OLXbFUb
+H89Em7qkl4o2ACTh255oM7FhVweof3UEaLCZMH+HZVVpHXNpEnhrfDvpTBbPGjUi
+-----END PGP SIGNATURE-----
+EOF
+ get_build_deps
+}
+
+test_get_parsed_build_deps_dsc() {
+ local ARCH="amd64"
+ local BINARY_ARCH="no"
+
+ cat > "$DEBIAN_CONTROL" << EOF
+Format: 3.0 (quilt)
+Source: haskell-concrete-typerep
+Binary: libghc-concrete-typerep-dev, libghc-concrete-typerep-prof, libghc-concrete-typerep-doc
+Architecture: any all
+Version: 0.1.0.2-4
+Maintainer: Debian Haskell Group <pkg-haskell-maintainers@lists.alioth.debian.org>
+Uploaders: Masayuki Hatta (mhatta) <mhatta@debian.org>
+Homepage: http://hackage.haskell.org/package/concrete-typerep
+Standards-Version: 3.9.3
+Vcs-Browser: http://darcs.debian.org/cgi-bin/darcsweb.cgi?r=pkg-haskell/haskell-concrete-typerep
+Vcs-Darcs: http://darcs.debian.org/pkg-haskell/haskell-concrete-typerep
+Build-Depends: debhelper (>= 9), haskell-devscripts (>= 0.9), cdbs, ghc, ghc-prof, libghc-hashable-dev (<< 1.3), libghc-hashable-prof (<< 1.3)
+Build-Depends-Indep: ghc-doc, libghc-hashable-doc (<< 1.3)
+Package-List:
+ libghc-concrete-typerep-dev deb haskell extra arch=any
+ libghc-concrete-typerep-doc deb doc extra arch=all
+ libghc-concrete-typerep-prof deb haskell extra arch=any
+Checksums-Sha1:
+ 7dc356eef28c83f606b792e3d39b68a04c1a6d98 3159 haskell-concrete-typerep_0.1.0.2.orig.tar.gz
+ a5b34d7dd7f1ef42b0afad86140efcd6997d09c1 2272 haskell-concrete-typerep_0.1.0.2-4.debian.tar.xz
+Checksums-Sha256:
+ f72a41d9d8315528c7b0e13bf61e6122c7d236cb529c207cfb431cf272439e1f 3159 haskell-concrete-typerep_0.1.0.2.orig.tar.gz
+ 09dcedfef76799dcb3c6a9e22bc22711050cc56769614bdbf61b426579ce10e5 2272 haskell-concrete-typerep_0.1.0.2-4.debian.tar.xz
+Files:
+ 5638a296661fb65145dfbc062cfa53db 3159 haskell-concrete-typerep_0.1.0.2.orig.tar.gz
+ 706754d44fac13c25e1ee8dd89180c53 2272 haskell-concrete-typerep_0.1.0.2-4.debian.tar.xz
+EOF
+ get_build_deps | filter_arch_deps "$ARCH" | filter_restriction_deps "$DEB_BUILD_PROFILES"
+}
+
+test_get_source_control_field_with_comments() {
+ cat <<EOF >"$DEBIAN_CONTROL"
+# This is a comment
+
+# So is this, but with a blank line above me
+Format: 1.0
+Source: something-funny
+Build-Depends: debhelper, something-else
+
+EOF
+ get_source_control_field "Source"
+}
+
+trap cleanup sigpipe sighup exit
+
+# TODO move to build dir
+DEBIAN_CONTROL="$(tempfile)"
+
+expect_output "autotools-dev (>= 1.2), debhelper, quilt (<< 12:0), libwxgtk2.8-dev, test [amd64 i386], test1, test2 [!i386 !amd64], test3 | test4, test5" \
+ test_get_build_deps "no"
+expect_output "autotools-dev (>= 1.2), debhelper, quilt (<< 12:0), libwxgtk2.8-dev" \
+ test_get_build_deps "yes"
+
+expect_fail checkbuilddep_archdeps "foo [amd64]" "amd64"
+expect_success checkbuilddep_archdeps "foo [i386]" "amd64"
+expect_fail checkbuilddep_archdeps "foo [i386 amd64]" "amd64"
+expect_success checkbuilddep_archdeps "foo [!amd64]" "amd64"
+expect_success checkbuilddep_archdeps "foo [!i386 !amd64]" "amd64"
+
+test_filter_arch_deps() {
+ echo "$1" | filter_arch_deps "$2"
+}
+
+expect_output "foo" test_filter_arch_deps "foo" "amd64"
+expect_output "foo" test_filter_arch_deps "foo [amd64]" "amd64"
+expect_output "bar, foo" test_filter_arch_deps "bar, foo [amd64]" "amd64"
+expect_output "bar | foo" test_filter_arch_deps "bar | foo [amd64]" "amd64"
+expect_output "bar" test_filter_arch_deps "bar | foo [amd64]" "i386"
+
+expect_fail checkbuilddep_restrictiondeps "foo <!stage1>" ""
+expect_success checkbuilddep_restrictiondeps "foo <!stage1>" "stage1"
+expect_fail checkbuilddep_restrictiondeps "foo <!stage1>" "notest"
+expect_success checkbuilddep_restrictiondeps "foo <!stage1>" "stage1 notest"
+
+expect_success checkbuilddep_restrictiondeps "foo <stage1>" ""
+expect_fail checkbuilddep_restrictiondeps "foo <stage1>" "stage1"
+expect_success checkbuilddep_restrictiondeps "foo <stage1>" "notest"
+expect_fail checkbuilddep_restrictiondeps "foo <stage1>" "stage1 notest"
+
+expect_fail checkbuilddep_restrictiondeps "foo <!stage1 !notest>" ""
+expect_success checkbuilddep_restrictiondeps "foo <!stage1 !notest>" "stage1"
+expect_success checkbuilddep_restrictiondeps "foo <!stage1 !notest>" "notest"
+expect_success checkbuilddep_restrictiondeps "foo <!stage1 !notest>" "stage1 notest"
+
+expect_success checkbuilddep_restrictiondeps "foo <stage1 notest>" ""
+expect_success checkbuilddep_restrictiondeps "foo <stage1 notest>" "stage1"
+expect_success checkbuilddep_restrictiondeps "foo <stage1 notest>" "notest"
+expect_fail checkbuilddep_restrictiondeps "foo <stage1 notest>" "stage1 notest"
+
+expect_success checkbuilddep_restrictiondeps "foo <!stage1 notest>" ""
+expect_success checkbuilddep_restrictiondeps "foo <!stage1 notest>" "stage1"
+expect_fail checkbuilddep_restrictiondeps "foo <!stage1 notest>" "notest"
+expect_success checkbuilddep_restrictiondeps "foo <!stage1 notest>" "stage1 notest"
+
+expect_success checkbuilddep_restrictiondeps "foo <stage1 !notest>" ""
+expect_fail checkbuilddep_restrictiondeps "foo <stage1 !notest>" "stage1"
+expect_success checkbuilddep_restrictiondeps "foo <stage1 !notest>" "notest"
+expect_success checkbuilddep_restrictiondeps "foo <stage1 !notest>" "stage1 notest"
+
+test_filter_restriction_deps() {
+ echo "$1" | filter_restriction_deps "$2"
+}
+
+expect_output "foo" test_filter_restriction_deps "foo <!stage1>" ""
+expect_output "" test_filter_restriction_deps "foo <!stage1>" "stage1"
+expect_output "foo" test_filter_restriction_deps "foo <stage1>" "stage1"
+expect_output "bar, foo" test_filter_restriction_deps "bar, foo <stage1>" "stage1"
+expect_output "bar | foo" test_filter_restriction_deps "bar | foo <stage1>" "stage1"
+expect_output "bar" test_filter_restriction_deps "bar | foo <!stage1>" "stage1"
+
+test_filter_arch_restriction_deps() {
+ echo "$1" | filter_arch_deps "$2" | filter_restriction_deps "$3"
+}
+
+expect_output "foo" test_filter_arch_restriction_deps "foo [amd64] <!stage1>" "amd64" ""
+expect_output "" test_filter_arch_restriction_deps "foo [amd64] <stage1>" "amd64" ""
+expect_output "foo" test_filter_arch_restriction_deps "foo [amd64] <!stage1>" "amd64" ""
+expect_output "" test_filter_arch_restriction_deps "foo [i386] <stage1>" "amd64" "stage1"
+
+expect_output "debhelper (>= 7)" test_get_build_deps_dsc
+expect_output "debhelper (>= 9), haskell-devscripts (>= 0.9), cdbs, ghc, ghc-prof, libghc-hashable-dev (<< 1.3), libghc-hashable-prof (<< 1.3), ghc-doc, libghc-hashable-doc (<< 1.3)" test_get_parsed_build_deps_dsc
+
+expect_output "something-funny" test_get_source_control_field_with_comments
+
+testlib_summary
diff --git a/t/test_testlib.sh b/t/test_testlib.sh
new file mode 100755
index 0000000..a37f6b1
--- /dev/null
+++ b/t/test_testlib.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+# testsuite for testlib
+
+TD="$(dirname "$0")"
+if [ -n "$PBUILDER_CHECKOUT" ]; then
+ . "$TD/testlib.sh"
+ . "$PBUILDER_CHECKOUT/pbuilder-modules"
+else
+ . "$TD/testlib.sh"
+ . "$PBUILDER_TEST_PKGLIBDIR/pbuilder-modules"
+fi
+
+test_success() {
+ exit 0
+}
+
+test_fail() {
+ exit 1
+}
+
+test_options() {
+ echo "$@"
+ exit 1
+}
+
+test_output() {
+ echo "$@"
+}
+
+expect_success test_success
+expect_fail test_fail
+expect_fail test_options "hello world"
+expect_output "foo bar" test_output "foo" "bar"
+testlib_summary
diff --git a/t/testlib.sh b/t/testlib.sh
new file mode 100644
index 0000000..7d31888
--- /dev/null
+++ b/t/testlib.sh
@@ -0,0 +1,158 @@
+#!/bin/bash
+# 2008 Junichi Uekawa <dancer@debian.org>
+
+set -e
+
+# library for functional unit-testing in bash.
+
+# WARNING: this file locates files differently from the other pbuilder
+# functions:
+# - if PBUILDER_CHECKOUT is set, it is assumed that testlib.sh is sourced from
+# a pbuilder checkout (e.g. from the upstream Makefile or Debian build)
+# - otherwise, PBUILDER_TEST_ROOT or PBUILDER_TEST_*DIR should be used to
+# locate files instead of PBUILDER_ROOT and PBUILDER_*DIR since
+# testlib_setup_env() overrides these vars to run the other pbuilder modules
+# with a fake environment
+
+# if this is set, use pbuilder files from this location; otherwise, use
+# installed files (from PBUILDER_TEST_ROOT, which is a copy of PBUILDER_ROOT)
+PBUILDER_CHECKOUT="${PBUILDER_CHECKOUT:-}"
+
+if [ -z "$PBUILDER_CHECKOUT" ]; then
+ # these currently don't need to be exported
+ PBUILDER_TEST_ROOT="${PBUILDER_ROOT:-}"
+ PBUILDER_TEST_PKGLIBDIR="${PBUILDER_PKGLIBDIR:-$PBUILDER_ROOT/usr/lib/pbuilder}"
+ PBUILDER_TEST_PKGDATADIR="${PBUILDER_PKGDATADIR:-$PBUILDER_ROOT/usr/share/pbuilder}"
+fi
+
+# set PBUILDER_TEST_VERBOSE to get the full output of tests
+
+TESTLIB_FAILS=0
+TESTLIB_TESTS=0
+
+testlib_echo() {
+ case "$1" in
+ OK)
+ shift
+ if [ -n "$PBUILDER_TEST_VERBOSE" ]; then
+ echo "[OK]" "$@" >&2
+ fi
+ ;;
+ FAIL)
+ shift
+ echo "[FAIL]" "$@" >&2
+ TESTLIB_FAILS=$(($TESTLIB_FAILS + 1))
+ ;;
+ esac
+ TESTLIB_TESTS=$(($TESTLIB_TESTS + 1))
+}
+
+testlib_summary() {
+ echo "$0: Ran $TESTLIB_TESTS tests and $(($TESTLIB_TESTS - $TESTLIB_FAILS)) succeeded, $TESTLIB_FAILS failed"
+ if [ $TESTLIB_FAILS != 0 ]; then
+ echo '================='
+ echo 'Testsuite FAILED!'
+ echo " $0"
+ echo '================='
+ return 1
+ fi
+ return 0
+}
+
+# Create fake installed tree with basic config files. Make sure you trap test
+# script exit to call testlib_cleanup_env. Optional arg is location of the
+# pbuilder checkout to copy files from.
+# this is where the env actually lives
+testlib_env_root=""
+testlib_setup_env() {
+ local abs_pbuilder_checkout r
+
+ if [ -n "$testlib_env_root" ]; then
+ echo "testlib_setup_env called twice without testlib_cleanup_env" >&2
+ testlib_cleanup_env
+ exit 1
+ fi
+
+ if [ -n "$PBUILDER_CHECKOUT" ]; then
+ abs_pbuilder_checkout="`cd $PBUILDER_CHECKOUT; pwd`"
+ fi
+
+ # backup env vars
+ testlib_env_oldhome="$HOME"
+ testlib_env_oldroot="$PBUILDER_ROOT"
+
+ testlib_env_root="`mktemp -dt`"
+ # brevity
+ r="$testlib_env_root"
+
+ mkdir "$r"/etc
+ touch "$r"/etc/pbuilderrc
+ mkdir -p "$r"/usr/share/pbuilder
+ if [ -n "$PBUILDER_CHECKOUT" ]; then
+ cp "$PBUILDER_CHECKOUT"/pbuilderrc "$r"/usr/share/pbuilder
+ else
+ cp "$PBUILDER_TEST_PKGDATADIR"/pbuilderrc "$r"/usr/share/pbuilder
+ fi
+ mkdir -p "$r"/usr/lib
+ if [ -n "$PBUILDER_CHECKOUT" ]; then
+ ln -s "$abs_pbuilder_checkout" "$r"/usr/lib/pbuilder
+ else
+ ln -s "$PBUILDER_TEST_PKGLIBDIR" "$r"/usr/lib/pbuilder
+ fi
+ export PBUILDER_ROOT="$r"
+ # when running the testsuite within pbuilder, these env vars will have been
+ # set by regular pbuilder commands, so we need to unset them as to allow
+ # their default values to be recomputed relative to PBUILDER_ROOT
+ unset PBUILDER_PKGLIBDIR PBUILDER_PKGDATADIR PBUILDER_SYSCONFDIR
+
+ mkdir "$r"/home
+ touch "$r"/home/.pbuilderrc
+ export HOME="$r"/home
+}
+
+# Reverse the effect of testlib_setup_env. Setup a trap handler in your tests
+# on this function if you call testlib_setup_env.
+testlib_cleanup_env() {
+ if [ -z "$testlib_env_root" ]; then
+ # nothing to do
+ return
+ fi
+ rm -rf "$testlib_env_root"
+ export PBUILDER_ROOT="$testlib_env_oldroot"
+ export HOME="$testlib_env_oldhome"
+ testlib_env_root=""
+}
+
+expect_success() {
+ # run the test in subshell; successful commands should not output anything
+ # to stderr but may send output to stdout
+ if (if [ -z "$PBUILDER_TEST_VERBOSE" ]; then exec >/dev/null; fi; "$@"); then
+ testlib_echo "OK" "$1"
+ else
+ testlib_echo "FAIL" "$1"
+ fi
+}
+
+expect_fail() {
+ # run the test in subshell; failed commands may output anything to stdout
+ # and stderr
+ if (if [ -z "$PBUILDER_TEST_VERBOSE" ]; then exec >/dev/null 2>&1; fi; "$@"); then
+ testlib_echo "FAIL" "$1"
+ else
+ testlib_echo "OK" "$1"
+ fi
+}
+
+expect_output() {
+ # run the test in subshell
+ local val result
+ val="$1"
+ shift
+ result="`"$@" 2>&1`" || true
+ if [ "$result" = "$val" ]; then
+ testlib_echo "OK" "$1"
+ else
+ testlib_echo "FAIL" "$1" "expected [$val] but got [$result]"
+ fi
+}
+