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