17 lines: ${BASH_LINENO[*]}
18 files: ${BASH_SOURCE[*]}
23 trap 'test $? = 0 || t-report-failure' EXIT
25 t-filter-out-git-hyphen-dir
29 : ${DGIT_TEST_DEBUG=-D}
30 export DGIT_TEST_DEBUG
32 : ${DGIT_TEST_DISTRO+ ${distro=${DGIT_TEST_DISTRO}}}
34 export GIT_COMMITTER_DATE='1440253867 +0100'
35 export GIT_AUTHOR_DATE='1440253867 +0100'
39 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
40 export DGIT_TEST_TROOT=$troot
43 if [ x"$tmp" = x ]; then
46 tmp=tests/tmp/$testname
49 elif [ "x$DGIT_TEST_TMPBASE" != x ]; then
50 tmpbase="$DGIT_TEST_TMPBASE"
58 test -f $tmp/.save-env || \
59 env -0 >$tmp/.save-env
63 export DEBCHANGE_VENDOR=dpkg
65 mkdir -p $tmp/incoming
66 cat <<END >$tmp/dput.cf
69 incoming = $tmp/incoming
73 : ${t_archive_method:=aq}
74 : ${tagpfx:=archive/test-dummy}
75 : ${suitespecs:=sid:unstable}
78 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
79 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
83 local mpat="$1"; shift
86 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
87 local ps="${PIPESTATUS[*]}"
91 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
93 *) fail "tee failed" ;;
96 t-grep-mpat "$mpat" $tmp/t.output
107 E:*) grepper=egrep ;;
108 F:*) grepper=fgrep ;;
109 *) fail "bad mpat prefix in $mpat";;
115 $grepper -e "$mpat" "$file" ||
116 fail "message not found"
119 t-expect-push-fail () {
120 local mpat="$1"; shift
122 local triedpush; triedpush=`git rev-parse HEAD`
125 t-expect-fail "$mpat" "$@"
127 diff $tmp/show-refs.{pre,post}-push
129 t-git-objects-not-present '' $triedpush
131 eval "$t_expect_push_fail_hook"
134 t-git-objects-not-present () {
135 # t-git-objects-not-present GITDIR|'' OBJID [...]
136 # specifying '' means the repo for package $p
137 local gitdir="${1-$dgitrepo}"
139 if ! [ -e "$gitdir" ]; then return; fi
142 t-expect-fail 'unable to find' \
148 local whichoutput=$1; shift
149 local whichrepo=${1-$dgitrepo}
150 local outputfile="$tmp/show-refs.$whichoutput"
153 if test -d $whichrepo; then
161 local edittree=$1.edit
162 if test -d "$edittree"; then
163 cp -a "$edittree"/* .
171 t-untar $troot/worktrees/${p}_$1
174 t-select-package () {
176 dgitrepo=$tmp/git/$p.git
183 local gs=$troot/git-srcs/${p}_$v.git
184 (set -e; cd $tmp/git; t-untar $gs)
189 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
192 t-git-merge-base () {
193 git merge-base $1 $2 || test $? = 1
197 # t-has-ancestor ANCESTOR
198 # (CHILD is implicit, HEAD)
199 local now; now=`git rev-parse HEAD`
200 local ancestor; ancestor=`git rev-parse $1^{}`
201 local mbase; mbase=`t-git-merge-base $ancestor $now`
202 if [ x$mbase != x$ancestor ]; then
203 fail "not ff $ancestor..$now, $mbase != $ancestor"
207 t-has-parent-or-is () {
208 # t-has-parent-or-is CHILD PARENT
212 parents=$(git show --pretty=format:' %P %H ' "$child")
213 parent=$(git rev-parse "$parent~0")
216 *) fail "child $child lacks parent $parent" ;;
220 t-prep-newpackage () {
227 if ! git show-ref --verify --quiet refs/heads/master; then
228 git branch -m dgit/sid master
236 t-archive-none-$t_archive_method
238 t-archive-none-aq () {
239 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
245 for suitespec in $suitespecs; do
246 local suite=${suitespec%%:*}
247 local sname=${suitespec#*:}
249 >$tmp/aq/package.$suite.$p
250 t-aq-archive-updated $suite $p
252 >$tmp/aq/package.new.$p
253 t-aq-archive-updated new $p
255 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
257 cat <<END >>$tmp/aq/suites
260 "archive" : "ftp-master",
261 "codename" : "$suite",
274 cat <<END >>$tmp/aq/suites
280 t-aq-archive-updated () {
283 local suitedir=$tmp/aq/dsc_in_suite/$suite
285 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
289 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
297 my $json = JSON->new->canonical();
298 print $json->encode(\@v) or die $!;
303 t-archive-process-incoming () {
305 mv $tmp/incoming/${p}_* $tmp/mirror/pool/main/
306 t-archive-query "$suite"
311 local dscf=main/${p}_${v}.dsc
312 t-archive-query-$t_archive_method "$suite" "$p" "$v" "$dscf"
314 t-archive-query-aq () {
319 local sha; sha=`sha256sum <$tmp/mirror/pool/$dscf`
320 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
321 t-aq-archive-updated $suite $p
327 local dscf=${p}_$2.dsc
328 rm -f $tmp/mirror/pool/main/${p}_*
329 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
330 t-archive-query $suite
333 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
336 t-git-dir-time-passes () {
337 touch -d 'last year' $dgitrepo
341 local gitdir=$dgitrepo
344 if test -e "$gitdir"; then fail "$gitdir exists"; fi
347 public) wantstat='7[75]5' ;;
348 secret) wantstat='7[70]0' ;;
349 *) fail "$1 t-git-dir-check ?" ;;
351 gotstat=`stat -c%a $gitdir`
353 *$wantstat) return ;;
354 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
358 t-expect-fsck-fail () {
359 echo >>$tmp/fsck.expected-errors "$1"
363 local fsckerrs=$(git rev-parse --git-dir)/dgit-test-fsck.errs
366 LC_MESSAGES=C git fsck --no-dangling --strict 2>&1 \
368 ps="${PIPESTATUS[*]}"
372 if [ -f $tmp/fsck.expected-errors ]; then
373 pats=(-w -f $tmp/fsck.expected-errors)
377 pats+=(-e 'notice: HEAD points to an unborn branch')
378 pats+=(-e 'notice: No default references')
381 grep -v "${pats[@]}" $fsckerrs
385 1) ;; # no unexpected errors
386 0) fail "unexpected messages from git-fsck" ;;
387 *) fail "grep of git-fsck failed" ;;
394 for d in $tmp/*/.git $tmp/git/*.git; do
402 : '========================================'
407 t-rm-dput-dropping () {
408 rm -f $tmp/${p}_${v}_*.upload
412 local dgit=${DGIT_TEST-dgit}
415 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
416 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
417 ${dgit_config_debian_alias-"--config-lookup-explode=dgit-distro.debian.alias-canon"} \
418 ${distro+${distro:+-d}}${distro--dtest-dummy} \
419 $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
420 -k39B13D8A $t_dgit_xopts "$@"
421 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
428 (export LC_ALL=C.UTF-8
429 if [ "$DGIT_TEST_INTREE" ]; then
430 make -C $DGIT_TEST_INTREE $page.$section.view
437 diff --exclude=.git --exclude=.pc -ruN $*
440 t-files-notexist () {
449 t-cloned-fetched-good () {
450 t-diff-nogit ../extract/$p-${v%-*} .
451 t-clean-on-branch dgit/sid
454 refs/heads/dgit/sid \
455 refs/remotes/dgit/dgit/sid
456 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
460 printf "%s${1:+\n}" "$1" >$tmp/t.want
463 diff $tmp/t.want $tmp/t.got
466 t-clean-on-branch () {
467 t-output "## $1" git status -b --porcelain
475 local import=IMPORT.${0##*/}
476 exec 4>$tmp/$import.new
479 for vn in $savevars; do
480 perl >&4 -I. -MDebian::Dgit -e '
481 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
482 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
485 (set -e; cd $tmp; tar cf $import.tar $savedirs)
487 printf >&4 "\n%s\n" "$importeval"
489 mv -f $tmp/$import.new $tmp/$import
497 if [ "x$tmpbase" = x ]; then
498 # ADTTMP was set on entry to tests/lib, so we
499 # are not sharing tmp area between tests
501 lock="$tmp/.dummy.lock"
503 setupsrc="$tmpbase/$setupname"
504 lock="$setupsrc.lock"
507 local simport="$setupsrc/IMPORT.$setupname"
509 if ! [ -e "$simport" ]; then
510 with-lock-ex -w "$lock" \
511 xargs -0 -a $tmp/.save-env \
514 setupname="$1"; shift
516 if [ -e "$simport" ]; then exit 0; fi
518 "tests/setup/$setupname"
519 ' x "$root" "$setupname" "$simport"
522 if [ "x$setupsrc" != "x$tmp" ]; then
523 (set -e; cd $tmp; tar xf "$simport.tar")
529 t-git-get-ref-exact () {
531 # does not dereference, unlike t-git-get-ref
534 *) fail "t-git-get-ref-exact bad $ref" ;;
536 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
543 *) fail "t-git-get-ref bad $ref" ;;
545 (git show-ref -d $1 || test $? = 1) | perl -ne '
546 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
547 END { print "$x\n" if length $x; }
551 t-ref-same-exact () {
553 local val; val=`t-git-get-ref-exact $name`
554 t-ref-same-val "$name" $val
559 local val; val=`t-git-get-ref $name`
560 t-ref-same-val "$name" $val
564 local val; val=`git rev-parse HEAD`
565 t-ref-same-val HEAD $val
571 case "${t_ref_val-unset}" in
574 *) fail "ref varies: ($name)\
575 ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
578 t_ref_names+=("$name")
581 t-refs-same-start () {
596 val=`t-git-get-ref $g`
597 if [ "x$val" != x ]; then
598 fail "ref $g unexpectedly exists ($val)"
604 echo refs/tags/$tagpfx/${v//\~/_}
608 git log -n1 --pretty=format:"$1" "$2"
611 t-sametree-parent () {
614 local ctree; ctree=$(t-format-ref '%T' "$ref")
617 for parent in $(t-format-ref '%P' "$ref"); do
618 local ptree; ptree=$(t-format-ref '%T' "$parent")
619 if [ "x$ptree" = "x$ctree" ]; then
623 case "$psame" in ""|" * *") break ;; esac
629 t-check-pushed-master () {
630 local master; master=`t-git-get-ref refs/heads/master`
631 if [ x$master = x$t_ref_val ]; then return; fi
632 if [ x$master = x ]; then fail "failed to push master"; fi
633 # didn't update master, it must be not FF
634 local mbase; mbase=`t-git-merge-base $master $t_ref_val`
635 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
640 local suite=${2:-sid}
646 t-pushed-good-core () {
650 refs/remotes/dgit/dgit/$suite
652 refs/heads/dgit/unstable \
653 refs/remotes/dgit/dgit/unstable
654 (set -e; cd $dgitrepo
658 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
662 git verify-tag `t-v-tag`
665 t-splitbrain-pushed-good--unpack () {
670 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
671 ln -s $tmp/incoming/*.orig*.tar* . ||:
672 ln -s $incoming_dsc .
673 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
674 dpkg-source "$@" -x *.dsc
677 git fetch ../../$p "refs/tags/*:refs/tags/*"
680 t-splitbrain-pushed-good--checkprep () {
682 git rm --cached -r --ignore-unmatch .pc
685 t-splitbrain-pushed-good--checkdiff () {
687 t-splitbrain-pushed-good--checkprep
688 t-output "" git diff --stat --cached $tag
691 t-splitbrain-pushed-good-start () {
692 dep14tag=refs/tags/test-dummy/${v//\~/_}
694 t-output "" git status --porcelain
696 t-refs-same $dep14tag
697 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
698 git merge-base --is-ancestor $dep14tag $dgittag
701 t-ref-same refs/heads/split.p
702 case "$(t-git-get-ref refs/heads/split.b)" in
704 "$(git rev-parse refs/heads/split.p^0)") ;;
705 "$(git rev-parse refs/heads/split.p^1)") ;;
712 t-splitbrain-pushed-good--unpack
713 t-splitbrain-pushed-good--checkdiff $dgittag
715 t-splitbrain-pushed-good-end-made-dep14 () {
716 t-splitbrain-pushed-good--checkdiff $dep14tag
720 t-splitbrain-rm-gitignore-patch () {
722 next unless $_ eq "auto-gitignore\n";
725 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
727 ' debian/patches/series
730 t-gbp-pushed-good () {
731 local suite=${1:-sid}
732 t-splitbrain-pushed-good-start
734 # Right, now we want to check that the maintainer tree and
735 # the dgit tree differ in exactly the ways we expect. We
736 # achieve this by trying to reconstruct the maintainer tree
737 # from the dgit tree.
739 # So, unpack it withut the patches applied
740 t-splitbrain-pushed-good--unpack --skip-patches
742 # dgit might have added a .gitignore patch, which we need to
744 t-splitbrain-rm-gitignore-patch
746 # Now the result should differ only in non-debian/ .gitignores
747 t-splitbrain-pushed-good--checkprep
748 git diff --cached --name-only $dep14tag >../changed
750 next if !m#^debian/# && m#(^|/)\.gitignore#;
754 # If we actually apply the gitignore patch by hand, it
756 if [ -f ../t-auto-gitignore ]; then
757 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
760 t-splitbrain-pushed-good-end-made-dep14
763 t-unapplied-pushed-good () {
764 t-splitbrain-pushed-good-start
765 t-splitbrain-pushed-good--unpack --skip-patches
766 t-splitbrain-pushed-good-end-made-dep14
769 t-dpm-pushed-good () {
770 t-splitbrain-pushed-good-start
771 t-splitbrain-pushed-good--unpack
772 t-splitbrain-rm-gitignore-patch
773 t-splitbrain-pushed-good-end-made-dep14
776 t-commit-build-push-expect-log () {
782 t-dgit push --new 2>&1 |tee $tmp/push.log
783 t-grep-mpat "$mpat" $tmp/push.log
790 use Dpkg::Control::Hash;
791 my $h = new Dpkg::Control::Hash allow_pgp=>1;
792 $h->parse(\*STDIN,"'"$file"'");
793 my $val = $h->{"'$field'"},"\n";
794 die "'"$file $field"'" unless defined $val;
800 export DGIT_TEST_DISTRO=''
802 t-git-config dgit-suite.unstable.distro test-dummy
812 "") '$var'="$tstunt" ;;
813 *) '$var'="$tstunt:$'$var'" ;;
819 t-tstunt--save-real () {
830 p="${p/:"$tmp/tstunt":/:}"
842 *) fail "did not find $f on PATH $PATH" ;;
845 local varname=${f//[^_0-9a-zA-Z]/_}
846 varname=DGIT_TEST_REAL_${varname^^}
849 : \${$varname:=\$real}
855 local tstunt=$tmp/tstunt
856 t-stunt-envvar PATH $tstunt
857 t-stunt-envvar PERLLIB $tstunt
860 t-tstunt--save-real $f
862 local d="$tstunt/${f%/*}"
864 ln -sf "$troot/tstunt/$f" "$d"/.
868 t-tstunt-parsechangelog () {
869 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
872 t-tstunt-lintian () {
876 t-tstunt-debuild () {
881 local dsc=${p}_${v}.dsc
882 incoming_dsc=$tmp/incoming/$dsc
887 local val; val=`t-822-field $incoming_dsc Dgit`
890 die "Dgit $_ ?" unless m/^\w+\b/;
891 print $&,"\n" or die $!;
893 t-ref-same-val $incoming_dsc "$val"
900 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
904 t-gbp-unapplied-pq2qc () {
905 # does `gbp pq export'
906 # commits the resulting debian/patches on qc/BRANCH
907 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
908 # qc/BRANCH is not fast-forwarding
912 branch=`git symbolic-ref HEAD`
913 branch=${branch#refs/heads/}
916 */*) fail "unexpected branch $branch" ;;
919 git branch -f qc/$branch
920 git checkout qc/$branch
921 git add debian/patches
922 git commit -m 'Commit patch queue'
925 t-git-pseudo-merge () {
926 # like git merge -s ours
927 if [ ! "$git_pseuomerge_opts" ]; then
928 if git merge --help \
929 | grep -q allow-unrelated-histories; then
930 git_pseuomerge_opts='--allow-unrelated-histories'
932 git_pseuomerge_opts+=' -s ours'
934 git merge $git_pseuomerge_opts "$@"
937 t-gbp-example-prep-no-ff () {
938 t-tstunt-parsechangelog
939 t-archive example 1.0-1
947 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
950 echo '/* some comment */' >>src.c
952 git commit -m 'Add a comment to an upstream file'
954 t-gbp-unapplied-pq2qc
956 t-commit 'some updates' 1.0-2
959 t-gbp-example-prep () {
960 t-gbp-example-prep-no-ff
963 -m 'Pseudo-merge to make descendant of archive' \
964 remotes/dgit/dgit/sid
967 t-make-badcommit () {
969 git cat-file commit HEAD | \
970 perl -pe 's/^committer /commiter /' | \
971 git hash-object -w -t commit --stdin
973 t-expect-fsck-fail $badcommit
978 v=${2:-${majorv:-1}.$revision}
979 dch --force-distribution -v$v --distribution ${3:-unstable} "$1"
980 git add debian/changelog
982 revision=$(( ${revision-0} + 1 ))
986 git config --global "$@"
990 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
991 t-git-config dgit-distro.test-dummy.git-check true
992 t-git-config dgit-distro.test-dummy.git-create true
993 t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
994 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
995 cp $troot/suites $tmp/.
996 cp $troot/suites $tmp/suites-master
998 export t_check_pushed_master=t-check-pushed-master
1000 drs_dispatch=$tmp/distro=test-dummy
1003 if [ "x$DGIT_TEST_INTREE" != x ]; then
1004 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
1007 ln -sf $tmp/git $drs_dispatch/repos
1008 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
1009 mkdir -p $drs_dispatch/keyrings
1010 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
1011 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
1012 ln -sf /bin/true $drs_dispatch/policy-hook
1016 export tagpfx=archive/test-dummy
1017 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
1020 export tagpfx=test-dummy
1021 t-git-config dgit-distro.test-dummy.dgit-tag-format old
1026 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
1027 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
1028 t-git-config dgit-distro.test-dummy.git-create true
1029 t-git-config dgit-distro.test-dummy.git-url \
1030 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
1032 t-git-config dgit-distro.test-dummy.diverts.drs /drs
1033 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
1034 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
1035 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
1036 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
1038 echo 'no-such-package* drs' >$drs_dispatch/diverts
1042 : '(((((((((((((((((((((((((((((((((((((((('
1043 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
1044 : '))))))))))))))))))))))))))))))))))))))))'
1047 t-policy-nonexist () {
1048 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
1051 t-make-hook-link () {
1052 local hook=$1 # in infra/
1054 hook=${DGIT_INFRA_PFX}$hook
1057 *) hook=`type -P $hook` ;;
1059 ln -sf "$hook" $linkpath
1064 t-make-hook-link $policyhook $drs_dispatch/policy-hook
1069 t-policy dgit-repos-policy-debian
1072 t-policy-admin create-db
1075 t-policy-periodic () {
1076 : '(((((((((((((((((((((((((((((((((((((((('
1077 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
1078 test-dummy $drs_dispatch '' --cron
1079 : '))))))))))))))))))))))))))))))))))))))))'
1083 local restriction=$1
1084 (cd $root; t-restriction-$restriction >&2)
1088 : "Hopefully installed: $*"
1095 export DGIT_TEST_TESTNAME="$testname"
1096 export DGIT_TEST_TMPBASE="$tmpbase"
1104 t-chain-test "${t#*-}"
1107 t-git-config dgit.default.old-dsc-distro test-dummy
1111 *) t-setup-import gnupg ;;