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:\
403 ${val:-nothing} != ${t_ref_val:-nothing}" ;;
408 t-refs-same-start () {
422 val=`t-git-get-ref $g`
423 if [ "x$val" != x ]; then
424 fail "ref $g unexpectedly exists ($val)"
430 echo refs/tags/test-dummy/${v//\~/_}
433 t-check-pushed-master () {
434 local master=`t-git-get-ref refs/heads/master`
435 if [ x$master = x$t_ref_val ]; then return; fi
436 if [ x$master = x ]; then fail "failed to push master"; fi
437 # didn't update master, it must be not FF
438 local mbase=`t-git-merge-base $master $t_ref_val`
439 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
448 refs/remotes/dgit/dgit/sid
450 refs/heads/dgit/unstable \
451 refs/remotes/dgit/dgit/unstable
452 (set -e; cd $dgitrepo
456 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
460 git verify-tag `t-v-tag`
463 t-commit-build-push-expect-log () {
469 t-dgit push --new 2>&1 |tee $tmp/push.log
470 t-grep-mpat "$mpat" $tmp/push.log
477 use Dpkg::Control::Hash;
478 my $h = new Dpkg::Control::Hash allow_pgp=>1;
479 $h->parse(\*STDIN,"'"$file"'");
480 my $val = $h->{"'$field'"},"\n";
481 die "'"$file $field"'" unless defined $val;
493 *) '$var'="$tstunt:$'$var'" ;;
499 local tstunt=$tmp/tstunt
500 t-stunt-envvar PATH $tstunt
501 t-stunt-envvar PERLLIB $tstunt
505 local d="$tstunt/${f%/*}"
507 ln -sf "$troot/tstunt/$f" "$d"/.
511 t-tstunt-parsechangelog () {
512 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
516 local dsc=${p}_${v}.dsc
517 local val=`t-822-field $tmp/incoming/$dsc Dgit`
518 perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
519 t-ref-same-val $dsc "$val"
526 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
530 t-gbp-unapplied-pq2qc () {
531 # does `gbp pq export'
532 # commits the resulting debian/patches on qc/BRANCH
533 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
534 # qc/BRANCH is not fast-forwarding
538 branch=`git symbolic-ref HEAD`
539 branch=${branch#refs/heads/}
542 */*) fail "unexpected branch $branch" ;;
545 git branch -f qc/$branch
546 git checkout qc/$branch
547 git add debian/patches
548 git commit -m 'Commit patch queue'
551 t-gbp-example-prep () {
552 t-archive example 1.0-1
560 git-checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
563 echo '/* some comment */' >>src.c
565 git commit -m 'Add a comment to an upstream file'
567 t-gbp-unapplied-pq2qc
569 t-commit 'some updates' 1.0-2
572 -m 'Pseudo-merge to make descendant of archive' \
573 remotes/dgit/dgit/sid
579 dch -v$v --distribution unstable "$1"
580 git add debian/changelog
582 revision=$(( ${revision-0} + 1 ))
586 git config --global "$@"
590 export DGIT_TEST_TROOT=$troot
591 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
592 t-git-config dgit-distro.test-dummy.git-check true
593 t-git-config dgit-distro.test-dummy.git-create true
594 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
595 cp $troot/suites $tmp/.
596 cp $troot/suites $tmp/suites-master
598 export t_check_pushed_master=t-check-pushed-master
600 drs_dispatch=$tmp/distro=test-dummy
603 if [ "x$DGIT_TEST_INTREE" != x ]; then
604 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
607 ln -sf $tmp/git $drs_dispatch/repos
608 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
609 mkdir -p $drs_dispatch/keyrings
610 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
611 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
612 ln -sf /bin/true $drs_dispatch/policy-hook
617 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
618 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
619 t-git-config dgit-distro.test-dummy.git-create true
620 t-git-config dgit-distro.test-dummy.git-url \
621 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
623 t-git-config dgit-distro.test-dummy.diverts.drs /drs
624 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
625 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
626 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
627 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
629 echo 'no-such-package* drs' >$drs_dispatch/diverts
633 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
636 t-policy-nonexist () {
637 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
640 t-make-hook-link () {
641 local hook=$1 # in infra/
643 hook=${DGIT_INFRA_PFX}$hook
646 *) hook=`type -P $hook` ;;
648 ln -sf "$hook" $linkpath
653 t-make-hook-link $policyhook $drs_dispatch/policy-hook
658 t-policy dgit-repos-policy-debian
661 t-policy-admin create-db
664 t-policy-periodic () {
665 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
666 test-dummy $drs_dispatch '' --cron
671 (cd $root; t-restriction-$restriction >&2)
675 : "Hopefully installed: $*"
682 export DGIT_TEST_TESTNAME="$testname"
690 t-chain-test "${t#*-}"