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" ;;
61 t-grep-mpat "$mpat" $tmp/t.output
74 *) fail "bad mpat prefix in $mpat";;
80 $grepper -e "$mpat" "$file" ||
81 fail "message not found"
84 t-expect-push-fail () {
85 local mpat="$1"; shift
87 local triedpush=`git rev-parse HEAD`
90 t-expect-fail "$mpat" "$@"
92 diff $tmp/show-refs.{pre,post}-push
94 t-git-objects-not-present '' $triedpush
96 eval "$t_expect_push_fail_hook"
99 t-git-objects-not-present () {
100 # t-git-objects-not-present GITDIR|'' OBJID [...]
101 # specifying '' means the repo for package $p
102 local gitdir="${1-$dgitrepo}"
104 if ! [ -e "$gitdir" ]; then return; fi
107 t-expect-fail 'unable to find' \
113 local whichoutput=$1; shift
114 local whichrepo=${1-$dgitrepo}
115 local outputfile="$tmp/show-refs.$whichoutput"
118 if test -d $whichrepo; then
126 local edittree=$1.edit
127 if test -d "$edittree"; then
128 cp -al "$edittree"/* .
136 t-untar $troot/worktrees/${p}_$1
139 t-select-package () {
141 dgitrepo=$tmp/git/$p.git
148 local gs=$troot/git-srcs/${p}_$v.git
149 (set -e; cd $tmp/git; t-untar $gs)
154 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
157 t-git-merge-base () {
158 git merge-base $1 $2 || test $? = 1
162 local now=`git rev-parse HEAD`
163 local ancestor=`git rev-parse $1^{}`
164 local mbase=`t-git-merge-base $ancestor $now`
165 if [ x$mbase != x$ancestor ]; then
166 fail "not ff $ancestor..$now, $mbase != $ancestor"
170 t-prep-newpackage () {
177 if ! git show-ref --verify --quiet refs/heads/master; then
178 git branch -m dgit/sid master
186 mkdir -p $tmp/aq $tmp/mirror/pool/main
190 >$tmp/aq/package.$suite.$p
191 t-archive-updated $suite $p
193 >$tmp/aq/package.new.$p
194 t-archive-updated new $p
196 ln -s sid $tmp/aq/dsc_in_suite/unstable
197 cat <<'END' >$tmp/aq/suites
200 "archive" : "ftp-master",
208 "dakname" : "unstable"
214 t-archive-updated () {
217 local suitedir=$tmp/aq/dsc_in_suite/$suite
219 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
223 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
231 print to_json \@v or die $!;
236 t-archive-process-incoming () {
238 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
239 t-archive-query "$suite"
244 local dscf=main/${p}_${v}.dsc
245 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
246 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
247 t-archive-updated $suite $p
253 local dscf=${p}_$2.dsc
254 rm -f $tmp/mirror/pool/main/${p}_*
255 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
259 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
262 t-git-dir-time-passes () {
263 touch -d 'last year' $dgitrepo
267 local gitdir=$dgitrepo
270 if test -e "$gitdir"; then fail "$gitdir exists"; fi
273 public) wantstat='7[75]5' ;;
274 secret) wantstat='7[70]0' ;;
275 *) fail "$1 t-git-dir-check ?" ;;
277 gotstat=`stat -c%a $gitdir`
279 *$wantstat) return ;;
280 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
284 t-rm-dput-dropping () {
285 rm -f $tmp/${p}_${v}_*.upload
289 local dgit=${DGIT_TEST-dgit}
292 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
293 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
294 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
296 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
301 diff --exclude=.git --exclude=.pc -ruN $*
304 t-files-notexist () {
313 t-cloned-fetched-good () {
314 t-diff-nogit ../extract/$p-${v%-*} .
315 t-clean-on-branch dgit/sid
318 refs/heads/dgit/sid \
319 refs/remotes/dgit/dgit/sid
320 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
324 printf "%s\n" "$1" >$tmp/t.want
327 diff $tmp/t.want $tmp/t.got
330 t-clean-on-branch () {
331 t-output "## $1" git status -b --porcelain
334 t-git-get-ref-exact () {
336 # does not dereference, unlike t-git-get-ref
339 *) fail "t-git-get-ref-exact bad $ref" ;;
341 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
348 *) fail "t-git-get-ref bad $ref" ;;
350 (git show-ref -d $1 || test $? = 1) | perl -ne '
351 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
352 END { print "$x\n" if length $x; }
356 t-ref-same-exact () {
358 local val=`t-git-get-ref-exact $name`
359 t-ref-same-val "$name" $val
364 local val=`t-git-get-ref $name`
365 t-ref-same-val "$name" $val
369 local val=`git rev-parse HEAD`
370 t-ref-same-val HEAD $val
379 *) fail "ref varies: $name: $val != $t_ref_val" ;;
384 t-refs-same-start () {
398 val=`t-git-get-ref $g`
399 if [ "x$val" != x ]; then
400 fail "ref $g unexpectedly exists ($val)"
406 echo refs/tags/test-dummy/${v//\~/_}
409 t-check-pushed-master () {
410 local master=`t-git-get-ref refs/heads/master`
411 if [ x$master = x$t_ref_val ]; then return; fi
412 if [ x$master = x ]; then fail "failed to push master"; fi
413 # didn't update master, it must be not FF
414 local mbase=`t-git-merge-base $master $t_ref_val`
415 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
424 refs/remotes/dgit/dgit/sid
426 refs/heads/dgit/unstable \
427 refs/remotes/dgit/dgit/unstable
428 (set -e; cd $dgitrepo
432 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
436 git verify-tag `t-v-tag`
439 t-commit-build-push-expect-log () {
445 t-dgit push --new 2>&1 |tee $tmp/push.log
446 t-grep-mpat "$mpat" $tmp/push.log
453 use Dpkg::Control::Hash;
454 my $h = new Dpkg::Control::Hash allow_pgp=>1;
455 $h->parse(\*STDIN,"'"$file"'");
456 my $val = $h->{"'$field'"},"\n";
457 die "'"$file $field"'" unless defined $val;
469 *) '$var'="$tstunt:$'$var'" ;;
475 local tstunt=$tmp/tstunt
476 t-stunt-envvar PATH $tstunt
477 t-stunt-envvar PERLLIB $tstunt
481 local d="$tstunt/${f%/*}"
483 ln -sf "$troot/tstunt/$f" "$d"/.
487 t-tstunt-parsechangelog () {
488 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
492 local dsc=${p}_${v}.dsc
493 local val=`t-822-field $tmp/incoming/$dsc Dgit`
494 perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
495 t-ref-same-val $dsc "$val"
502 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
509 dch -v$v --distribution unstable "$1"
510 git add debian/changelog
512 revision=$(( ${revision-0} + 1 ))
516 git config --global "$@"
520 export DGIT_TEST_TROOT=$troot
521 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
522 t-git-config dgit-distro.test-dummy.git-check true
523 t-git-config dgit-distro.test-dummy.git-create true
524 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
525 cp $troot/suites $tmp/.
526 cp $troot/suites $tmp/suites-master
528 export t_check_pushed_master=t-check-pushed-master
530 drs_dispatch=$tmp/distro=test-dummy
533 if [ "x$DGIT_TEST_INTREE" != x ]; then
534 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
537 ln -sf $tmp/git $drs_dispatch/repos
538 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
539 mkdir -p $drs_dispatch/keyrings
540 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
541 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
542 ln -sf /bin/true $drs_dispatch/policy-hook
547 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
548 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
549 t-git-config dgit-distro.test-dummy.git-create true
550 t-git-config dgit-distro.test-dummy.git-url \
551 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
553 t-git-config dgit-distro.test-dummy.diverts.drs /drs
554 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
555 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
556 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
557 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
559 echo 'no-such-package* drs' >$drs_dispatch/diverts
563 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
566 t-policy-nonexist () {
567 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
570 t-make-hook-link () {
571 local hook=$1 # in infra/
573 hook=${DGIT_INFRA_PFX}$hook
576 *) hook=`type -P $hook` ;;
578 ln -sf "$hook" $linkpath
583 t-make-hook-link $policyhook $drs_dispatch/policy-hook
588 t-policy dgit-repos-policy-debian
591 t-policy-admin create-db
594 t-policy-periodic () {
595 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
596 test-dummy $drs_dispatch '' --cron
603 export DGIT_TEST_TESTNAME="$testname"
611 t-chain-test "${t#*-}"