chiark / gitweb /
test suite: gitattributes: Break out t-dgit-warn-check
[dgit.git] / tests / tests / gitattributes
index fd3faa35899acc3e43bd5870ee5b7e7c4773150e..d9323b6ea4c97b4ab14f729413780a2564e75f0d 100755 (executable)
@@ -103,22 +103,55 @@ sfmt_setup () {
        cd ..
 }
 
+sums_check () {
+       # caller should cd into working directory, set
+       #   $sums  $branch
+       # and check out $branch
+
+       sha256sum af/* >../$sums.checkout
+       diff -U0 ../sums ../$sums.checkout
+
+       for f in af/*; do
+               git cat-file blob "refs/heads/$branch:$f" \
+                       | sha256sum \
+                       | sed -e 's#-$#'$f'#' \
+               >>../$sums
+       done
+
+       diff -U0 ../sums ../$sums
+}
+
+t-dgit-warn-check () {
+       local warnok=$1; shift
+       # warnok should be  0 if the warning is expected
+       #                   1 if the warning is NOT expected
+
+       local err=stderr.$wd
+
+       LC_MESSAGES=C t-dgit "$@" 2>&1 |tee ../$err
+
+       set +e
+       fgrep 'warning: source tree contains .gitattributes' ../$err
+       rc=$?
+       set -e
+
+       test "$rc" = "$warnok"
+}
+
 sfmt_import () {
        inst=$1
        dgitargs=$2
        branch="import.$sfmt-$inst"
-       brkerr=stderr.$sfmt-$inst.broken
        dscf=${p}_${v}.dsc
        sums=sums.$sfmt-$inst
+       wd=$pdb-import-$inst
 
-       mkdir $pdb-import-$inst
-       cd $pdb-import-$inst
+       mkdir $wd
+       cd $wd
        git init
 
-       LC_MESSAGES=C \
-       t-dgit $dgitargs import-dsc ../$dscf +$branch.broken \
-               2>&1 |tee ../$brkerr
-       fgrep 'warning: source tree contains .gitattributes' ../$brkerr
+       t-dgit-warn-check 0 $dgitargs import-dsc ../$dscf +$branch.broken
+
        git checkout $branch.broken
        sha256sum af/* >../$sums.broken
 
@@ -136,16 +169,11 @@ sfmt_import () {
 
        t-dgit $dgitargs import-dsc ../$dscf +$branch
        git checkout $branch
+       git reset --hard
 
-       for f in af/*; do
-               git cat-file blob "refs/heads/$branch:$f" \
-                       | sha256sum \
-                       | sed -e 's#-$#'$f'#' \
-               >>../$sums
-       done
+       sums_check
 
        cd ..
-       diff -U0 sums $sums
 }
 
 : ----- generate the orig -----