chiark / gitweb /
Test suite: Use t-expect-push-fail everywhere
[dgit.git] / tests / lib
index 5c8293f9b200d1f127c8811b7f875fe6ca5024f0..f45dd0b2bb80ecbdec39807d471cac72bf2f531d 100644 (file)
--- a/tests/lib
+++ b/tests/lib
@@ -44,17 +44,48 @@ 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
+       t-reporefs pre-push
+       t-expect-fail "$mpat"  "$@"
+       t-reporefs post-push
+       diff $tmp/show-refs.{pre,post}-push
 }
 
 t-reporefs () {
+       local whichoutput=$1; shift
+       local outputfile="$tmp/show-refs.$whichoutput"
        (set -e
-       if test -d $tmp/git/$p.git; then
+        exec >"$outputfile"
+        if test -d $tmp/git/$p.git; then
                cd $tmp/git/$p.git
                git show-ref |sort
        fi)