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