chiark / gitweb /
Bugfixes (now tests/tests/drs-clone-nogit works)
[dgit.git] / tests / lib
1 #
2
3 exec 2>&1
4 set -x
5
6 if [ "x$DGIT_TEST_INTREE" != x ]; then
7         : ${DGIT_TEST:=$DGIT_TEST_INTREE/dgit}
8         : ${DGIT_REPOS_SERVER_TEST:=$DGIT_TEST_INTREE/infra/dgit-repos-server}
9         : ${DGIT_SSH_DISPATCH_TEST:=$DGIT_TEST_INTREE/infra/dgit-ssh-dispatch}
10         export DGIT_TEST DGIT_REPOS_SERVER_TEST DGIT_SSH_DISPATCH_TEST
11 fi
12
13 root=`pwd`
14 troot=$root/tests
15 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
16
17 tmp=$ADTTMP
18 if [ x"$tmp" = x ]; then
19         mkdir -p tests/tmp
20         tmp=tests/tmp/$testname
21         rm -rf $tmp
22         mkdir $tmp
23 fi
24 cd $tmp
25 export HOME=$tmp
26
27 tmp=`pwd`
28 export DGIT_TEST_DUMMY_DIR=$tmp
29 ln -f $troot/ssh ssh
30
31 mkdir -p $tmp/gnupg
32 cp $troot/gnupg/* $tmp/gnupg
33 chmod go-rw $tmp/gnupg/*
34 export GNUPGHOME=$tmp/gnupg
35
36 mkdir -p $tmp/incoming
37 cat <<END >$tmp/dput.cf
38 [test-dummy]
39 method                  = local
40 incoming                = $tmp/incoming
41 run_dinstall            = 0
42 END
43
44 fail () {
45         echo >&2 "failed: $*"
46         exit 1
47 }
48
49 t-untar () {
50         local tarfile=$1.tar
51         local edittree=$1.edit
52         if test -d "$edittree"; then
53                 cp -al "$edittree"/* .
54         else
55                 tar xf "$tarfile"
56         fi
57 }
58
59 t-worktree () {
60         rm -rf $p
61         t-untar $troot/worktrees/${p}_$1
62 }
63
64 t-git () {
65         p=$1
66         v=$2
67         mkdir -p $tmp/git
68         local gs=$troot/git-srcs/${p}_$v.git
69         (set -e; cd $tmp/git; t-untar $gs)
70 }
71
72 t-git-none () {
73         mkdir -p $tmp/git
74         (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
75 }
76
77 t-has-ancestor () {
78         local now=`git rev-parse HEAD`
79         local ancestor=`git rev-parse $1^{}`
80         local mbase=`git merge-base $ancestor $now`
81         if [ x$mbase != x$ancestor ]; then
82                 fail "not ff $ancestor..$now, $mbase != $ancestor"
83         fi
84 }       
85
86 t-archive-none () {
87         p=$1
88         mkdir -p $tmp/aq $tmp/mirror
89         echo sid >$tmp/aq/suite.unstable
90 }
91
92 t-archive-process-incoming () {
93         mv incoming/${p}_${v}[._]* mirror/
94         t-archive-query
95 }
96
97 t-archive-query () {
98         local dscf=${p}_${v}.dsc
99         echo "${v} $dscf" >>$tmp/aq/package.sid.${p}
100 }
101
102 t-archive () {
103         t-archive-none $1
104         v=$2
105         local dscf=${p}_$2.dsc
106         rm -f $tmp/mirror/${p}_*
107         ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/
108         t-archive-query
109         rm -rf $tmp/extract
110         mkdir $tmp/extract
111         (set -e; cd $tmp/extract; dpkg-source -x ../mirror/$dscf)
112 }
113
114 t-dgit () {
115         local dgit=${DGIT_TEST-dgit}
116         : '
117 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
118         $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
119                 -dtest-dummy $DGIT_TEST_OPTS ${DGIT_TEST_DEBUG--D} \
120                 -k39B13D8A "$@"
121         : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
122 '
123 }
124
125 t-diff-nogit () {
126         diff --exclude=.git --exclude=.pc -ruN $*
127 }
128
129 t-cloned-fetched-good () {
130         t-diff-nogit ../extract/$p-${v%-*} .
131         t-clean-on-branch dgit/sid
132         t-refs-same-start
133         t-refs-same \
134                 refs/heads/dgit/sid \
135                 refs/remotes/dgit/dgit/sid
136         t-refs-notexist dgit/unstable remotes/dgit/dgit/unstable
137 }
138
139 t-output () {
140         printf "%s\n" "$1" >$tmp/t.want
141         shift
142         "$@" >$tmp/t.got
143         diff $tmp/t.want $tmp/t.got
144 }
145
146 t-clean-on-branch () {
147         t-output "## $1" git status -b --porcelain
148 }
149
150 t-git-get-ref () {
151         local ref=$1
152         git show-ref -d $1 | perl -ne '
153                 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
154                 END { print "$x\n" if length $x; }
155         '
156 }
157
158 t-ref-same () {
159         local name="$1"
160         local val=`t-git-get-ref $name`
161         t-ref-same-val "$name" $val
162 }
163
164 t-ref-head () {
165         local val=`git rev-parse HEAD`
166         t-ref-same-val HEAD $val
167 }
168
169 t-ref-same-val () {
170         local name="$1"
171         local val=$2
172         case "$t_ref_val" in
173         '')             ;;
174         "$val")         ;;
175         *)              fail "ref varies: $name: $val != $t_ref_val" ;;
176         esac
177         t_ref_val="$val"
178 }
179
180 t-refs-same-start () {
181         t_ref_val=''
182 }
183
184 t-refs-same () {
185         local g
186         for g in $*; do
187                 t-ref-same $g
188         done
189 }
190
191 t-refs-notexist () {
192         local val
193         for g in $*; do
194                 val=`t-git-get-ref $g >$tmp/t.refx`
195                 if [ "x$val" != x ]; then
196                         fail "ref $g unexpectedly exists ($val)"
197                 fi
198         done
199 }
200
201 t-v-tag () {
202         echo refs/tags/debian/${v//\~/_}
203 }
204
205 t-pushed-good () {
206         local branch=$1
207         t-ref-dsc-dgit
208         t-refs-same \
209                 refs/heads/$branch \
210                 `t-v-tag` \
211                 refs/remotes/dgit/dgit/sid
212         t-refs-notexist \
213                 refs/heads/dgit/unstable \
214                 refs/remotes/dgit/dgit/unstable
215         (set -e; cd $tmp/git/$p.git
216          t-refs-same \
217                 refs/dgit/sid \
218                 `t-v-tag`
219          t-refs-notexist \
220                 refs/dgit/unstable
221         )
222         git verify-tag `t-v-tag`
223 }
224
225 t-822-field () {
226         local file=$1
227         local field=$2
228         perl -e '
229                 use Dpkg::Control::Hash;
230                 my $h = new Dpkg::Control::Hash allow_pgp=>1;
231                 $h->parse(\*STDIN,"'"$file"'");
232                 my $val = $h->{"'$field'"},"\n";
233                 die "'"$file $field"'" unless defined $val;
234                 print $val,"\n";
235         ' <$file
236 }
237
238 t-ref-dsc-dgit () {
239         local dsc=${p}_${v}.dsc
240         local val=`t-822-field $tmp/incoming/$dsc Dgit`
241         perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
242         t-ref-same-val $dsc "$val"
243 }
244
245 t-apply-diff () {
246         local v1=$1
247         local v2=$2
248         (cd $troot/pkg-srcs; debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc) \
249                 | patch -p1 -u
250 }
251
252 t-git-config () {
253         git config --global "$@"
254 }
255
256 t-drs () {
257         export DGIT_TEST_TROOT=$troot
258         export DGIT_TEST_TMP=$tmp
259  t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
260  t-git-config dgit-distro.test-dummy.git-check true
261  t-git-config dgit-distro.test-dummy.git-create true
262         cp $root/tests/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
263         cp $root/tests/suites $tmp/.
264         ln -s /bin/true $tmp/policy
265 }
266
267 t-dss () {
268         t-drs
269  t-git-config dgit-distro.test-dummy.ssh "$troot/dss-ssh"
270  t-git-config dgit-distro.test-dummy.git-check ssh-cmd
271  t-git-config dgit-distro.test-dummy.git-create true
272  t-git-config dgit-distro.test-dummy.git-url \
273                 "ext::$troot/dss-ssh X %S /dgit/test-dummy/repos"
274
275  t-git-config dgit-distro.test-dummy.diverts.drs /drs
276  t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
277  t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
278  t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
279  t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
280
281         dss_dispatch=$tmp/dispatch-dir/distro=test-dummy
282         mkdir -p $dss_dispatch
283         ln -sf $root $dss_dispatch/dgit-live
284         ln -sf $tmp/git $dss_dispatch/repos
285         ln -sf $tmp/suites $tmp/dm.txt $dss_dispatch/
286         mkdir -p $dss_dispatch/keyrings
287         ln -sf $tmp/dd.gpg $dss_dispatch/keyrings/debian-keyring.gpg
288         ln -sf $tmp/dm.gpg $dss_dispatch/keyrings/debian-maintainers.gpg
289
290         echo 'no-such-package* drs' >$dss_dispatch/diverts
291 }
292
293 t-chain-test () {
294         local ct=$1
295         local d=${0%/*}
296         cd $root
297         export DGIT_TEST_TESTNAME="$testname"
298         export ADTTMP=$tmp
299         exec "$d/$ct"
300 }       
301
302 t-alt-test () {
303         local t=${0##*/}
304         t-${t%%-*}
305         t-chain-test "${t#*-}"
306 }