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