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
66 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
67 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
71 local mpat="$1"; shift
74 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
75 local ps="${PIPESTATUS[*]}"
79 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
81 *) fail "tee failed" ;;
84 t-grep-mpat "$mpat" $tmp/t.output
97 *) fail "bad mpat prefix in $mpat";;
103 $grepper -e "$mpat" "$file" ||
104 fail "message not found"
107 t-expect-push-fail () {
108 local mpat="$1"; shift
110 local triedpush=`git rev-parse HEAD`
113 t-expect-fail "$mpat" "$@"
115 diff $tmp/show-refs.{pre,post}-push
117 t-git-objects-not-present '' $triedpush
119 eval "$t_expect_push_fail_hook"
122 t-git-objects-not-present () {
123 # t-git-objects-not-present GITDIR|'' OBJID [...]
124 # specifying '' means the repo for package $p
125 local gitdir="${1-$dgitrepo}"
127 if ! [ -e "$gitdir" ]; then return; fi
130 t-expect-fail 'unable to find' \
136 local whichoutput=$1; shift
137 local whichrepo=${1-$dgitrepo}
138 local outputfile="$tmp/show-refs.$whichoutput"
141 if test -d $whichrepo; then
149 local edittree=$1.edit
150 if test -d "$edittree"; then
151 cp -a "$edittree"/* .
159 t-untar $troot/worktrees/${p}_$1
162 t-select-package () {
164 dgitrepo=$tmp/git/$p.git
171 local gs=$troot/git-srcs/${p}_$v.git
172 (set -e; cd $tmp/git; t-untar $gs)
177 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
180 t-git-merge-base () {
181 git merge-base $1 $2 || test $? = 1
185 local now=`git rev-parse HEAD`
186 local ancestor=`git rev-parse $1^{}`
187 local mbase=`t-git-merge-base $ancestor $now`
188 if [ x$mbase != x$ancestor ]; then
189 fail "not ff $ancestor..$now, $mbase != $ancestor"
193 t-prep-newpackage () {
200 if ! git show-ref --verify --quiet refs/heads/master; then
201 git branch -m dgit/sid master
209 mkdir -p $tmp/aq $tmp/mirror/pool/main
213 >$tmp/aq/package.$suite.$p
214 t-archive-updated $suite $p
216 >$tmp/aq/package.new.$p
217 t-archive-updated new $p
219 ln -s sid $tmp/aq/dsc_in_suite/unstable
220 cat <<'END' >$tmp/aq/suites
223 "archive" : "ftp-master",
231 "dakname" : "unstable"
237 t-archive-updated () {
240 local suitedir=$tmp/aq/dsc_in_suite/$suite
242 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
246 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
254 print to_json \@v or die $!;
259 t-archive-process-incoming () {
261 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
262 t-archive-query "$suite"
267 local dscf=main/${p}_${v}.dsc
268 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
269 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
270 t-archive-updated $suite $p
276 local dscf=${p}_$2.dsc
277 rm -f $tmp/mirror/pool/main/${p}_*
278 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
282 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
285 t-git-dir-time-passes () {
286 touch -d 'last year' $dgitrepo
290 local gitdir=$dgitrepo
293 if test -e "$gitdir"; then fail "$gitdir exists"; fi
296 public) wantstat='7[75]5' ;;
297 secret) wantstat='7[70]0' ;;
298 *) fail "$1 t-git-dir-check ?" ;;
300 gotstat=`stat -c%a $gitdir`
302 *$wantstat) return ;;
303 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
307 t-rm-dput-dropping () {
308 rm -f $tmp/${p}_${v}_*.upload
312 local dgit=${DGIT_TEST-dgit}
315 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
316 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
317 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
319 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
324 diff --exclude=.git --exclude=.pc -ruN $*
327 t-files-notexist () {
336 t-cloned-fetched-good () {
337 t-diff-nogit ../extract/$p-${v%-*} .
338 t-clean-on-branch dgit/sid
341 refs/heads/dgit/sid \
342 refs/remotes/dgit/dgit/sid
343 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
347 printf "%s\n" "$1" >$tmp/t.want
350 diff $tmp/t.want $tmp/t.got
353 t-clean-on-branch () {
354 t-output "## $1" git status -b --porcelain
357 t-git-get-ref-exact () {
359 # does not dereference, unlike t-git-get-ref
362 *) fail "t-git-get-ref-exact bad $ref" ;;
364 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
371 *) fail "t-git-get-ref bad $ref" ;;
373 (git show-ref -d $1 || test $? = 1) | perl -ne '
374 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
375 END { print "$x\n" if length $x; }
379 t-ref-same-exact () {
381 local val=`t-git-get-ref-exact $name`
382 t-ref-same-val "$name" $val
387 local val=`t-git-get-ref $name`
388 t-ref-same-val "$name" $val
392 local val=`git rev-parse HEAD`
393 t-ref-same-val HEAD $val
402 *) fail "ref varies: $name: $val != $t_ref_val" ;;
407 t-refs-same-start () {
421 val=`t-git-get-ref $g`
422 if [ "x$val" != x ]; then
423 fail "ref $g unexpectedly exists ($val)"
429 echo refs/tags/test-dummy/${v//\~/_}
432 t-check-pushed-master () {
433 local master=`t-git-get-ref refs/heads/master`
434 if [ x$master = x$t_ref_val ]; then return; fi
435 if [ x$master = x ]; then fail "failed to push master"; fi
436 # didn't update master, it must be not FF
437 local mbase=`t-git-merge-base $master $t_ref_val`
438 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
447 refs/remotes/dgit/dgit/sid
449 refs/heads/dgit/unstable \
450 refs/remotes/dgit/dgit/unstable
451 (set -e; cd $dgitrepo
455 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
459 git verify-tag `t-v-tag`
462 t-commit-build-push-expect-log () {
468 t-dgit push --new 2>&1 |tee $tmp/push.log
469 t-grep-mpat "$mpat" $tmp/push.log
476 use Dpkg::Control::Hash;
477 my $h = new Dpkg::Control::Hash allow_pgp=>1;
478 $h->parse(\*STDIN,"'"$file"'");
479 my $val = $h->{"'$field'"},"\n";
480 die "'"$file $field"'" unless defined $val;
492 *) '$var'="$tstunt:$'$var'" ;;
498 local tstunt=$tmp/tstunt
499 t-stunt-envvar PATH $tstunt
500 t-stunt-envvar PERLLIB $tstunt
504 local d="$tstunt/${f%/*}"
506 ln -sf "$troot/tstunt/$f" "$d"/.
510 t-tstunt-parsechangelog () {
511 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
515 local dsc=${p}_${v}.dsc
516 local val=`t-822-field $tmp/incoming/$dsc Dgit`
517 perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
518 t-ref-same-val $dsc "$val"
525 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
529 t-gbp-unapplied-pq2qc () {
530 # does `gbp pq export'
531 # commits the resulting debian/patches on qc/BRANCH
532 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
533 # qc/BRANCH is not fast-forwarding
537 branch=`git symbolic-ref HEAD`
538 branch=${branch#refs/heads/}
541 */*) fail "unexpected branch $branch" ;;
544 git branch -f qc/$branch
545 git checkout qc/$branch
546 git add debian/patches
547 git commit -m 'Commit patch queue'
550 t-gbp-example-prep () {
551 t-archive example 1.0-1
559 git-checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
562 echo '/* some comment */' >>src.c
564 git commit -m 'Add a comment to an upstream file'
566 t-gbp-unapplied-pq2qc
568 t-commit 'some updates' 1.0-2
571 -m 'Pseudo-merge to make descendant of archive' \
572 remotes/dgit/dgit/sid
578 dch -v$v --distribution unstable "$1"
579 git add debian/changelog
581 revision=$(( ${revision-0} + 1 ))
585 git config --global "$@"
589 export DGIT_TEST_TROOT=$troot
590 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
591 t-git-config dgit-distro.test-dummy.git-check true
592 t-git-config dgit-distro.test-dummy.git-create true
593 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
594 cp $troot/suites $tmp/.
595 cp $troot/suites $tmp/suites-master
597 export t_check_pushed_master=t-check-pushed-master
599 drs_dispatch=$tmp/distro=test-dummy
602 if [ "x$DGIT_TEST_INTREE" != x ]; then
603 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
606 ln -sf $tmp/git $drs_dispatch/repos
607 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
608 mkdir -p $drs_dispatch/keyrings
609 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
610 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
611 ln -sf /bin/true $drs_dispatch/policy-hook
616 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
617 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
618 t-git-config dgit-distro.test-dummy.git-create true
619 t-git-config dgit-distro.test-dummy.git-url \
620 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
622 t-git-config dgit-distro.test-dummy.diverts.drs /drs
623 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
624 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
625 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
626 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
628 echo 'no-such-package* drs' >$drs_dispatch/diverts
632 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
635 t-policy-nonexist () {
636 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
639 t-make-hook-link () {
640 local hook=$1 # in infra/
642 hook=${DGIT_INFRA_PFX}$hook
645 *) hook=`type -P $hook` ;;
647 ln -sf "$hook" $linkpath
652 t-make-hook-link $policyhook $drs_dispatch/policy-hook
657 t-policy dgit-repos-policy-debian
660 t-policy-admin create-db
663 t-policy-periodic () {
664 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
665 test-dummy $drs_dispatch '' --cron
670 (cd $root; t-restriction-$restriction >&2)
674 : "Hopefully installed: $*"
681 export DGIT_TEST_TESTNAME="$testname"
689 t-chain-test "${t#*-}"