11 : ${DGIT_TEST_DEBUG:=-D}
12 export DGIT_TEST_DEBUG
16 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
19 if [ x"$tmp" = x ]; then
21 tmp=tests/tmp/$testname
34 cp $troot/gnupg/* $tmp/gnupg
35 chmod go-rw $tmp/gnupg/*
37 export DEBCHANGE_VENDOR=dpkg
39 mkdir -p $tmp/incoming
40 cat <<END >$tmp/dput.cf
43 incoming = $tmp/incoming
48 local mpat="$1"; shift
51 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
52 local ps="${PIPESTATUS[*]}"
56 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
58 *) fail "tee failed" ;;
61 t-grep-mpat "$mpat" $tmp/t.output
74 *) fail "bad mpat prefix in $mpat";;
80 $grepper -e "$mpat" "$file" ||
81 fail "message not found"
84 t-expect-push-fail () {
85 local mpat="$1"; shift
87 local triedpush=`git rev-parse HEAD`
90 t-expect-fail "$mpat" "$@"
92 diff $tmp/show-refs.{pre,post}-push
94 t-git-objects-not-present '' $triedpush
96 eval "$t_expect_push_fail_hook"
99 t-git-objects-not-present () {
100 # t-git-objects-not-present GITDIR|'' OBJID [...]
101 # specifying '' means the repo for package $p
102 local gitdir="${1-$dgitrepo}"
104 if ! [ -e "$gitdir" ]; then return; fi
107 t-expect-fail 'unable to find' \
113 local whichoutput=$1; shift
114 local outputfile="$tmp/show-refs.$whichoutput"
117 if test -d $dgitrepo; then
125 local edittree=$1.edit
126 if test -d "$edittree"; then
127 cp -al "$edittree"/* .
135 t-untar $troot/worktrees/${p}_$1
138 t-select-package () {
140 dgitrepo=$tmp/git/$p.git
147 local gs=$troot/git-srcs/${p}_$v.git
148 (set -e; cd $tmp/git; t-untar $gs)
153 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
156 t-git-merge-base () {
157 git merge-base $1 $2 || test $? = 1
161 local now=`git rev-parse HEAD`
162 local ancestor=`git rev-parse $1^{}`
163 local mbase=`t-git-merge-base $ancestor $now`
164 if [ x$mbase != x$ancestor ]; then
165 fail "not ff $ancestor..$now, $mbase != $ancestor"
169 t-prep-newpackage () {
176 if ! git show-ref --verify --quiet refs/heads/master; then
177 git branch -m dgit/sid master
185 mkdir -p $tmp/aq $tmp/mirror/pool/main
189 >$tmp/aq/package.$suite.$p
190 t-archive-updated $suite $p
192 >$tmp/aq/package.new.$p
193 t-archive-updated new $p
195 ln -s sid $tmp/aq/dsc_in_suite/unstable
196 cat <<'END' >$tmp/aq/suites
199 "archive" : "ftp-master",
207 "dakname" : "unstable"
213 t-archive-updated () {
216 local suitedir=$tmp/aq/dsc_in_suite/$suite
218 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
222 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
230 print to_json \@v or die $!;
235 t-archive-process-incoming () {
237 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
238 t-archive-query "$suite"
243 local dscf=main/${p}_${v}.dsc
244 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
245 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
246 t-archive-updated $suite $p
252 local dscf=${p}_$2.dsc
253 rm -f $tmp/mirror/pool/main/${p}_*
254 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
258 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
261 t-git-dir-time-passes () {
262 touch -d 'last year' $dgitrepo
266 local gitdir=$dgitrepo
269 if test -e "$gitdir"; then fail "$gitdir exists"; fi
272 public) wantstat='7[75]5' ;;
273 secret) wantstat='7[70]0' ;;
274 *) fail "$1 t-git-dir-check ?" ;;
276 gotstat=`stat -c%a $gitdir`
278 *$wantstat) return ;;
279 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
283 t-rm-dput-dropping () {
284 rm -f $tmp/${p}_${v}_*.upload
288 local dgit=${DGIT_TEST-dgit}
291 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
292 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
293 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
295 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
300 diff --exclude=.git --exclude=.pc -ruN $*
303 t-cloned-fetched-good () {
304 t-diff-nogit ../extract/$p-${v%-*} .
305 t-clean-on-branch dgit/sid
308 refs/heads/dgit/sid \
309 refs/remotes/dgit/dgit/sid
310 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
314 printf "%s\n" "$1" >$tmp/t.want
317 diff $tmp/t.want $tmp/t.got
320 t-clean-on-branch () {
321 t-output "## $1" git status -b --porcelain
324 t-git-get-ref-exact () {
326 # does not dereference, unlike t-git-get-ref
329 *) fail "t-git-get-ref-exact bad $ref" ;;
331 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
338 *) fail "t-git-get-ref bad $ref" ;;
340 (git show-ref -d $1 || test $? = 1) | perl -ne '
341 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
342 END { print "$x\n" if length $x; }
346 t-ref-same-exact () {
348 local val=`t-git-get-ref-exact $name`
349 t-ref-same-val "$name" $val
354 local val=`t-git-get-ref $name`
355 t-ref-same-val "$name" $val
359 local val=`git rev-parse HEAD`
360 t-ref-same-val HEAD $val
369 *) fail "ref varies: $name: $val != $t_ref_val" ;;
374 t-refs-same-start () {
388 val=`t-git-get-ref $g`
389 if [ "x$val" != x ]; then
390 fail "ref $g unexpectedly exists ($val)"
396 echo refs/tags/test-dummy/${v//\~/_}
399 t-check-pushed-master () {
400 local master=`t-git-get-ref refs/heads/master`
401 if [ x$master = x$t_ref_val ]; then return; fi
402 if [ x$master = x ]; then fail "failed to push master"; fi
403 # didn't update master, it must be not FF
404 local mbase=`t-git-merge-base $master $t_ref_val`
405 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
414 refs/remotes/dgit/dgit/sid
416 refs/heads/dgit/unstable \
417 refs/remotes/dgit/dgit/unstable
418 (set -e; cd $dgitrepo
422 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
426 git verify-tag `t-v-tag`
433 use Dpkg::Control::Hash;
434 my $h = new Dpkg::Control::Hash allow_pgp=>1;
435 $h->parse(\*STDIN,"'"$file"'");
436 my $val = $h->{"'$field'"},"\n";
437 die "'"$file $field"'" unless defined $val;
449 *) '$var'="$tstunt:$'$var'" ;;
455 local tstunt=$tmp/tstunt
456 t-stunt-envvar PATH $tstunt
457 t-stunt-envvar PERLLIB $tstunt
461 local d="$tstunt/${f%/*}"
463 ln -sf "$troot/tstunt/$f" "$d"/.
467 t-tstunt-parsechangelog () {
468 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
472 local dsc=${p}_${v}.dsc
473 local val=`t-822-field $tmp/incoming/$dsc Dgit`
474 perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
475 t-ref-same-val $dsc "$val"
482 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
489 dch -v$v --distribution unstable "$1"
490 git add debian/changelog
492 revision=$(( ${revision-0} + 1 ))
496 git config --global "$@"
500 export DGIT_TEST_TROOT=$troot
501 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
502 t-git-config dgit-distro.test-dummy.git-check true
503 t-git-config dgit-distro.test-dummy.git-create true
504 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
505 cp $troot/suites $tmp/.
506 cp $troot/suites $tmp/suites-master
508 export t_check_pushed_master=t-check-pushed-master
510 drs_dispatch=$tmp/distro=test-dummy
513 if [ "x$DGIT_TEST_INTREE" != x ]; then
514 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
517 ln -sf $tmp/git $drs_dispatch/repos
518 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
519 mkdir -p $drs_dispatch/keyrings
520 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
521 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
522 ln -sf /bin/true $drs_dispatch/policy-hook
527 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
528 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
529 t-git-config dgit-distro.test-dummy.git-create true
530 t-git-config dgit-distro.test-dummy.git-url \
531 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
533 t-git-config dgit-distro.test-dummy.diverts.drs /drs
534 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
535 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
536 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
537 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
539 echo 'no-such-package* drs' >$drs_dispatch/diverts
543 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
546 t-policy-nonexist () {
547 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
552 policyhook=${DGIT_INFRA_PFX}$policyhook
555 *) policyhook=`type -P $policyhook` ;;
557 ln -sf "$policyhook" $drs_dispatch/policy-hook
562 t-policy dgit-repos-policy-debian
565 t-policy-admin create-db
568 t-policy-periodic () {
569 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
570 test-dummy $drs_dispatch '' --cron
577 export DGIT_TEST_TESTNAME="$testname"
585 t-chain-test "${t#*-}"