chiark / gitweb /
Turn off debug for wrong tree test
[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 () {
86         t-archive-none $1
87         v=$2
88         local dscf=${p}_$2.dsc
89         rm -f $tmp/mirror/${p}_*
90         ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/
91         echo "$2 $dscf" >>$tmp/aq/package.sid.${p}
92         rm -rf $tmp/extract
93         mkdir $tmp/extract
94         (set -e; cd $tmp/extract; dpkg-source -x ../mirror/$dscf)
95 }
96
97 t-dgit () {
98         : '
99
100 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
101         ${DGIT_TEST-dgit} --dget:-u --dput:--config=$tmp/dput.cf \
102                 -dtest-dummy $DGIT_TEST_OPTS ${DGIT_TEST_DEBUG--D} \
103                 -k39B13D8A "$@"
104         : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
105 '
106 }
107
108 t-diff-nogit () {
109         diff --exclude=.git -ruN $*
110 }
111
112 t-cloned-fetched-good () {
113         t-diff-nogit ../extract/$p-${v%-*} .
114         t-clean-on-branch dgit/sid
115         t-refs-same-start
116         t-refs-same \
117                 refs/heads/dgit/sid \
118                 refs/remotes/dgit/dgit/sid
119         t-refs-notexist dgit/unstable remotes/dgit/dgit/unstable
120 }
121
122 t-output () {
123         printf "%s\n" "$1" >$tmp/t.want
124         shift
125         "$@" >$tmp/t.got
126         diff $tmp/t.want $tmp/t.got
127 }
128
129 t-clean-on-branch () {
130         t-output "## $1" git status -b --porcelain
131 }
132
133 t-git-get-ref () {
134         local ref=$1
135         git show-ref -d $1 | perl -ne '
136                 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
137                 END { print "$x\n" if length $x; }
138         '
139 }
140
141 t-ref-same () {
142         local name="$1"
143         local val=`t-git-get-ref $name`
144         t-ref-same-val "$name" $val
145 }
146
147 t-ref-head () {
148         local val=`git rev-parse HEAD`
149         t-ref-same-val HEAD $val
150 }
151
152 t-ref-same-val () {
153         local name="$1"
154         local val=$2
155         case "$t_ref_val" in
156         '')             ;;
157         "$val")         ;;
158         *)              fail "ref varies: $name: $val != $t_ref_val" ;;
159         esac
160         t_ref_val="$val"
161 }
162
163 t-refs-same-start () {
164         t_ref_val=''
165 }
166
167 t-refs-same () {
168         local g
169         for g in $*; do
170                 t-ref-same $g
171         done
172 }
173
174 t-refs-notexist () {
175         local val
176         for g in $*; do
177                 val=`t-git-get-ref $g >$tmp/t.refx`
178                 if [ "x$val" != x ]; then
179                         fail "ref $g unexpectedly exists ($val)"
180                 fi
181         done
182 }
183
184 t-v-tag () {
185         echo refs/tags/debian/${v//\~/_}
186 }
187
188 t-pushed-good () {
189         local branch=$1
190         t-ref-dsc-dgit
191         t-refs-same \
192                 refs/heads/$branch \
193                 `t-v-tag` \
194                 refs/remotes/dgit/dgit/sid
195         t-refs-notexist \
196                 refs/heads/dgit/unstable \
197                 refs/remotes/dgit/dgit/unstable
198         (set -e; cd $tmp/git/$p.git
199          t-refs-same \
200                 refs/dgit/sid \
201                 `t-v-tag`
202          t-refs-notexist \
203                 refs/dgit/unstable
204         )
205         git verify-tag `t-v-tag`
206 }
207
208 t-822-field () {
209         local file=$1
210         local field=$2
211         perl -e '
212                 use Dpkg::Control::Hash;
213                 my $h = new Dpkg::Control::Hash allow_pgp=>1;
214                 $h->parse(\*STDIN,"'"$file"'");
215                 my $val = $h->{"'$field'"},"\n";
216                 die "'"$file $field"'" unless defined $val;
217                 print $val,"\n";
218         ' <$file
219 }
220
221 t-ref-dsc-dgit () {
222         local dsc=${p}_${v}.dsc
223         local val=`t-822-field $tmp/incoming/$dsc Dgit`
224         perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
225         t-ref-same-val $dsc "$val"
226 }
227
228 t-apply-diff () {
229         local v1=$1
230         local v2=$2
231         (cd $troot/pkg-srcs; debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc) \
232                 | patch -p1 -u
233 }
234
235 t-git-config () {
236         git config --global "$@"
237 }
238
239 t-drs () {
240         export DGIT_TEST_TROOT=$troot
241         export DGIT_TEST_TMP=$tmp
242  t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
243  t-git-config dgit-distro.test-dummy.git-check true
244  t-git-config dgit-distro.test-dummy.git-create true
245         cp $root/tests/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
246         cp $root/tests/suites $tmp/.
247 }
248
249 t-drs-test () {
250         t-drs
251         cd $root
252         export DGIT_TEST_TESTNAME="$testname"
253         export ADTTMP=$tmp
254         exec "${0///drs-//}" "$@"
255 }