16 lines: ${BASH_LINENO[*]}
17 files: ${BASH_SOURCE[*]}
22 trap 'test $? = 0 || t-report-failure' EXIT
26 : ${DGIT_TEST_DEBUG=-D}
27 export DGIT_TEST_DEBUG
29 export GIT_COMMITTER_DATE='1440253867 +0100'
30 export GIT_AUTHOR_DATE='1440253867 +0100'
34 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
37 if [ x"$tmp" = x ]; then
39 tmp=tests/tmp/$testname
52 cp $troot/gnupg/* $tmp/gnupg
53 chmod go-rw $tmp/gnupg/*
55 export DEBCHANGE_VENDOR=dpkg
57 mkdir -p $tmp/incoming
58 cat <<END >$tmp/dput.cf
61 incoming = $tmp/incoming
65 : ${tagpfx:=test-dummy}
68 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
69 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
73 local mpat="$1"; shift
76 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
77 local ps="${PIPESTATUS[*]}"
81 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
83 *) fail "tee failed" ;;
86 t-grep-mpat "$mpat" $tmp/t.output
99 *) fail "bad mpat prefix in $mpat";;
105 $grepper -e "$mpat" "$file" ||
106 fail "message not found"
109 t-expect-push-fail () {
110 local mpat="$1"; shift
112 local triedpush=`git rev-parse HEAD`
115 t-expect-fail "$mpat" "$@"
117 diff $tmp/show-refs.{pre,post}-push
119 t-git-objects-not-present '' $triedpush
121 eval "$t_expect_push_fail_hook"
124 t-git-objects-not-present () {
125 # t-git-objects-not-present GITDIR|'' OBJID [...]
126 # specifying '' means the repo for package $p
127 local gitdir="${1-$dgitrepo}"
129 if ! [ -e "$gitdir" ]; then return; fi
132 t-expect-fail 'unable to find' \
138 local whichoutput=$1; shift
139 local whichrepo=${1-$dgitrepo}
140 local outputfile="$tmp/show-refs.$whichoutput"
143 if test -d $whichrepo; then
151 local edittree=$1.edit
152 if test -d "$edittree"; then
153 cp -a "$edittree"/* .
161 t-untar $troot/worktrees/${p}_$1
164 t-select-package () {
166 dgitrepo=$tmp/git/$p.git
173 local gs=$troot/git-srcs/${p}_$v.git
174 (set -e; cd $tmp/git; t-untar $gs)
179 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
182 t-git-merge-base () {
183 git merge-base $1 $2 || test $? = 1
187 local now=`git rev-parse HEAD`
188 local ancestor=`git rev-parse $1^{}`
189 local mbase=`t-git-merge-base $ancestor $now`
190 if [ x$mbase != x$ancestor ]; then
191 fail "not ff $ancestor..$now, $mbase != $ancestor"
195 t-prep-newpackage () {
202 if ! git show-ref --verify --quiet refs/heads/master; then
203 git branch -m dgit/sid master
211 mkdir -p $tmp/aq $tmp/mirror/pool/main
215 >$tmp/aq/package.$suite.$p
216 t-archive-updated $suite $p
218 >$tmp/aq/package.new.$p
219 t-archive-updated new $p
221 ln -s sid $tmp/aq/dsc_in_suite/unstable
222 cat <<'END' >$tmp/aq/suites
225 "archive" : "ftp-master",
233 "dakname" : "unstable"
239 t-archive-updated () {
242 local suitedir=$tmp/aq/dsc_in_suite/$suite
244 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
248 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
256 my $json = JSON->new->canonical();
257 print $json->encode(\@v) or die $!;
262 t-archive-process-incoming () {
264 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
265 t-archive-query "$suite"
270 local dscf=main/${p}_${v}.dsc
271 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
272 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
273 t-archive-updated $suite $p
279 local dscf=${p}_$2.dsc
280 rm -f $tmp/mirror/pool/main/${p}_*
281 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
285 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
288 t-git-dir-time-passes () {
289 touch -d 'last year' $dgitrepo
293 local gitdir=$dgitrepo
296 if test -e "$gitdir"; then fail "$gitdir exists"; fi
299 public) wantstat='7[75]5' ;;
300 secret) wantstat='7[70]0' ;;
301 *) fail "$1 t-git-dir-check ?" ;;
303 gotstat=`stat -c%a $gitdir`
305 *$wantstat) return ;;
306 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
310 t-rm-dput-dropping () {
311 rm -f $tmp/${p}_${v}_*.upload
315 local dgit=${DGIT_TEST-dgit}
318 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
319 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
320 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
322 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
327 diff --exclude=.git --exclude=.pc -ruN $*
330 t-files-notexist () {
339 t-cloned-fetched-good () {
340 t-diff-nogit ../extract/$p-${v%-*} .
341 t-clean-on-branch dgit/sid
344 refs/heads/dgit/sid \
345 refs/remotes/dgit/dgit/sid
346 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
350 printf "%s\n" "$1" >$tmp/t.want
353 diff $tmp/t.want $tmp/t.got
356 t-clean-on-branch () {
357 t-output "## $1" git status -b --porcelain
360 t-git-get-ref-exact () {
362 # does not dereference, unlike t-git-get-ref
365 *) fail "t-git-get-ref-exact bad $ref" ;;
367 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
374 *) fail "t-git-get-ref bad $ref" ;;
376 (git show-ref -d $1 || test $? = 1) | perl -ne '
377 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
378 END { print "$x\n" if length $x; }
382 t-ref-same-exact () {
384 local val=`t-git-get-ref-exact $name`
385 t-ref-same-val "$name" $val
390 local val=`t-git-get-ref $name`
391 t-ref-same-val "$name" $val
395 local val=`git rev-parse HEAD`
396 t-ref-same-val HEAD $val
405 *) fail "ref varies: $name:\
406 ${val:-nothing} != ${t_ref_val:-nothing}" ;;
411 t-refs-same-start () {
425 val=`t-git-get-ref $g`
426 if [ "x$val" != x ]; then
427 fail "ref $g unexpectedly exists ($val)"
433 echo refs/tags/$tagpfx/${v//\~/_}
436 t-check-pushed-master () {
437 local master=`t-git-get-ref refs/heads/master`
438 if [ x$master = x$t_ref_val ]; then return; fi
439 if [ x$master = x ]; then fail "failed to push master"; fi
440 # didn't update master, it must be not FF
441 local mbase=`t-git-merge-base $master $t_ref_val`
442 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
451 refs/remotes/dgit/dgit/sid
453 refs/heads/dgit/unstable \
454 refs/remotes/dgit/dgit/unstable
455 (set -e; cd $dgitrepo
459 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
463 git verify-tag `t-v-tag`
466 t-commit-build-push-expect-log () {
472 t-dgit push --new 2>&1 |tee $tmp/push.log
473 t-grep-mpat "$mpat" $tmp/push.log
480 use Dpkg::Control::Hash;
481 my $h = new Dpkg::Control::Hash allow_pgp=>1;
482 $h->parse(\*STDIN,"'"$file"'");
483 my $val = $h->{"'$field'"},"\n";
484 die "'"$file $field"'" unless defined $val;
496 *) '$var'="$tstunt:$'$var'" ;;
502 local tstunt=$tmp/tstunt
503 t-stunt-envvar PATH $tstunt
504 t-stunt-envvar PERLLIB $tstunt
508 local d="$tstunt/${f%/*}"
510 ln -sf "$troot/tstunt/$f" "$d"/.
514 t-tstunt-parsechangelog () {
515 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
519 local dsc=${p}_${v}.dsc
520 local val=`t-822-field $tmp/incoming/$dsc Dgit`
521 perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
522 t-ref-same-val $dsc "$val"
529 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
533 t-gbp-unapplied-pq2qc () {
534 # does `gbp pq export'
535 # commits the resulting debian/patches on qc/BRANCH
536 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
537 # qc/BRANCH is not fast-forwarding
541 branch=`git symbolic-ref HEAD`
542 branch=${branch#refs/heads/}
545 */*) fail "unexpected branch $branch" ;;
548 git branch -f qc/$branch
549 git checkout qc/$branch
550 git add debian/patches
551 git commit -m 'Commit patch queue'
554 t-gbp-example-prep () {
555 t-archive example 1.0-1
563 git-checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
566 echo '/* some comment */' >>src.c
568 git commit -m 'Add a comment to an upstream file'
570 t-gbp-unapplied-pq2qc
572 t-commit 'some updates' 1.0-2
575 -m 'Pseudo-merge to make descendant of archive' \
576 remotes/dgit/dgit/sid
582 dch -v$v --distribution unstable "$1"
583 git add debian/changelog
585 revision=$(( ${revision-0} + 1 ))
589 git config --global "$@"
593 export DGIT_TEST_TROOT=$troot
594 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
595 t-git-config dgit-distro.test-dummy.git-check true
596 t-git-config dgit-distro.test-dummy.git-create true
597 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
598 cp $troot/suites $tmp/.
599 cp $troot/suites $tmp/suites-master
601 export t_check_pushed_master=t-check-pushed-master
603 drs_dispatch=$tmp/distro=test-dummy
606 if [ "x$DGIT_TEST_INTREE" != x ]; then
607 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
610 ln -sf $tmp/git $drs_dispatch/repos
611 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
612 mkdir -p $drs_dispatch/keyrings
613 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
614 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
615 ln -sf /bin/true $drs_dispatch/policy-hook
619 export tagpfx=archive/test-dummy
620 t-git-config dgit-distro.test-dummy.dgit-tag-format new
623 t-git-config dgit-distro.test-dummy.dgit-tag-format old
628 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
629 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
630 t-git-config dgit-distro.test-dummy.git-create true
631 t-git-config dgit-distro.test-dummy.git-url \
632 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
634 t-git-config dgit-distro.test-dummy.diverts.drs /drs
635 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
636 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
637 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
638 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
640 echo 'no-such-package* drs' >$drs_dispatch/diverts
644 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
647 t-policy-nonexist () {
648 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
651 t-make-hook-link () {
652 local hook=$1 # in infra/
654 hook=${DGIT_INFRA_PFX}$hook
657 *) hook=`type -P $hook` ;;
659 ln -sf "$hook" $linkpath
664 t-make-hook-link $policyhook $drs_dispatch/policy-hook
669 t-policy dgit-repos-policy-debian
672 t-policy-admin create-db
675 t-policy-periodic () {
676 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
677 test-dummy $drs_dispatch '' --cron
682 (cd $root; t-restriction-$restriction >&2)
686 : "Hopefully installed: $*"
693 export DGIT_TEST_TESTNAME="$testname"
701 t-chain-test "${t#*-}"