chiark / gitweb /
autopkgtests: fetch-somegit-notlast: new test
[dgit.git] / tests / lib
1 #
2
3 exec 2>&1
4 set -x
5
6 root=`pwd`
7 troot=$root/tests
8 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 tmp=`pwd`
19 export DGIT_TEST_DUMMY_DIR=$tmp
20 ln $troot/ssh ssh
21
22 mkdir $tmp/gnupg
23 cp $troot/gnupg/* $tmp/gnupg
24 chmod go-rw $tmp/gnupg/*
25 export GNUPGHOME=$tmp/gnupg
26
27 mkdir $tmp/incoming
28 cat <<END >$tmp/dput.cf
29 [test-dummy]
30 method                  = local
31 incoming                = $tmp/incoming
32 run_dinstall            = 0
33 END
34
35 t-worktree () {
36         rm -rf $p
37         tar xf $troot/worktrees/${p}_$1.tar
38 }
39
40 t-git () {
41         p=$1
42         v=$2
43         mkdir -p $tmp/git
44         (set -e; cd $tmp/git; tar xf $troot/git-srcs/${p}_$v.git.tar)
45 }
46
47 t-git-none () {
48         mkdir -p $tmp/git
49         (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
50 }
51
52 t-has-ancestor () {
53         local now=`git rev-parse HEAD`
54         local ancestor=`git rev-parse $1^{}`
55         local mbase=`git merge-base $ancestor $now`
56         if [ x$mbase != x$ancestor ]; then
57                 echo "not ff $ancestor..$now, $mbase != $ancestor"
58                 exit 1
59         fi
60 }       
61
62 t-archive-none () {
63         p=$1
64         mkdir -p $tmp/aq $tmp/mirror
65         echo sid >$tmp/aq/suite.unstable
66 }
67
68 t-archive () {
69         t-archive-none $1
70         v=$2
71         local dscf=${p}_$2.dsc
72         rm -f $tmp/mirror/${p}_*
73         ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/
74         echo "$2 $dscf" >>$tmp/aq/package.sid.${p}
75         rm -rf $tmp/extract
76         mkdir $tmp/extract
77         (set -e; cd $tmp/extract; dpkg-source -x ../mirror/$dscf)
78 }
79
80 t-dgit () {
81         : '{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
82         ${DGIT_TEST-dgit} --dget:-u --dput:--config=$tmp/dput.cf \
83                 -dtest-dummy -D -k39B13D8A "$@"
84         : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}'
85 }
86
87 t-diff-nogit () {
88         diff --exclude=.git -ruN $*
89 }
90
91 t-cloned-fetched-good () {
92         t-diff-nogit ../extract/$p-${v%-*} .
93         t-clean-on-branch dgit/sid
94         t-refs-same \
95                 refs/heads/dgit/sid \
96                 refs/remotes/dgit/dgit/sid
97         t-refs-notexist dgit/unstable remotes/dgit/dgit/unstable
98 }
99
100 t-output () {
101         printf "%s\n" "$1" >$tmp/t.want
102         shift
103         "$@" >$tmp/t.got
104         diff $tmp/t.want $tmp/t.got
105 }
106
107 t-clean-on-branch () {
108         t-output "## $1" git status -b --porcelain
109 }
110
111 t-git-get-ref () {
112         local ref=$1
113         git show-ref -d $1 | perl -ne '
114                 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
115                 END { print "$x\n" if length $x; }
116         '
117 }
118
119 t-refs-same () {
120         local f=$1
121         t-git-get-ref $f >$tmp/t.ref1
122         t-refs-same-more "$@"
123 }
124
125 t-refs-same-more () {
126         local g
127         for g in $*; do
128                 t-git-get-ref $g >$tmp/t.refn
129                 diff $tmp/t.ref1 $tmp/t.refn
130         done
131 }
132
133 t-refs-notexist () {
134         for g in $*; do
135                 t-git-get-ref $g >$tmp/t.refx
136                 diff /dev/null $tmp/t.refx
137         done
138 }
139
140 t-v-tag () {
141         echo refs/tags/debian/${v//\~/_}
142 }
143
144 t-pushed-good () {
145         local branch=$1
146         t-ref-dsc-dgit
147         t-refs-same-more \
148                 refs/heads/$branch \
149                 `t-v-tag` \
150                 refs/remotes/dgit/dgit/sid
151         t-refs-notexist \
152                 refs/heads/dgit/unstable \
153                 refs/remotes/dgit/dgit/unstable
154         (set -e; cd $tmp/git/$p.git
155          t-refs-same-more \
156                 refs/dgit/sid \
157                 `t-v-tag`
158          t-refs-notexist \
159                 refs/dgit/unstable
160         )
161         git verify-tag `t-v-tag`
162 }
163
164 t-ref-dsc-dgit () {
165         perl -e '
166                 use Dpkg::Control::Hash;
167                 my $h = new Dpkg::Control::Hash allow_pgp=>1;
168                 $h->parse(\*STDIN,"dsc");
169                 my $ref = $h->{"Dgit"},"\n";
170                 die unless $ref =~ m/^\w+\b/;
171                 print $ref,"\n";
172         ' <$tmp/incoming/${p}_${v}.dsc >$tmp/t.ref1
173 }
174
175 t-apply-diff () {
176         local v1=$1
177         local v2=$2
178         (cd $troot/pkg-srcs; debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc) \
179                 | patch -p1 -u
180 }