]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
* debian/apt.cron.daily:
[apt.git] / test / integration / framework
index 4bbe1b408e15c0b12a8fc7f50b4b6a5abe0972b4..013a71ec02cbcf0515ecd449e64ba015f70401e7 100644 (file)
@@ -39,6 +39,10 @@ fi
 if [ $MSGLEVEL -le 2 ]; then
        msgmsg() { true; }
        msgnmsg() { true; }
+       msgtest() { true; }
+       msgpass() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
+       msgskip() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
+       msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; }
 fi
 if [ $MSGLEVEL -le 3 ]; then
        msginfo() { true; }
@@ -75,6 +79,7 @@ aptcache() { runapt apt-cache $*; }
 aptget() { runapt apt-get $*; }
 aptftparchive() { runapt apt-ftparchive $*; }
 aptkey() { runapt apt-key $*; }
+aptmark() { runapt apt-mark $*; }
 dpkg() {
        $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $*
 }
@@ -88,6 +93,11 @@ aptitude() {
        fi
 }
 
+addtrap() {
+       CURRENTTRAP="$CURRENTTRAP $1"
+       trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
+}
+
 setupenvironment() {
        TMPWORKINGDIRECTORY=$(mktemp -d)
        local TESTDIR=$(readlink -f $(dirname $0))
@@ -95,8 +105,7 @@ setupenvironment() {
        BUILDDIRECTORY="${TESTDIR}/../../build/bin"
        test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
        local OLDWORKINGDIRECTORY=$(pwd)
-       CURRENTTRAP="cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY"
-       trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
+       addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY;"
        cd $TMPWORKINGDIRECTORY
        mkdir rootdir aptarchive keys
        cd rootdir
@@ -180,8 +189,12 @@ Maintainer: Joe Sixpack <joe@example.org>
 Build-Depends: debhelper (>= 7)
 Standards-Version: 3.9.1
 
-Package: $NAME
-Architecture: $ARCH" > debian/control
+Package: $NAME" > debian/control
+       if [ "$ARCH" = 'all' ]; then
+               echo "Architecture: all" >> debian/control
+       else
+               echo "Architecture: any" >> debian/control
+       fi
        test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
        if [ -z "$DESCRIPTION" ]; then
                echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
@@ -211,9 +224,64 @@ buildsimplenativepackage() {
        else
                DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
        fi
-       setupsimplenativepackage "$NAME" "$ARCH" "$VERSION" "$RELEASE" "$DEPENDENCIES" "$DESCRIPTION" "$SECTION"
-       buildpackage "incoming/${NAME}-${VERSION}" "$RELEASE" "$DISTSECTION"
-       rm -rf "incoming/${NAME}-${VERSION}"
+       local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
+
+       msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
+       mkdir -p $BUILDDIR/debian/source
+       echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
+       echo "#!/bin/sh
+echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
+
+       echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
+       echo "$NAME ($VERSION) $RELEASE; urgency=low
+
+  * Initial release
+
+ -- Joe Sixpack <joe@example.org>  $(date -R)" > ${BUILDDIR}/debian/changelog
+       echo "Source: $NAME
+Section: $SECTION
+Priority: optional
+Maintainer: Joe Sixpack <joe@example.org>
+Standards-Version: 3.9.1
+
+Package: $NAME" > ${BUILDDIR}/debian/control
+       if [ "$ARCH" = 'all' ]; then
+               echo "Architecture: all" >> ${BUILDDIR}/debian/control
+       else
+               echo "Architecture: any" >> ${BUILDDIR}/debian/control
+       fi
+       test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> ${BUILDDIR}/debian/control
+       if [ -z "$DESCRIPTION" ]; then
+               echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
+ If you find such a package installed on your system,
+ YOU did something horribly wrong! They are autogenerated
+ und used only by testcases for APT and surf no other propose…" >> ${BUILDDIR}/debian/control
+       else
+               echo "Description: $DESCRIPTION" >> ${BUILDIR}/debian/control
+       fi
+       echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
+       local SRCS="$( (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
+       for SRC in $SRCS; do
+               echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
+       done
+
+       for arch in $(echo "$ARCH" | sed -e 's#,#\n#g'); do
+               rm -rf ${BUILDDIR}/debian/tmp
+               mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
+               cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
+               cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
+               (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
+               (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
+
+               dpkg-deb --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. 2> /dev/null > /dev/null
+               echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
+       done
+
+       mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
+       cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
+       cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
+       rm -rf "${BUILDDIR}"
+       msgdone "info"
 }
 
 buildpackage() {
@@ -264,9 +332,11 @@ createaptftparchiveconfig() {
        echo -n '";
 };
 Default {
-       Packages::Compress ". gzip bzip2 lzma";
-       Sources::Compress ". gzip bzip2 lzma";
-       Contents::Compress ". gzip bzip2 lzma";
+       Packages::Compress ". gzip bzip2 lzma xz";
+       Sources::Compress ". gzip bzip2 lzma xz";
+       Contents::Compress ". gzip bzip2 lzma xz";
+       Translation::Compress ". gzip bzip2 lzma xz";
+       LongDescription "false";
 };
 TreeDefault {
        Directory "pool/";
@@ -352,6 +422,29 @@ Filename: pool/main/${NAME}/${NAME}_${VERSION}_${ARCH}.deb" >> $FILE
        done
 }
 
+insertinstalledpackage() {
+       local NAME="$1"
+       local ARCH="$2"
+       local VERSION="$3"
+       local DEPENDENCIES="$4"
+       local FILE="rootdir/var/lib/dpkg/status"
+       echo "Package: $NAME
+Status: install ok installed
+Priority: optional
+Section: other
+Installed-Size: 42
+Maintainer: Joe Sixpack <joe@example.org>
+Architecture: $ARCH
+Version: $VERSION" >> $FILE
+       test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
+       echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
+ If you find such a package installed on your system,
+ YOU did something horribly wrong! They are autogenerated
+ und used only by testcases for APT and surf no other propose…
+" >> $FILE
+}
+
+
 buildaptarchivefromincoming() {
        msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
        cd aptarchive
@@ -372,6 +465,7 @@ buildaptarchivefromfiles() {
                cat ${line} | gzip > ${line}.gz
                cat ${line} | bzip2 > ${line}.bz2
                cat ${line} | lzma > ${line}.lzma
+               cat ${line} | xz > ${line}.xz
                msgdone "info"
        done
        generatereleasefiles
@@ -379,7 +473,11 @@ buildaptarchivefromfiles() {
 
 generatereleasefiles() {
        msgninfo "\tGenerate Release files… "
+       local DATE="${1:-now}"
        if [ -e aptarchive/dists ]; then
+               for dir in $(find ./aptarchive/dists -mindepth 3 -maxdepth 3 -type d -name 'i18n'); do
+                       aptftparchive -qq release $dir -o APT::FTPArchive::Release::Patterns::='Translation-*' > $dir/Index
+               done
                for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
                        local CODENAME="$(echo "$dir" | cut -d'/' -f 4)"
                        aptftparchive -qq release $dir -o APT::FTPArchive::Release::Suite="${CODENAME}" -o APT::FTPArchive::Release::Codename="${CODENAME}" | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
@@ -391,6 +489,11 @@ NotAutomatic: yes' $dir/Release
        else
                aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
        fi
+       if [ "$DATE" != "now" ]; then
+               for release in $(find ./aptarchive -name 'Release'); do
+                       touch -d "$1" $release
+               done
+       fi
        msgdone "info"
 }
 
@@ -451,6 +554,7 @@ signreleasefiles() {
        done
        for RELEASE in $(find aptarchive/ -name Release); do
                gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE}
+               gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE
        done
        msgdone "info"
 }
@@ -458,8 +562,7 @@ signreleasefiles() {
 changetowebserver() {
        if which weborf > /dev/null; then
                weborf -xb aptarchive/ 2>&1 > /dev/null &
-               CURRENTTRAP="kill $!; $CURRENTTRAP"
-               trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
+               addtrap "kill $!;"
                local APTARCHIVE="file://$(readlink -f ./aptarchive)"
                for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
                        sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
@@ -493,17 +596,18 @@ testfileequal() {
 
 testequal() {
        local COMPAREFILE=$(mktemp)
+       addtrap "rm $COMPAREFILE;"
        echo "$1" > $COMPAREFILE
        shift
        msgtest "Test for equality of" "$*"
        $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
-       rm $COMPAREFILE
 }
 
 testequalor2() {
        local COMPAREFILE1=$(mktemp)
        local COMPAREFILE2=$(mktemp)
        local COMPAREAGAINST=$(mktemp)
+       addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
        echo "$1" > $COMPAREFILE1
        echo "$2" > $COMPAREFILE2
        shift 2
@@ -514,16 +618,15 @@ testequalor2() {
                ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
                       "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
                  msgfail )
-       rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
 }
 
 testshowvirtual() {
-       local VIRTUAL="N: Can't select versions from package '$1' as it purely virtual"
+       local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
        local PACKAGE="$1"
        shift
        while [ -n "$1" ]; do
                VIRTUAL="${VIRTUAL}
-N: Can't select versions from package '$1' as it purely virtual"
+N: Can't select versions from package '$1' as it is purely virtual"
                PACKAGE="${PACKAGE} $1"
                shift
        done
@@ -531,11 +634,11 @@ N: Can't select versions from package '$1' as it purely virtual"
        VIRTUAL="${VIRTUAL}
 N: No packages found"
        local COMPAREFILE=$(mktemp)
+       addtrap "rm $COMPAREFILE;"
        local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
        eval `apt-config shell ARCH APT::Architecture`
        echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
        aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
-       rm $COMPAREFILE
 }
 
 testnopackage() {
@@ -552,8 +655,8 @@ testnopackage() {
 
 testdpkginstalled() {
        msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
-       local PKGS="$(dpkg -l $* | grep '^[a-z]' | grep '^[^i]' | wc -l)"
-       if [ "$PKGS" != 0 ]; then
+       local PKGS="$(dpkg -l $* | grep '^i' | wc -l)"
+       if [ "$PKGS" != $# ]; then
                echo $PKGS
                dpkg -l $* | grep '^[a-z]'
                msgfail
@@ -562,9 +665,9 @@ testdpkginstalled() {
        msgpass
 }
 
-testdpkgnoninstalled() {
-       msgtest "Test for correctly non-installed package(s) with" "dpkg -l $*"
-       local PKGS="$(dpkg -l $* | grep '^[a-z]' | grep '^[^u]' | wc -l)"
+testdpkgnotinstalled() {
+       msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
+       local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
        if [ "$PKGS" != 0 ]; then
                echo
                dpkg -l $* | grep '^[a-z]'
@@ -573,3 +676,16 @@ testdpkgnoninstalled() {
        fi
        msgpass
 }
+
+testmarkedauto() {
+       local COMPAREFILE=$(mktemp)
+       addtrap "rm $COMPAREFILE;"
+       if [ -n "$1" ]; then
+               msgtest 'Test for correctly marked as auto-installed' "$*"
+               while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
+       else
+               msgtest 'Test for correctly marked as auto-installed' 'no package'
+               echo > $COMPAREFILE
+       fi
+       aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
+}