]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
improve partial/ cleanup in abort and failure cases
[apt.git] / test / integration / framework
index 5f13df1c056334abed41b26e8be97cb4b64ef06d..7564a0faff9584835fc45df7641dff05abc78abd 100644 (file)
@@ -3,7 +3,7 @@
 EXIT_CODE=0
 
 # we all like colorful messages
 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
        if [ ! -t 1 ]; then # but check that we output to a terminal
                export MSGCOLOR='NO'
        fi
@@ -1005,6 +1005,7 @@ signreleasefiles() {
 }
 
 webserverconfig() {
 }
 
 webserverconfig() {
+       local WEBSERVER="${3:-http://localhost:8080}"
        local NOCHECK=false
        if [ "$1" = '--no-check' ]; then
                NOCHECK=true
        local NOCHECK=false
        if [ "$1" = '--no-check' ]; then
                NOCHECK=true
@@ -1016,10 +1017,10 @@ webserverconfig() {
        local URI
        if [ -n "$2" ]; then
                msgtest "Set webserver config option '${1}' to" "$2"
        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}"
        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
        fi
        if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
                msgpass
@@ -1125,8 +1126,10 @@ acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
 
 downloadfile() {
        local PROTO="${1%%:*}"
 
 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" 2>&1 ; then
+               return 1
+       fi
        # only if the file exists the download was successful
        if [ -r "$2" ]; then
                return 0
        # only if the file exists the download was successful
        if [ -r "$2" ]; then
                return 0
@@ -1338,7 +1341,7 @@ testwarning() {
        else
                msgtest 'Test for successful execution with warnings of' "$*"
        fi
        else
                msgtest 'Test for successful execution with warnings of' "$*"
        fi
-       local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
+       local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
        if "$@" >${OUTPUT} 2>&1; then
                if expr match "$1" '^apt.*' >/dev/null; then
                        if grep -q -E ' runtime error: ' "$OUTPUT"; then
        if "$@" >${OUTPUT} 2>&1; then
                if expr match "$1" '^apt.*' >/dev/null; then
                        if grep -q -E ' runtime error: ' "$OUTPUT"; then
@@ -1388,6 +1391,40 @@ testfailure() {
        aptautotest 'testfailure' "$@"
 }
 
        aptautotest 'testfailure' "$@"
 }
 
+testsuccessequal() {
+       local CMP="$1"
+       shift
+       testsuccess "$@"
+       testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$CMP"
+}
+testwarningequal() {
+       local CMP="$1"
+       shift
+       testwarning "$@"
+       testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" "$CMP"
+}
+testfailureequal() {
+       local CMP="$1"
+       shift
+       testfailure "$@"
+       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"
        if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
 testfilestats() {
        msgtest "Test that file $1 has $2 $3" "$4"
        if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
@@ -1431,12 +1468,14 @@ pause() {
 }
 
 listcurrentlistsdirectory() {
 }
 
 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 ###
 }
 
 ### convinience hacks ###
@@ -1484,16 +1523,21 @@ aptautotest_aptget_update() {
        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
        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
                testfilestats "$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
        done
+       if [ "$1" = '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_apt_update() { aptautotest_aptget_update "$@"; }
+aptautotest_aptcdrom_add() { aptautotest_aptget_update "$@"; }
 
 testaptautotestnodpkgwarning() {
        local TESTCALL="$1"
        while [ -n "$2" ]; do
 
 testaptautotestnodpkgwarning() {
        local TESTCALL="$1"
        while [ -n "$2" ]; do
-               if [ "$2" = '-s' ]; then return; fi
+               if expr match "$2" '^-[a-z]*s' >/dev/null 2>&1; then return; fi
                shift
        done
        testfailure grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
                shift
        done
        testfailure grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"