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}
66 : ${suitespecs:=sid:unstable}
69 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
70 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
74 local mpat="$1"; shift
77 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
78 local ps="${PIPESTATUS[*]}"
82 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
84 *) fail "tee failed" ;;
87 t-grep-mpat "$mpat" $tmp/t.output
100 *) fail "bad mpat prefix in $mpat";;
106 $grepper -e "$mpat" "$file" ||
107 fail "message not found"
110 t-expect-push-fail () {
111 local mpat="$1"; shift
113 local triedpush=`git rev-parse HEAD`
116 t-expect-fail "$mpat" "$@"
118 diff $tmp/show-refs.{pre,post}-push
120 t-git-objects-not-present '' $triedpush
122 eval "$t_expect_push_fail_hook"
125 t-git-objects-not-present () {
126 # t-git-objects-not-present GITDIR|'' OBJID [...]
127 # specifying '' means the repo for package $p
128 local gitdir="${1-$dgitrepo}"
130 if ! [ -e "$gitdir" ]; then return; fi
133 t-expect-fail 'unable to find' \
139 local whichoutput=$1; shift
140 local whichrepo=${1-$dgitrepo}
141 local outputfile="$tmp/show-refs.$whichoutput"
144 if test -d $whichrepo; then
152 local edittree=$1.edit
153 if test -d "$edittree"; then
154 cp -a "$edittree"/* .
162 t-untar $troot/worktrees/${p}_$1
165 t-select-package () {
167 dgitrepo=$tmp/git/$p.git
174 local gs=$troot/git-srcs/${p}_$v.git
175 (set -e; cd $tmp/git; t-untar $gs)
180 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
183 t-git-merge-base () {
184 git merge-base $1 $2 || test $? = 1
188 local now=`git rev-parse HEAD`
189 local ancestor=`git rev-parse $1^{}`
190 local mbase=`t-git-merge-base $ancestor $now`
191 if [ x$mbase != x$ancestor ]; then
192 fail "not ff $ancestor..$now, $mbase != $ancestor"
196 t-prep-newpackage () {
203 if ! git show-ref --verify --quiet refs/heads/master; then
204 git branch -m dgit/sid master
212 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
218 for suitespec in $suitespecs; do
219 local suite=${suitespec%%:*}
220 local sname=${suitespec#*:}
222 >$tmp/aq/package.$suite.$p
223 t-archive-updated $suite $p
225 >$tmp/aq/package.new.$p
226 t-archive-updated new $p
228 ln -s $suite $tmp/aq/dsc_in_suite/$sname
230 cat <<END >>$tmp/aq/suites
233 "archive" : "ftp-master",
234 "codename" : "$suite",
247 cat <<END >>$tmp/aq/suites
253 t-archive-updated () {
256 local suitedir=$tmp/aq/dsc_in_suite/$suite
258 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
262 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
270 my $json = JSON->new->canonical();
271 print $json->encode(\@v) or die $!;
276 t-archive-process-incoming () {
278 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
279 t-archive-query "$suite"
284 local dscf=main/${p}_${v}.dsc
285 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
286 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
287 t-archive-updated $suite $p
293 local dscf=${p}_$2.dsc
294 rm -f $tmp/mirror/pool/main/${p}_*
295 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
299 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
302 t-git-dir-time-passes () {
303 touch -d 'last year' $dgitrepo
307 local gitdir=$dgitrepo
310 if test -e "$gitdir"; then fail "$gitdir exists"; fi
313 public) wantstat='7[75]5' ;;
314 secret) wantstat='7[70]0' ;;
315 *) fail "$1 t-git-dir-check ?" ;;
317 gotstat=`stat -c%a $gitdir`
319 *$wantstat) return ;;
320 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
324 t-rm-dput-dropping () {
325 rm -f $tmp/${p}_${v}_*.upload
329 local dgit=${DGIT_TEST-dgit}
332 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
333 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
334 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
336 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
341 diff --exclude=.git --exclude=.pc -ruN $*
344 t-files-notexist () {
353 t-cloned-fetched-good () {
354 t-diff-nogit ../extract/$p-${v%-*} .
355 t-clean-on-branch dgit/sid
358 refs/heads/dgit/sid \
359 refs/remotes/dgit/dgit/sid
360 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
364 printf "%s\n" "$1" >$tmp/t.want
367 diff $tmp/t.want $tmp/t.got
370 t-clean-on-branch () {
371 t-output "## $1" git status -b --porcelain
374 t-git-get-ref-exact () {
376 # does not dereference, unlike t-git-get-ref
379 *) fail "t-git-get-ref-exact bad $ref" ;;
381 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
388 *) fail "t-git-get-ref bad $ref" ;;
390 (git show-ref -d $1 || test $? = 1) | perl -ne '
391 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
392 END { print "$x\n" if length $x; }
396 t-ref-same-exact () {
398 local val=`t-git-get-ref-exact $name`
399 t-ref-same-val "$name" $val
404 local val=`t-git-get-ref $name`
405 t-ref-same-val "$name" $val
409 local val=`git rev-parse HEAD`
410 t-ref-same-val HEAD $val
419 *) fail "ref varies: $name:\
420 ${val:-nothing} != ${t_ref_val:-nothing}" ;;
425 t-refs-same-start () {
439 val=`t-git-get-ref $g`
440 if [ "x$val" != x ]; then
441 fail "ref $g unexpectedly exists ($val)"
447 echo refs/tags/$tagpfx/${v//\~/_}
450 t-check-pushed-master () {
451 local master=`t-git-get-ref refs/heads/master`
452 if [ x$master = x$t_ref_val ]; then return; fi
453 if [ x$master = x ]; then fail "failed to push master"; fi
454 # didn't update master, it must be not FF
455 local mbase=`t-git-merge-base $master $t_ref_val`
456 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
465 refs/remotes/dgit/dgit/sid
467 refs/heads/dgit/unstable \
468 refs/remotes/dgit/dgit/unstable
469 (set -e; cd $dgitrepo
473 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
477 git verify-tag `t-v-tag`
480 t-commit-build-push-expect-log () {
486 t-dgit push --new 2>&1 |tee $tmp/push.log
487 t-grep-mpat "$mpat" $tmp/push.log
494 use Dpkg::Control::Hash;
495 my $h = new Dpkg::Control::Hash allow_pgp=>1;
496 $h->parse(\*STDIN,"'"$file"'");
497 my $val = $h->{"'$field'"},"\n";
498 die "'"$file $field"'" unless defined $val;
510 *) '$var'="$tstunt:$'$var'" ;;
516 local tstunt=$tmp/tstunt
517 t-stunt-envvar PATH $tstunt
518 t-stunt-envvar PERLLIB $tstunt
522 local d="$tstunt/${f%/*}"
524 ln -sf "$troot/tstunt/$f" "$d"/.
528 t-tstunt-parsechangelog () {
529 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
533 local dsc=${p}_${v}.dsc
534 local val=`t-822-field $tmp/incoming/$dsc Dgit`
535 perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
536 t-ref-same-val $dsc "$val"
543 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
547 t-gbp-unapplied-pq2qc () {
548 # does `gbp pq export'
549 # commits the resulting debian/patches on qc/BRANCH
550 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
551 # qc/BRANCH is not fast-forwarding
555 branch=`git symbolic-ref HEAD`
556 branch=${branch#refs/heads/}
559 */*) fail "unexpected branch $branch" ;;
562 git branch -f qc/$branch
563 git checkout qc/$branch
564 git add debian/patches
565 git commit -m 'Commit patch queue'
568 t-gbp-example-prep () {
569 t-archive example 1.0-1
577 git-checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
580 echo '/* some comment */' >>src.c
582 git commit -m 'Add a comment to an upstream file'
584 t-gbp-unapplied-pq2qc
586 t-commit 'some updates' 1.0-2
589 -m 'Pseudo-merge to make descendant of archive' \
590 remotes/dgit/dgit/sid
596 dch -v$v --distribution unstable "$1"
597 git add debian/changelog
599 revision=$(( ${revision-0} + 1 ))
603 git config --global "$@"
607 export DGIT_TEST_TROOT=$troot
608 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
609 t-git-config dgit-distro.test-dummy.git-check true
610 t-git-config dgit-distro.test-dummy.git-create true
611 t-git-config dgit-distro.test-dummy.dgit-tag-format old,new
612 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
613 cp $troot/suites $tmp/.
614 cp $troot/suites $tmp/suites-master
616 export t_check_pushed_master=t-check-pushed-master
618 drs_dispatch=$tmp/distro=test-dummy
621 if [ "x$DGIT_TEST_INTREE" != x ]; then
622 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
625 ln -sf $tmp/git $drs_dispatch/repos
626 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
627 mkdir -p $drs_dispatch/keyrings
628 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
629 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
630 ln -sf /bin/true $drs_dispatch/policy-hook
634 export tagpfx=archive/test-dummy
635 t-git-config dgit-distro.test-dummy.dgit-tag-format new
638 t-git-config dgit-distro.test-dummy.dgit-tag-format old
643 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
644 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
645 t-git-config dgit-distro.test-dummy.git-create true
646 t-git-config dgit-distro.test-dummy.git-url \
647 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
649 t-git-config dgit-distro.test-dummy.diverts.drs /drs
650 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
651 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
652 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
653 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
655 echo 'no-such-package* drs' >$drs_dispatch/diverts
659 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
662 t-policy-nonexist () {
663 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
666 t-make-hook-link () {
667 local hook=$1 # in infra/
669 hook=${DGIT_INFRA_PFX}$hook
672 *) hook=`type -P $hook` ;;
674 ln -sf "$hook" $linkpath
679 t-make-hook-link $policyhook $drs_dispatch/policy-hook
684 t-policy dgit-repos-policy-debian
687 t-policy-admin create-db
690 t-policy-periodic () {
691 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
692 test-dummy $drs_dispatch '' --cron
697 (cd $root; t-restriction-$restriction >&2)
701 : "Hopefully installed: $*"
708 export DGIT_TEST_TESTNAME="$testname"
716 t-chain-test "${t#*-}"