chiark / gitweb /
test suite: gitattributes: Break out t-dgit-warn-check
[dgit.git] / tests / tests / gitattributes
1 #!/bin/bash
2 set -e
3 . tests/lib
4
5 t-dependencies bsdgames
6 t-dependencies man-db git-man
7 t-tstunt-parsechangelog
8
9 t-archive-none example
10 t-git-none
11 bv=1.0
12 t-worktree $bv
13
14 : ----- prepare badnesses -----
15
16 mkdir af
17
18 badattr1 () {
19         local filename=$1
20         local attrspec=$2
21         echo >>af/$filename "Test file with $attrspec"
22         printf >>af/$filename 'crlf: \r\n'
23         echo >>af/$filename 'id $Id: $'
24         echo >>af/$filename 'id $Id: SPLARK $'
25         echo >>gitattrs "af/$filename" "$attrspec"
26 }
27
28 badattr () {
29         attrname=$1; shift
30         badattr1 $attrname-set $attrname
31         badattr1 $attrname-unset -$attrname
32         badattr1 $attrname-unspec \!$attrname
33         local val
34         for val in "$@"; do
35                 badattr1 $attrname=$val $attrname=$val
36         done
37 }
38
39 # xxx want to make each of these files into a quilt patch
40
41 t-git-config core.eol crlf
42
43 badattr text auto
44 badattr eol lf crlf
45 badattr ident
46
47 t-git-config filter.dgit-test-crazy-f.smudge '/usr/games/rot13 2'
48 t-git-config filter.dgit-test-crazy-f.clean  '/usr/games/rot13 24'
49 t-git-config filter.dgit-test-crazy-f.requrired true
50
51 badattr filter dgit-test-crazy-f
52
53 badattr diff
54 badattr merge text binary union
55 badattr whitespace
56 badattr export-ignore
57 badattr export-subst
58 badattr delta
59 badattr encoding no-such-encoding
60
61 man gitattributes \
62 | perl -ne 'print $1,"\n" if m/^ *(\w[-a-z]*)$/' \
63 > grepped-attrs
64
65 exec <grepped-attrs
66 while read attr; do
67         badattr $attr
68 done
69
70 sha256sum af/* >sums
71
72 # ----- common to source formats -----
73
74 sfmt_setup () {
75         v=$1
76         sfmt=$2
77
78         pdb=$p.$sfmt
79
80         local addpatch=${sfmt}_addpatch
81         local convert=${sfmt}_convert
82
83         cp -a $p $pdb-edit
84         cd $pdb-edit
85
86         $convert
87
88         dch -v $v -m convert
89
90         rm -rf .git
91
92         cp ../gitattrs .gitattributes
93         $addpatch gitattrs
94
95         cp -a ../af .
96         $addpatch files
97
98         cp ../sums .
99         $addpatch sums
100
101         dpkg-source -b .
102
103         cd ..
104 }
105
106 sums_check () {
107         # caller should cd into working directory, set
108         #   $sums  $branch
109         # and check out $branch
110
111         sha256sum af/* >../$sums.checkout
112         diff -U0 ../sums ../$sums.checkout
113
114         for f in af/*; do
115                 git cat-file blob "refs/heads/$branch:$f" \
116                         | sha256sum \
117                         | sed -e 's#-$#'$f'#' \
118                 >>../$sums
119         done
120
121         diff -U0 ../sums ../$sums
122 }
123
124 t-dgit-warn-check () {
125         local warnok=$1; shift
126         # warnok should be  0 if the warning is expected
127         #                   1 if the warning is NOT expected
128
129         local err=stderr.$wd
130
131         LC_MESSAGES=C t-dgit "$@" 2>&1 |tee ../$err
132
133         set +e
134         fgrep 'warning: source tree contains .gitattributes' ../$err
135         rc=$?
136         set -e
137
138         test "$rc" = "$warnok"
139 }
140
141 sfmt_import () {
142         inst=$1
143         dgitargs=$2
144         branch="import.$sfmt-$inst"
145         dscf=${p}_${v}.dsc
146         sums=sums.$sfmt-$inst
147         wd=$pdb-import-$inst
148
149         mkdir $wd
150         cd $wd
151         git init
152
153         t-dgit-warn-check 0 $dgitargs import-dsc ../$dscf +$branch.broken
154
155         git checkout $branch.broken
156         sha256sum af/* >../$sums.broken
157
158         for s in ../sums ../$sums.broken; do
159                 sed 's/[0-9a-f]* //' $s >$s.nosums
160         done
161         diff -U0 ../sums.nosums ../$sums.broken.nosums
162         set +e
163         diff -U0 ../sums ../$sums.broken
164         rc=$?
165         set -e
166         test $rc = 1
167
168         t-dgit setup-new-tree
169
170         t-dgit $dgitargs import-dsc ../$dscf +$branch
171         git checkout $branch
172         git reset --hard
173
174         sums_check
175
176         cd ..
177 }
178
179 : ----- generate the orig -----
180
181 origtar=${p}_${bv}.orig.tar.gz
182
183 tar --exclude=debian --exclude=.git -zcf $origtar $p
184
185 : ----- test 1.0 native -----
186
187 native_addpatch () { :; }
188 native_convert () { :; }
189
190 sfmt_setup 1.1 native
191 sfmt_import norm
192
193 : ----- test 1.0 diff -----
194
195 diff_addpatch () { :; }
196 diff_convert () { :; }
197
198 sfmt_setup 1.1 diff
199 sfmt_import norm
200
201 : ----- test "3.0 (quilt)" -----
202
203 quilt_addpatch () {
204         pname=$1
205         cat >../editor.pl <<END
206                 next if m/^$/..0;
207                 s{^(description:).*}{\$1 dgit test patch $pname}i;
208                 \$_='' if m/^ /;
209 END
210         EDITOR="perl -pi $tmp/editor.pl" dpkg-source -iX --commit . $pname
211         test -f debian/patches/$pname
212 }
213
214 quilt_convert () {
215         mkdir -p debian/source
216         echo '3.0 (quilt)' >debian/source/format
217 }
218
219 sfmt_setup 1.0-1 quilt
220 sfmt_import norm
221 sfmt_import absurd --force-import-gitapply-absurd
222
223 #t-ok