chiark / gitweb /
Test suite: Make t-reporefs stash the output
[dgit.git] / tests / lib
index aec86127d227ac0c4f81af3304ba4be42aa3d470..776e2a3e40f42bf426365d96f2894e57795044e7 100644 (file)
--- a/tests/lib
+++ b/tests/lib
@@ -2,6 +2,7 @@
 
 exec 2>&1
 set -x
+set -o pipefail
 
 . tests/lib-core
 
@@ -43,11 +44,25 @@ END
 
 t-expect-fail () {
        local mpat="$1"; shift
+       set +o pipefail
        LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
-       test ${PIPESTATUS[0]} != 0
+       local gotstatus=${PIPESTATUS[0]}
+       set -o pipefail
+       test $gotstatus != 0
        egrep "$mpat" $tmp/t.output ||false
 }
 
+t-reporefs () {
+       local whichoutput=$1; shift
+       local outputfile="$tmp/show-refs.$whichoutput"
+       (set -e
+        exec >"$outputfile"
+        if test -d $tmp/git/$p.git; then
+               cd $tmp/git/$p.git
+               git show-ref |sort
+       fi)
+}
+
 t-untar () {
        local tarfile=$1.tar
        local edittree=$1.edit
@@ -225,7 +240,7 @@ t-cloned-fetched-good () {
        t-refs-same \
                refs/heads/dgit/sid \
                refs/remotes/dgit/dgit/sid
-       t-refs-notexist dgit/unstable remotes/dgit/dgit/unstable
+       t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
 }
 
 t-output () {
@@ -241,7 +256,11 @@ t-clean-on-branch () {
 
 t-git-get-ref () {
        local ref=$1
-       git show-ref -d $1 | perl -ne '
+       case "$ref" in
+       refs/*) ;;
+       *) fail "t-git-get-ref bad $ref" ;;
+       esac
+       (git show-ref -d $1 || test $? = 1) | perl -ne '
                $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
                END { print "$x\n" if length $x; }
        '
@@ -366,8 +385,9 @@ t-ref-dsc-dgit () {
 t-apply-diff () {
        local v1=$1
        local v2=$2
-       (cd $troot/pkg-srcs; debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc) \
-               | patch -p1 -u
+       (cd $troot/pkg-srcs;
+        debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
+        | patch -p1 -u
 }
 
 t-commit () {
@@ -425,17 +445,16 @@ t-policy-admin () {
 
 t-policy () {
        local policyhook=$1
-       t-dsd
-
        ln -sf ${DGIT_INFRA_PFX}$policyhook \
                $drs_dispatch/policy-hook
-
-       mkdir $tmp/git
-       t-policy-admin create-db
 }
 
 t-debpolicy () {
+       t-dsd
        t-policy dgit-repos-policy-debian
+
+       mkdir $tmp/git
+       t-policy-admin create-db
 }
 
 t-policy-periodic () {