chiark / gitweb /
Test suite: t-expect-push-fail checks HEAD object did not arrive
[dgit.git] / tests / lib
index cf8b72569dfdabc2368c0f49f4762cc4dede8128..5b93d98dc86b074d71080106cf9ca35a8ec43e9c 100644 (file)
--- a/tests/lib
+++ b/tests/lib
@@ -44,12 +44,71 @@ END
 
 t-expect-fail () {
        local mpat="$1"; shift
+
+       local grepper=fgrep
+       case "$mpat" in
+       [A-Z]:*)
+               case "$mpat" in
+               E:*)    grepper=egrep   ;;
+               F:*)    grepper=fgrep   ;;
+               *)      fail "bad mpat prefix in $mpat";;
+               esac
+               mpat=${mpat#[A-Z]:}
+               ;;
+       esac
+
        set +o pipefail
        LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
-       local gotstatus=${PIPESTATUS[0]}
+       local ps="${PIPESTATUS[*]}"
        set -o pipefail
-       test $gotstatus != 0
-       egrep "$mpat" $tmp/t.output ||false
+
+       case $ps in
+       "0 0")  fail "command unexpectedly succeeded (instead of: $mpat)" ;;
+       *" 0")  ;;
+       *)      fail "tee failed"  ;;
+       esac
+
+       $grepper -e "$mpat" $tmp/t.output ||
+               fail "error message not found"
+}
+
+t-expect-push-fail () {
+       local mpat="$1"; shift
+
+       local triedpush=`git rev-parse HEAD`
+
+       t-reporefs pre-push
+       t-expect-fail "$mpat"  "$@"
+       t-reporefs post-push
+       diff $tmp/show-refs.{pre,post}-push
+
+       t-git-objects-not-present '' $triedpush
+
+       eval "$t_expect_push_fail_hook"
+}
+
+t-git-objects-not-present () {
+       # t-git-objects-not-present GITDIR|'' OBJID [...]
+       # specifying '' means the repo for package $p
+       local gitdir="${1-$tmp/git/$p.git}"
+       local obj
+       if ! [ -e "$gitdir" ]; then return; fi
+       for obj in "$@"; do
+               GIT_DIR=$gitdir \
+               t-expect-fail 'unable to find' \
+               git cat-file -t $obj
+       done
+}
+
+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 () {