aboutsummaryrefslogtreecommitdiff
path: root/testlib.sh
diff options
context:
space:
mode:
Diffstat (limited to 'testlib.sh')
-rw-r--r--testlib.sh42
1 files changed, 36 insertions, 6 deletions
diff --git a/testlib.sh b/testlib.sh
index 2c01739..77943fb 100644
--- a/testlib.sh
+++ b/testlib.sh
@@ -1,10 +1,30 @@
#!/bin/bash
# 2008 Junichi Uekawa <dancer@debian.org>
-set -e
+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
+
TESTLIB_FAILS=0
TESTLIB_TESTS=0
@@ -40,9 +60,7 @@ testlib_summary() {
# this is where the env actually lives
testlib_env_root=""
testlib_setup_env() {
- local pbuilder_checkout abs_pbuilder_checkout r
- pbuilder_checkout="${1:-.}"
- abs_pbuilder_checkout="`cd $pbuilder_checkout; pwd`"
+ local abs_pbuilder_checkout r
if [ -n "$testlib_env_root" ]; then
echo "testlib_setup_env called twice without testlib_cleanup_env" >&2
@@ -50,6 +68,10 @@ testlib_setup_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"
@@ -61,9 +83,17 @@ testlib_setup_env() {
mkdir "$r"/etc
touch "$r"/etc/pbuilderrc
mkdir -p "$r"/usr/share/pbuilder
- cp "$pbuilder_checkout"/pbuilderrc "$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
- ln -s "$abs_pbuilder_checkout" "$r"/usr/lib/pbuilder
+ 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