]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
hide Translation-* in 'apt-cache policy' output
[apt.git] / test / integration / framework
index ec23e41e6454a567e8d017d5df31739138a998af..7b03c09eff90fabef231cd7905e565436f0c2131 100644 (file)
@@ -3,7 +3,7 @@
 EXIT_CODE=0
 
 # we all like colorful messages
-if [ "$MSGCOLOR" != 'NO' ]; then
+if [ "$MSGCOLOR" != 'NO' ] && [ "$MSGCOLOR" != 'ALWAYS' ]; then
        if [ ! -t 1 ]; then # but check that we output to a terminal
                export MSGCOLOR='NO'
        fi
@@ -137,7 +137,14 @@ dpkgcheckbuilddeps() {
        command dpkg-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg "$@"
 }
 gdb() {
-       local CMD="$1"
+       local CMD
+       case "$1" in
+       aptget) CMD="apt-get";;
+       aptcache) CMD="apt-cache";;
+       aptmark) CMD="apt-mark";;
+       apthelper) CMD="apt-helper";;
+       *) CMD="$1";;
+       esac
        shift
        runapt command gdb --quiet -ex run "${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
 }
@@ -189,6 +196,7 @@ setupenvironment() {
 
        TESTDIRECTORY=$(readlink -f $(dirname $0))
         # allow overriding the default BUILDDIR location
+       SOURCEDIRECTORY=${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}
        BUILDDIRECTORY=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
        LIBRARYPATH=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
         METHODSDIR=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
@@ -834,7 +842,9 @@ buildaptarchivefromincoming() {
 
 buildaptarchivefromfiles() {
        msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
-       find aptarchive -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
+       local DIR='aptarchive'
+       if [ -d "${DIR}/dists" ]; then DIR="${DIR}/dists"; fi
+       find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
                msgninfo "\t${line} file… "
                compressfile "$line" "$1"
                msgdone "info"
@@ -1004,7 +1014,17 @@ signreleasefiles() {
        msgdone "info"
 }
 
+redatereleasefiles() {
+       local DATE="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
+       for release in $(find aptarchive/ -name 'Release'); do
+               sed -i "s/^Date: .*$/Date: ${DATE}/" $release
+               touch -d "$DATE" $release
+       done
+       signreleasefiles "${2:-Joe Sixpack}"
+}
+
 webserverconfig() {
+       local WEBSERVER="${3:-http://localhost:8080}"
        local NOCHECK=false
        if [ "$1" = '--no-check' ]; then
                NOCHECK=true
@@ -1016,10 +1036,10 @@ webserverconfig() {
        local URI
        if [ -n "$2" ]; then
                msgtest "Set webserver config option '${1}' to" "$2"
-               URI="http://localhost:8080/_config/set/${1}/${2}"
+               URI="${WEBSERVER}/_config/set/${1}/${2}"
        else
                msgtest 'Clear webserver config option' "${1}"
-               URI="http://localhost:8080/_config/clear/${1}"
+               URI="${WEBSERVER}/_config/clear/${1}"
        fi
        if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
                msgpass
@@ -1125,8 +1145,10 @@ acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
 
 downloadfile() {
        local PROTO="${1%%:*}"
-       apthelper -o Debug::Acquire::${PROTO}=1 -o Debug::pkgAcquire::Worker=1 \
-               download-file "$1" "$2" 2>&1 || true
+       if ! apthelper -o Debug::Acquire::${PROTO}=1 -o Debug::pkgAcquire::Worker=1 \
+               download-file "$1" "$2" "$3" 2>&1 ; then
+               return 1
+       fi
        # only if the file exists the download was successful
        if [ -r "$2" ]; then
                return 0
@@ -1151,9 +1173,9 @@ testfileequal() {
        shift
        msgtest "Test for correctness of file" "$FILE"
        if [ -z "$*" ]; then
-               echo -n "" | checkdiff $FILE - && msgpass || msgfail
+               echo -n "" | checkdiff - $FILE && msgpass || msgfail
        else
-               echo "$*" | checkdiff $FILE - && msgpass || msgfail
+               echo "$*" | checkdiff - $FILE && msgpass || msgfail
        fi
 }
 
@@ -1407,6 +1429,20 @@ testfailureequal() {
        testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" "$CMP"
 }
 
+testfailuremsg() {
+       local CMP="$1"
+       shift
+       testfailure "$@"
+       msgtest 'Check that the output of the previous failed command has expected' 'failures and warnings'
+       grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output" 2>&1 || true
+       if echo "$CMP" | checkdiff - "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output"; then
+               msgpass
+       else
+               echo '### Complete output ###'
+               cat "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
+               msgfail
+       fi
+}
 
 testfilestats() {
        msgtest "Test that file $1 has $2 $3" "$4"
@@ -1451,12 +1487,14 @@ pause() {
 }
 
 listcurrentlistsdirectory() {
-       find rootdir/var/lib/apt/lists -maxdepth 1 -type d | while read line; do
-               stat --format '%U:%G:%a:%n' "$line"
-       done
-       find rootdir/var/lib/apt/lists -maxdepth 1 \! -type d | while read line; do
-               stat --format '%U:%G:%a:%s:%y:%n' "$line"
-       done
+       {
+               find rootdir/var/lib/apt/lists -maxdepth 1 -type d | while read line; do
+                       stat --format '%U:%G:%a:%n' "$line"
+               done
+               find rootdir/var/lib/apt/lists -maxdepth 1 \! -type d | while read line; do
+                       stat --format '%U:%G:%a:%s:%y:%n' "$line"
+               done
+       } | sort
 }
 
 ### convinience hacks ###
@@ -1500,20 +1538,31 @@ aptautotest() {
 }
 
 aptautotest_aptget_update() {
+       local TESTCALL="$1"
+       while [ -n "$2" ]; do
+               if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
+               shift
+       done
        if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
        testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
        testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
        # all copied files are properly chmodded
-       for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -maxdepth 1 -type f ! -name 'lock'); do
+       for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
                testfilestats "$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
        done
+       if [ "$TESTCALL" = 'testsuccess' ]; then
+               # failure cases can retain partial files and such
+               testempty find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \( -name 'lock' -o -name '*.FAILED' \)
+       fi
 }
 aptautotest_apt_update() { aptautotest_aptget_update "$@"; }
+aptautotest_aptcdrom_add() { aptautotest_aptget_update "$@"; }
 
 testaptautotestnodpkgwarning() {
        local TESTCALL="$1"
        while [ -n "$2" ]; do
-               if expr match "$2" '^-[a-z]*s' >/dev/null 2>&1; then return; fi
+               if expr match "$2" '^-[a-z]*s' >/dev/null 2>&1; then return; fi # simulation mode
+               if expr match "$2" '^-dy\?' >/dev/null 2>&1; then return; fi # download-only mode
                shift
        done
        testfailure grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"