X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=tests%2Flib;h=c91020bc3285a3e5545fe0e5d71b3d0340d42e8f;hp=e960c1c62c33f60c76a27f83cd212aac0b8fcc2a;hb=5d8e32854c1d89e337bc606d423634a667f9b0ff;hpb=d05936fa35e8fccc8b9eead88379fcdaa2021277 diff --git a/tests/lib b/tests/lib index e960c1c6..c91020bc 100644 --- a/tests/lib +++ b/tests/lib @@ -2,6 +2,7 @@ exec 2>&1 set -x +set -o pipefail . tests/lib-core @@ -43,9 +44,43 @@ 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 - test ${PIPESTATUS[0]} != 0 - egrep "$mpat" $tmp/t.output ||false + local ps="${PIPESTATUS[*]}" + set -o pipefail + + 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-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 () { @@ -245,7 +280,7 @@ t-git-get-ref () { refs/*) ;; *) fail "t-git-get-ref bad $ref" ;; esac - git show-ref -d $1 | perl -ne ' + (git show-ref -d $1 || test $? = 1) | perl -ne ' $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#; END { print "$x\n" if length $x; } '