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 print to_json \@v or die $!;
261 t-archive-process-incoming () {
263 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
264 t-archive-query "$suite"
269 local dscf=main/${p}_${v}.dsc
270 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
271 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
272 t-archive-updated $suite $p
278 local dscf=${p}_$2.dsc
279 rm -f $tmp/mirror/pool/main/${p}_*
280 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
284 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
287 t-git-dir-time-passes () {
288 touch -d 'last year' $dgitrepo
292 local gitdir=$dgitrepo
295 if test -e "$gitdir"; then fail "$gitdir exists"; fi
298 public) wantstat='7[75]5' ;;
299 secret) wantstat='7[70]0' ;;
300 *) fail "$1 t-git-dir-check ?" ;;
302 gotstat=`stat -c%a $gitdir`
304 *$wantstat) return ;;
305 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
309 t-rm-dput-dropping () {
310 rm -f $tmp/${p}_${v}_*.upload
314 local dgit=${DGIT_TEST-dgit}
317 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
318 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
319 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
321 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
326 diff --exclude=.git --exclude=.pc -ruN $*
329 t-files-notexist () {
338 t-cloned-fetched-good () {
339 t-diff-nogit ../extract/$p-${v%-*} .
340 t-clean-on-branch dgit/sid
343 refs/heads/dgit/sid \
344 refs/remotes/dgit/dgit/sid
345 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
349 printf "%s\n" "$1" >$tmp/t.want
352 diff $tmp/t.want $tmp/t.got
355 t-clean-on-branch () {
356 t-output "## $1" git status -b --porcelain
359 t-git-get-ref-exact () {
361 # does not dereference, unlike t-git-get-ref
364 *) fail "t-git-get-ref-exact bad $ref" ;;
366 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
373 *) fail "t-git-get-ref bad $ref" ;;
375 (git show-ref -d $1 || test $? = 1) | perl -ne '
376 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
377 END { print "$x\n" if length $x; }
381 t-ref-same-exact () {
383 local val=`t-git-get-ref-exact $name`
384 t-ref-same-val "$name" $val
389 local val=`t-git-get-ref $name`
390 t-ref-same-val "$name" $val
394 local val=`git rev-parse HEAD`
395 t-ref-same-val HEAD $val
404 *) fail "ref varies: $name:\
405 ${val:-nothing} != ${t_ref_val:-nothing}" ;;
410 t-refs-same-start () {
424 val=`t-git-get-ref $g`
425 if [ "x$val" != x ]; then
426 fail "ref $g unexpectedly exists ($val)"
432 echo refs/tags/$tagpfx/${v//\~/_}
435 t-check-pushed-master () {
436 local master=`t-git-get-ref refs/heads/master`
437 if [ x$master = x$t_ref_val ]; then return; fi
438 if [ x$master = x ]; then fail "failed to push master"; fi
439 # didn't update master, it must be not FF
440 local mbase=`t-git-merge-base $master $t_ref_val`
441 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
450 refs/remotes/dgit/dgit/sid
452 refs/heads/dgit/unstable \
453 refs/remotes/dgit/dgit/unstable
454 (set -e; cd $dgitrepo
458 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
462 git verify-tag `t-v-tag`
465 t-commit-build-push-expect-log () {
471 t-dgit push --new 2>&1 |tee $tmp/push.log
472 t-grep-mpat "$mpat" $tmp/push.log
479 use Dpkg::Control::Hash;
480 my $h = new Dpkg::Control::Hash allow_pgp=>1;
481 $h->parse(\*STDIN,"'"$file"'");
482 my $val = $h->{"'$field'"},"\n";
483 die "'"$file $field"'" unless defined $val;
495 *) '$var'="$tstunt:$'$var'" ;;
501 local tstunt=$tmp/tstunt
502 t-stunt-envvar PATH $tstunt
503 t-stunt-envvar PERLLIB $tstunt
507 local d="$tstunt/${f%/*}"
509 ln -sf "$troot/tstunt/$f" "$d"/.
513 t-tstunt-parsechangelog () {
514 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
518 local dsc=${p}_${v}.dsc
519 local val=`t-822-field $tmp/incoming/$dsc Dgit`
520 perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
521 t-ref-same-val $dsc "$val"
528 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
532 t-gbp-unapplied-pq2qc () {
533 # does `gbp pq export'
534 # commits the resulting debian/patches on qc/BRANCH
535 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
536 # qc/BRANCH is not fast-forwarding
540 branch=`git symbolic-ref HEAD`
541 branch=${branch#refs/heads/}
544 */*) fail "unexpected branch $branch" ;;
547 git branch -f qc/$branch
548 git checkout qc/$branch
549 git add debian/patches
550 git commit -m 'Commit patch queue'
553 t-gbp-example-prep () {
554 t-archive example 1.0-1
562 git-checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
565 echo '/* some comment */' >>src.c
567 git commit -m 'Add a comment to an upstream file'
569 t-gbp-unapplied-pq2qc
571 t-commit 'some updates' 1.0-2
574 -m 'Pseudo-merge to make descendant of archive' \
575 remotes/dgit/dgit/sid
581 dch -v$v --distribution unstable "$1"
582 git add debian/changelog
584 revision=$(( ${revision-0} + 1 ))
588 git config --global "$@"
592 export DGIT_TEST_TROOT=$troot
593 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
594 t-git-config dgit-distro.test-dummy.git-check true
595 t-git-config dgit-distro.test-dummy.git-create true
596 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
597 cp $troot/suites $tmp/.
598 cp $troot/suites $tmp/suites-master
600 export t_check_pushed_master=t-check-pushed-master
602 drs_dispatch=$tmp/distro=test-dummy
605 if [ "x$DGIT_TEST_INTREE" != x ]; then
606 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
609 ln -sf $tmp/git $drs_dispatch/repos
610 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
611 mkdir -p $drs_dispatch/keyrings
612 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
613 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
614 ln -sf /bin/true $drs_dispatch/policy-hook
619 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
620 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
621 t-git-config dgit-distro.test-dummy.git-create true
622 t-git-config dgit-distro.test-dummy.git-url \
623 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
625 t-git-config dgit-distro.test-dummy.diverts.drs /drs
626 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
627 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
628 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
629 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
631 echo 'no-such-package* drs' >$drs_dispatch/diverts
635 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
638 t-policy-nonexist () {
639 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
642 t-make-hook-link () {
643 local hook=$1 # in infra/
645 hook=${DGIT_INFRA_PFX}$hook
648 *) hook=`type -P $hook` ;;
650 ln -sf "$hook" $linkpath
655 t-make-hook-link $policyhook $drs_dispatch/policy-hook
660 t-policy dgit-repos-policy-debian
663 t-policy-admin create-db
666 t-policy-periodic () {
667 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
668 test-dummy $drs_dispatch '' --cron
673 (cd $root; t-restriction-$restriction >&2)
677 : "Hopefully installed: $*"
684 export DGIT_TEST_TESTNAME="$testname"
692 t-chain-test "${t#*-}"