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 export DEBCHANGE_VENDOR=dpkg
39 mkdir -p $tmp/incoming
40 cat <<END >$tmp/dput.cf
43 incoming = $tmp/incoming
48 local mpat="$1"; shift
51 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
52 local ps="${PIPESTATUS[*]}"
56 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
58 *) fail "tee failed" ;;
67 *) fail "bad mpat prefix in $mpat";;
73 $grepper -e "$mpat" $tmp/t.output ||
74 fail "error message not found"
77 t-expect-push-fail () {
78 local mpat="$1"; shift
80 local triedpush=`git rev-parse HEAD`
83 t-expect-fail "$mpat" "$@"
85 diff $tmp/show-refs.{pre,post}-push
87 t-git-objects-not-present '' $triedpush
89 eval "$t_expect_push_fail_hook"
92 t-git-objects-not-present () {
93 # t-git-objects-not-present GITDIR|'' OBJID [...]
94 # specifying '' means the repo for package $p
95 local gitdir="${1-$dgitrepo}"
97 if ! [ -e "$gitdir" ]; then return; fi
100 t-expect-fail 'unable to find' \
106 local whichoutput=$1; shift
107 local outputfile="$tmp/show-refs.$whichoutput"
110 if test -d $dgitrepo; then
118 local edittree=$1.edit
119 if test -d "$edittree"; then
120 cp -al "$edittree"/* .
128 t-untar $troot/worktrees/${p}_$1
131 t-select-package () {
133 dgitrepo=$tmp/git/$p.git
140 local gs=$troot/git-srcs/${p}_$v.git
141 (set -e; cd $tmp/git; t-untar $gs)
146 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
149 t-git-merge-base () {
150 git merge-base $1 $2 || test $? = 1
154 local now=`git rev-parse HEAD`
155 local ancestor=`git rev-parse $1^{}`
156 local mbase=`t-git-merge-base $ancestor $now`
157 if [ x$mbase != x$ancestor ]; then
158 fail "not ff $ancestor..$now, $mbase != $ancestor"
162 t-prep-newpackage () {
169 if ! git show-ref --verify --quiet refs/heads/master; then
170 git branch -m dgit/sid master
178 mkdir -p $tmp/aq $tmp/mirror/pool/main
182 >$tmp/aq/package.$suite.$p
183 t-archive-updated $suite $p
185 >$tmp/aq/package.new.$p
186 t-archive-updated new $p
188 ln -s sid $tmp/aq/dsc_in_suite/unstable
189 cat <<'END' >$tmp/aq/suites
192 "archive" : "ftp-master",
200 "dakname" : "unstable"
206 t-archive-updated () {
209 local suitedir=$tmp/aq/dsc_in_suite/$suite
211 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
215 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
223 print to_json \@v or die $!;
228 t-archive-process-incoming () {
230 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
231 t-archive-query "$suite"
236 local dscf=main/${p}_${v}.dsc
237 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
238 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
239 t-archive-updated $suite $p
245 local dscf=${p}_$2.dsc
246 rm -f $tmp/mirror/pool/main/${p}_*
247 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
251 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
254 t-git-dir-time-passes () {
255 touch -d 'last year' $dgitrepo
259 local gitdir=$dgitrepo
262 if test -e "$gitdir"; then fail "$gitdir exists"; fi
265 public) wantstat='7[75]5' ;;
266 secret) wantstat='7[70]0' ;;
267 *) fail "$1 t-git-dir-check ?" ;;
269 gotstat=`stat -c%a $gitdir`
271 *$wantstat) return ;;
272 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
276 t-rm-dput-dropping () {
277 rm -f $tmp/${p}_${v}_*.upload
281 local dgit=${DGIT_TEST-dgit}
284 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
285 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
286 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
288 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
293 diff --exclude=.git --exclude=.pc -ruN $*
296 t-cloned-fetched-good () {
297 t-diff-nogit ../extract/$p-${v%-*} .
298 t-clean-on-branch dgit/sid
301 refs/heads/dgit/sid \
302 refs/remotes/dgit/dgit/sid
303 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
307 printf "%s\n" "$1" >$tmp/t.want
310 diff $tmp/t.want $tmp/t.got
313 t-clean-on-branch () {
314 t-output "## $1" git status -b --porcelain
317 t-git-get-ref-exact () {
319 # does not dereference, unlike t-git-get-ref
322 *) fail "t-git-get-ref-exact bad $ref" ;;
324 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
331 *) fail "t-git-get-ref bad $ref" ;;
333 (git show-ref -d $1 || test $? = 1) | perl -ne '
334 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
335 END { print "$x\n" if length $x; }
339 t-ref-same-exact () {
341 local val=`t-git-get-ref-exact $name`
342 t-ref-same-val "$name" $val
347 local val=`t-git-get-ref $name`
348 t-ref-same-val "$name" $val
352 local val=`git rev-parse HEAD`
353 t-ref-same-val HEAD $val
362 *) fail "ref varies: $name: $val != $t_ref_val" ;;
367 t-refs-same-start () {
381 val=`t-git-get-ref $g`
382 if [ "x$val" != x ]; then
383 fail "ref $g unexpectedly exists ($val)"
389 echo refs/tags/test-dummy/${v//\~/_}
392 t-check-pushed-master () {
393 local master=`t-git-get-ref refs/heads/master`
394 if [ x$master = x$t_ref_val ]; then return; fi
395 if [ x$master = x ]; then fail "failed to push master"; fi
396 # didn't update master, it must be not FF
397 local mbase=`t-git-merge-base $master $t_ref_val`
398 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
407 refs/remotes/dgit/dgit/sid
409 refs/heads/dgit/unstable \
410 refs/remotes/dgit/dgit/unstable
411 (set -e; cd $dgitrepo
415 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
419 git verify-tag `t-v-tag`
426 use Dpkg::Control::Hash;
427 my $h = new Dpkg::Control::Hash allow_pgp=>1;
428 $h->parse(\*STDIN,"'"$file"'");
429 my $val = $h->{"'$field'"},"\n";
430 die "'"$file $field"'" unless defined $val;
442 *) '$var'="$tstunt:$'$var'" ;;
448 local tstunt=$tmp/tstunt
449 t-stunt-envvar PATH $tstunt
450 t-stunt-envvar PERLLIB $tstunt
454 local d="$tstunt/${f%/*}"
456 ln -sf "$troot/tstunt/$f" "$d"/.
460 t-tstunt-parsechangelog () {
461 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
465 local dsc=${p}_${v}.dsc
466 local val=`t-822-field $tmp/incoming/$dsc Dgit`
467 perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
468 t-ref-same-val $dsc "$val"
475 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
482 dch -v$v --distribution unstable "$1"
483 git add debian/changelog
485 revision=$(( ${revision-0} + 1 ))
489 git config --global "$@"
493 export DGIT_TEST_TROOT=$troot
494 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
495 t-git-config dgit-distro.test-dummy.git-check true
496 t-git-config dgit-distro.test-dummy.git-create true
497 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
498 cp $troot/suites $tmp/.
499 cp $troot/suites $tmp/suites-master
501 export t_check_pushed_master=t-check-pushed-master
503 drs_dispatch=$tmp/distro=test-dummy
506 if [ "x$DGIT_TEST_INTREE" != x ]; then
507 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
510 ln -sf $tmp/git $drs_dispatch/repos
511 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
512 mkdir -p $drs_dispatch/keyrings
513 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
514 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
515 ln -sf /bin/true $drs_dispatch/policy-hook
520 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
521 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
522 t-git-config dgit-distro.test-dummy.git-create true
523 t-git-config dgit-distro.test-dummy.git-url \
524 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
526 t-git-config dgit-distro.test-dummy.diverts.drs /drs
527 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
528 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
529 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
530 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
532 echo 'no-such-package* drs' >$drs_dispatch/diverts
536 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
539 t-policy-nonexist () {
540 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
545 policyhook=${DGIT_INFRA_PFX}$policyhook
548 *) policyhook=`type -P $policyhook` ;;
550 ln -sf "$policyhook" $drs_dispatch/policy-hook
555 t-policy dgit-repos-policy-debian
558 t-policy-admin create-db
561 t-policy-periodic () {
562 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
563 test-dummy $drs_dispatch '' --cron
570 export DGIT_TEST_TESTNAME="$testname"
578 t-chain-test "${t#*-}"