11 : ${DGIT_TEST_DEBUG:=-D}
12 export DGIT_TEST_DEBUG
16 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
19 if [ x"$tmp" = x ]; then
21 tmp=tests/tmp/$testname
34 cp $troot/gnupg/* $tmp/gnupg
35 chmod go-rw $tmp/gnupg/*
37 mkdir -p $tmp/incoming
38 cat <<END >$tmp/dput.cf
41 incoming = $tmp/incoming
46 local mpat="$1"; shift
54 *) fail "bad mpat prefix in $mpat";;
61 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
62 local ps="${PIPESTATUS[*]}"
66 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
68 *) fail "tee failed" ;;
71 $grepper -e "$mpat" $tmp/t.output ||
72 fail "error message not found"
75 t-expect-push-fail () {
76 local mpat="$1"; shift
78 local triedpush=`git rev-parse HEAD`
81 t-expect-fail "$mpat" "$@"
83 diff $tmp/show-refs.{pre,post}-push
85 t-git-objects-not-present '' $triedpush
87 eval "$t_expect_push_fail_hook"
90 t-git-objects-not-present () {
91 # t-git-objects-not-present GITDIR|'' OBJID [...]
92 # specifying '' means the repo for package $p
93 local gitdir="${1-$tmp/git/$p.git}"
95 if ! [ -e "$gitdir" ]; then return; fi
98 t-expect-fail 'unable to find' \
104 local whichoutput=$1; shift
105 local outputfile="$tmp/show-refs.$whichoutput"
108 if test -d $tmp/git/$p.git; then
116 local edittree=$1.edit
117 if test -d "$edittree"; then
118 cp -al "$edittree"/* .
126 t-untar $troot/worktrees/${p}_$1
133 local gs=$troot/git-srcs/${p}_$v.git
134 (set -e; cd $tmp/git; t-untar $gs)
139 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
143 local now=`git rev-parse HEAD`
144 local ancestor=`git rev-parse $1^{}`
145 local mbase=`git merge-base $ancestor $now`
146 if [ x$mbase != x$ancestor ]; then
147 fail "not ff $ancestor..$now, $mbase != $ancestor"
151 t-prep-newpackage () {
158 if ! git-show-ref --verify --quiet refs/heads/master; then
159 git branch -m dgit/sid master
167 mkdir -p $tmp/aq $tmp/mirror/pool/main
171 >$tmp/aq/package.$suite.$p
172 t-archive-updated $suite $p
174 >$tmp/aq/package.new.$p
175 t-archive-updated new $p
177 ln -s sid $tmp/aq/dsc_in_suite/unstable
178 cat <<'END' >$tmp/aq/suites
181 "archive" : "ftp-master",
189 "dakname" : "unstable"
195 t-archive-updated () {
198 local suitedir=$tmp/aq/dsc_in_suite/$suite
200 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
204 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
212 print to_json \@v or die $!;
217 t-archive-process-incoming () {
219 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
220 t-archive-query "$suite"
225 local dscf=main/${p}_${v}.dsc
226 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
227 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
228 t-archive-updated $suite $p
234 local dscf=${p}_$2.dsc
235 rm -f $tmp/mirror/pool/main/${p}_*
236 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
240 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
243 t-git-dir-time-passes () {
244 touch -d 'last year' $tmp/git/$p.git
248 local gitdir=$tmp/git/$p.git
251 if test -e "$gitdir"; then fail "$gitdir exists"; fi
254 public) wantstat='7[75]5' ;;
255 secret) wantstat='7[70]0' ;;
256 *) fail "$1 t-git-dir-check ?" ;;
258 gotstat=`stat -c%a $gitdir`
260 *$wantstat) return ;;
261 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
265 t-rm-dput-dropping () {
266 rm -f $tmp/${p}_${v}_*.upload
270 local dgit=${DGIT_TEST-dgit}
272 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
273 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
274 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
276 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
281 diff --exclude=.git --exclude=.pc -ruN $*
284 t-cloned-fetched-good () {
285 t-diff-nogit ../extract/$p-${v%-*} .
286 t-clean-on-branch dgit/sid
289 refs/heads/dgit/sid \
290 refs/remotes/dgit/dgit/sid
291 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
295 printf "%s\n" "$1" >$tmp/t.want
298 diff $tmp/t.want $tmp/t.got
301 t-clean-on-branch () {
302 t-output "## $1" git status -b --porcelain
305 t-git-get-ref-exact () {
307 # does not dereference, unlike t-git-get-ref
310 *) fail "t-git-get-ref-exact bad $ref" ;;
312 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
319 *) fail "t-git-get-ref bad $ref" ;;
321 (git show-ref -d $1 || test $? = 1) | perl -ne '
322 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
323 END { print "$x\n" if length $x; }
329 local val=`t-git-get-ref $name`
330 t-ref-same-val "$name" $val
334 local val=`git rev-parse HEAD`
335 t-ref-same-val HEAD $val
344 *) fail "ref varies: $name: $val != $t_ref_val" ;;
349 t-refs-same-start () {
363 val=`t-git-get-ref $g >$tmp/t.refx`
364 if [ "x$val" != x ]; then
365 fail "ref $g unexpectedly exists ($val)"
371 echo refs/tags/debian/${v//\~/_}
380 refs/remotes/dgit/dgit/sid
382 refs/heads/dgit/unstable \
383 refs/remotes/dgit/dgit/unstable
384 (set -e; cd $tmp/git/$p.git
391 git verify-tag `t-v-tag`
398 use Dpkg::Control::Hash;
399 my $h = new Dpkg::Control::Hash allow_pgp=>1;
400 $h->parse(\*STDIN,"'"$file"'");
401 my $val = $h->{"'$field'"},"\n";
402 die "'"$file $field"'" unless defined $val;
414 *) '$var'="$tstunt:$'$var'" ;;
420 local tstunt=$tmp/tstunt
421 t-stunt-envvar PATH $tstunt
422 t-stunt-envvar PERLLIB $tstunt
426 local d="$tstunt/${f%/*}"
428 ln -sf "$troot/tstunt/$f" "$d"/.
432 t-tstunt-parsechangelog () {
433 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
436 t-prep-mergechangelogs () {
437 local b=merge.dpkg-mergechangelogs
438 git config $b.name 'debian/changelog merge driver'
439 git config $b.driver 'dpkg-mergechangelogs -m %O %A %B %A'
441 echo >>.git/info/attributes \
442 'debian/changelog merge=dpkg-mergechangelogs'
446 local dsc=${p}_${v}.dsc
447 local val=`t-822-field $tmp/incoming/$dsc Dgit`
448 perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
449 t-ref-same-val $dsc "$val"
456 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
463 dch -v$v --distribution unstable "$1"
464 git add debian/changelog
466 revision=$(( $revision + 1 ))
470 git config --global "$@"
474 export DGIT_TEST_TROOT=$troot
475 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
476 t-git-config dgit-distro.test-dummy.git-check true
477 t-git-config dgit-distro.test-dummy.git-create true
478 cp $root/tests/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
479 cp $root/tests/suites $tmp/.
481 drs_dispatch=$tmp/distro=test-dummy
483 ln -sf $root $drs_dispatch/dgit-live
484 ln -sf $tmp/git $drs_dispatch/repos
485 ln -sf $tmp/suites $tmp/dm.txt $drs_dispatch/
486 mkdir -p $drs_dispatch/keyrings
487 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
488 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
489 ln -sf /bin/true $drs_dispatch/policy-hook
494 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
495 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
496 t-git-config dgit-distro.test-dummy.git-create true
497 t-git-config dgit-distro.test-dummy.git-url \
498 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
500 t-git-config dgit-distro.test-dummy.diverts.drs /drs
501 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
502 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
503 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
504 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
506 echo 'no-such-package* drs' >$drs_dispatch/diverts
510 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
515 ln -sf ${DGIT_INFRA_PFX}$policyhook \
516 $drs_dispatch/policy-hook
521 t-policy dgit-repos-policy-debian
524 t-policy-admin create-db
527 t-policy-periodic () {
528 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
529 test-dummy $drs_dispatch '' --cron
536 export DGIT_TEST_TESTNAME="$testname"
544 t-chain-test "${t#*-}"