12 : ${DGIT_TEST_DEBUG:=-D}
13 export DGIT_TEST_DEBUG
17 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
20 if [ x"$tmp" = x ]; then
22 tmp=tests/tmp/$testname
35 cp $troot/gnupg/* $tmp/gnupg
36 chmod go-rw $tmp/gnupg/*
38 export DEBCHANGE_VENDOR=dpkg
40 mkdir -p $tmp/incoming
41 cat <<END >$tmp/dput.cf
44 incoming = $tmp/incoming
49 local mpat="$1"; shift
52 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
53 local ps="${PIPESTATUS[*]}"
57 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
59 *) fail "tee failed" ;;
62 t-grep-mpat "$mpat" $tmp/t.output
75 *) fail "bad mpat prefix in $mpat";;
81 $grepper -e "$mpat" "$file" ||
82 fail "message not found"
85 t-expect-push-fail () {
86 local mpat="$1"; shift
88 local triedpush=`git rev-parse HEAD`
91 t-expect-fail "$mpat" "$@"
93 diff $tmp/show-refs.{pre,post}-push
95 t-git-objects-not-present '' $triedpush
97 eval "$t_expect_push_fail_hook"
100 t-git-objects-not-present () {
101 # t-git-objects-not-present GITDIR|'' OBJID [...]
102 # specifying '' means the repo for package $p
103 local gitdir="${1-$dgitrepo}"
105 if ! [ -e "$gitdir" ]; then return; fi
108 t-expect-fail 'unable to find' \
114 local whichoutput=$1; shift
115 local whichrepo=${1-$dgitrepo}
116 local outputfile="$tmp/show-refs.$whichoutput"
119 if test -d $whichrepo; then
127 local edittree=$1.edit
128 if test -d "$edittree"; then
129 cp -al "$edittree"/* .
137 t-untar $troot/worktrees/${p}_$1
140 t-select-package () {
142 dgitrepo=$tmp/git/$p.git
149 local gs=$troot/git-srcs/${p}_$v.git
150 (set -e; cd $tmp/git; t-untar $gs)
155 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
158 t-git-merge-base () {
159 git merge-base $1 $2 || test $? = 1
163 local now=`git rev-parse HEAD`
164 local ancestor=`git rev-parse $1^{}`
165 local mbase=`t-git-merge-base $ancestor $now`
166 if [ x$mbase != x$ancestor ]; then
167 fail "not ff $ancestor..$now, $mbase != $ancestor"
171 t-prep-newpackage () {
178 if ! git show-ref --verify --quiet refs/heads/master; then
179 git branch -m dgit/sid master
187 mkdir -p $tmp/aq $tmp/mirror/pool/main
191 >$tmp/aq/package.$suite.$p
192 t-archive-updated $suite $p
194 >$tmp/aq/package.new.$p
195 t-archive-updated new $p
197 ln -s sid $tmp/aq/dsc_in_suite/unstable
198 cat <<'END' >$tmp/aq/suites
201 "archive" : "ftp-master",
209 "dakname" : "unstable"
215 t-archive-updated () {
218 local suitedir=$tmp/aq/dsc_in_suite/$suite
220 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
224 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
232 print to_json \@v or die $!;
237 t-archive-process-incoming () {
239 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
240 t-archive-query "$suite"
245 local dscf=main/${p}_${v}.dsc
246 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
247 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
248 t-archive-updated $suite $p
254 local dscf=${p}_$2.dsc
255 rm -f $tmp/mirror/pool/main/${p}_*
256 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
260 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
263 t-git-dir-time-passes () {
264 touch -d 'last year' $dgitrepo
268 local gitdir=$dgitrepo
271 if test -e "$gitdir"; then fail "$gitdir exists"; fi
274 public) wantstat='7[75]5' ;;
275 secret) wantstat='7[70]0' ;;
276 *) fail "$1 t-git-dir-check ?" ;;
278 gotstat=`stat -c%a $gitdir`
280 *$wantstat) return ;;
281 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
285 t-rm-dput-dropping () {
286 rm -f $tmp/${p}_${v}_*.upload
290 local dgit=${DGIT_TEST-dgit}
293 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
294 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
295 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
297 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
302 diff --exclude=.git --exclude=.pc -ruN $*
305 t-files-notexist () {
314 t-cloned-fetched-good () {
315 t-diff-nogit ../extract/$p-${v%-*} .
316 t-clean-on-branch dgit/sid
319 refs/heads/dgit/sid \
320 refs/remotes/dgit/dgit/sid
321 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
325 printf "%s\n" "$1" >$tmp/t.want
328 diff $tmp/t.want $tmp/t.got
331 t-clean-on-branch () {
332 t-output "## $1" git status -b --porcelain
335 t-git-get-ref-exact () {
337 # does not dereference, unlike t-git-get-ref
340 *) fail "t-git-get-ref-exact bad $ref" ;;
342 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
349 *) fail "t-git-get-ref bad $ref" ;;
351 (git show-ref -d $1 || test $? = 1) | perl -ne '
352 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
353 END { print "$x\n" if length $x; }
357 t-ref-same-exact () {
359 local val=`t-git-get-ref-exact $name`
360 t-ref-same-val "$name" $val
365 local val=`t-git-get-ref $name`
366 t-ref-same-val "$name" $val
370 local val=`git rev-parse HEAD`
371 t-ref-same-val HEAD $val
380 *) fail "ref varies: $name: $val != $t_ref_val" ;;
385 t-refs-same-start () {
399 val=`t-git-get-ref $g`
400 if [ "x$val" != x ]; then
401 fail "ref $g unexpectedly exists ($val)"
407 echo refs/tags/test-dummy/${v//\~/_}
410 t-check-pushed-master () {
411 local master=`t-git-get-ref refs/heads/master`
412 if [ x$master = x$t_ref_val ]; then return; fi
413 if [ x$master = x ]; then fail "failed to push master"; fi
414 # didn't update master, it must be not FF
415 local mbase=`t-git-merge-base $master $t_ref_val`
416 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
425 refs/remotes/dgit/dgit/sid
427 refs/heads/dgit/unstable \
428 refs/remotes/dgit/dgit/unstable
429 (set -e; cd $dgitrepo
433 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
437 git verify-tag `t-v-tag`
440 t-commit-build-push-expect-log () {
446 t-dgit push --new 2>&1 |tee $tmp/push.log
447 t-grep-mpat "$mpat" $tmp/push.log
454 use Dpkg::Control::Hash;
455 my $h = new Dpkg::Control::Hash allow_pgp=>1;
456 $h->parse(\*STDIN,"'"$file"'");
457 my $val = $h->{"'$field'"},"\n";
458 die "'"$file $field"'" unless defined $val;
470 *) '$var'="$tstunt:$'$var'" ;;
476 local tstunt=$tmp/tstunt
477 t-stunt-envvar PATH $tstunt
478 t-stunt-envvar PERLLIB $tstunt
482 local d="$tstunt/${f%/*}"
484 ln -sf "$troot/tstunt/$f" "$d"/.
488 t-tstunt-parsechangelog () {
489 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
493 local dsc=${p}_${v}.dsc
494 local val=`t-822-field $tmp/incoming/$dsc Dgit`
495 perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
496 t-ref-same-val $dsc "$val"
503 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
510 dch -v$v --distribution unstable "$1"
511 git add debian/changelog
513 revision=$(( ${revision-0} + 1 ))
517 git config --global "$@"
521 export DGIT_TEST_TROOT=$troot
522 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
523 t-git-config dgit-distro.test-dummy.git-check true
524 t-git-config dgit-distro.test-dummy.git-create true
525 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
526 cp $troot/suites $tmp/.
527 cp $troot/suites $tmp/suites-master
529 export t_check_pushed_master=t-check-pushed-master
531 drs_dispatch=$tmp/distro=test-dummy
534 if [ "x$DGIT_TEST_INTREE" != x ]; then
535 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
538 ln -sf $tmp/git $drs_dispatch/repos
539 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
540 mkdir -p $drs_dispatch/keyrings
541 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
542 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
543 ln -sf /bin/true $drs_dispatch/policy-hook
548 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
549 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
550 t-git-config dgit-distro.test-dummy.git-create true
551 t-git-config dgit-distro.test-dummy.git-url \
552 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
554 t-git-config dgit-distro.test-dummy.diverts.drs /drs
555 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
556 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
557 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
558 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
560 echo 'no-such-package* drs' >$drs_dispatch/diverts
564 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
567 t-policy-nonexist () {
568 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
571 t-make-hook-link () {
572 local hook=$1 # in infra/
574 hook=${DGIT_INFRA_PFX}$hook
577 *) hook=`type -P $hook` ;;
579 ln -sf "$hook" $linkpath
584 t-make-hook-link $policyhook $drs_dispatch/policy-hook
589 t-policy dgit-repos-policy-debian
592 t-policy-admin create-db
595 t-policy-periodic () {
596 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
597 test-dummy $drs_dispatch '' --cron
602 (cd $root; t-restriction-$restriction >&2)
606 : "Hopefully installed: $*"
613 export DGIT_TEST_TESTNAME="$testname"
621 t-chain-test "${t#*-}"