chiark / gitweb /
test suite: gitattributes: Check that warning does not appear when unexpected
[dgit.git] / tests / tests / gitattributes
index a00c1d3667482732aa4781b5395dfcc10d110bfb..dec85b56ee6d32db5085acb5059d28f632901e75 100755 (executable)
@@ -104,8 +104,12 @@ sfmt_setup () {
 }
 
 sums_check () {
-       # caller should cd into working directory and set
+       # 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" \
@@ -117,22 +121,37 @@ sums_check () {
        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
 
@@ -148,8 +167,9 @@ sfmt_import () {
 
        t-dgit setup-new-tree
 
-       t-dgit $dgitargs import-dsc ../$dscf +$branch
+       t-dgit-warn-check 1 $dgitargs import-dsc ../$dscf +$branch
        git checkout $branch
+       git reset --hard
 
        sums_check