chiark / gitweb /
test suite: Do not tolerate any stderr output from git-fsck
[dgit.git] / tests / lib
index 579ddda34665dc279cd268ae70a011515095db1e..52aca71b6e27cb5818bba3f040f1f5bef76aca19 100644 (file)
--- a/tests/lib
+++ b/tests/lib
@@ -349,8 +349,35 @@ t-git-dir-check () {
        esac
 }
 
+t-expect-fsck-fail () {
+       echo >>$tmp/fsck.expected-errors "$1"
+}
+
 t-git-fsck () {
-       git fsck --no-dangling --strict
+       set +e
+       LC_MESSAGES=C git fsck --no-dangling --strict 2>&1 \
+               | tee dgit-test-fsck.errs
+       ps="${PIPESTATUS[*]}"
+       set -e
+
+       local pats
+       if [ -f $tmp/fsck.expected-errors ]; then
+               pats=(-w -f $tmp/fsck.expected-errors)
+       else
+               test "$ps" = "0 0"
+       fi
+       pats+=(-e 'notice: HEAD points to an unborn branch')
+       pats+=(-e 'notice: No default references')
+
+       set +e
+       grep -v "${pats[@]}" dgit-test-fsck.errs
+       rc=$?
+       set -e
+       case $rc in
+       1) ;; # no unexpected errors
+       0) fail "unexpected messages from git-fsck" ;;
+       *) fail "grep of git-fsck failed" ;;
+       esac
 }
 
 t-fscks () {