]> git.saurik.com Git - apt.git/commitdiff
tests: enhance output of grep and test fails
authorDavid Kalnischkies <david@kalnischkies.de>
Sat, 25 Oct 2014 11:37:05 +0000 (13:37 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Sun, 26 Oct 2014 13:14:42 +0000 (14:14 +0100)
Git-Dch: Ignore

test/integration/framework
test/integration/run-tests
test/integration/test-apt-get-clean
test/integration/test-apt-key
test/integration/test-authentication-basic
test/integration/test-bug-738785-switch-protocol

index 190d4d665a48305e268c8178f515b9e6cd116e48..153c5bb255d856469426a400050d348538e34435 100644 (file)
@@ -77,12 +77,6 @@ if [ $MSGLEVEL -le 2 ]; then
        msgnmsg() { true; }
        msgtest() { true; }
        msgpass() { printf " ${CPASS}P${CNORMAL}"; }
-       msgskip() { printf " ${CWARNING}S${CNORMAL}" >&2; }
-       if [ -n "$CFAIL" ]; then
-               msgfail() { printf " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
-       else
-               msgfail() { printf " ###FAILED###" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
-       fi
 fi
 if [ $MSGLEVEL -le 3 ]; then
        msginfo() { true; }
@@ -1228,6 +1222,36 @@ testmarkedauto() {
        aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
 }
 
+msgfailoutput() {
+       local MSG="$1"
+       local OUTPUT="$2"
+       shift 2
+       echo >&2
+       if [ "$1" = 'grep' ]; then
+               while [ -n "$2" ]; do shift; done
+               echo "#### Complete file: $1 ####"
+               cat >&2 "$1" || true
+               echo '#### grep output ####'
+       elif [ "$1" = 'test' ]; then
+               # doesn't support ! or non-file flags
+               msgfailoutputstatfile() {
+                       local FILEFLAGS='^-[bcdefgGhkLOprsStuwx]$'
+                       if expr match "$1" "$FILEFLAGS" >/dev/null; then
+                               echo "#### stat(2) of file: $2 ####"
+                               stat "$2" || true
+                       fi
+               }
+               msgfailoutputstatfile "$2" "$3"
+               while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
+                       shift 3
+                       msgfailoutputstatfile "$2" "$3"
+               done
+               echo '#### test output ####'
+       fi
+       cat >&2 $OUTPUT
+       msgfail "$MSG"
+}
+
 testsuccess() {
        if [ "$1" = '--nomsg' ]; then
                shift
@@ -1237,10 +1261,10 @@ testsuccess() {
        local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
        if "$@" >${OUTPUT} 2>&1; then
                if expr match "$1" '^apt.*' >/dev/null; then
-                       if grep -q -E '^[WE]: ' "$OUTPUT"; then
-                               echo >&2
-                               cat >&2 $OUTPUT
-                               msgfail 'successful run, but output contains warnings/errors'
+                       if grep -q -E ' runtime error: ' "$OUTPUT"; then
+                               msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
+                       elif grep -q -E '^[WE]: ' "$OUTPUT"; then
+                               msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
                        else
                                msgpass
                        fi
@@ -1249,9 +1273,7 @@ testsuccess() {
                fi
        else
                local EXITCODE=$?
-               echo >&2
-               cat >&2 $OUTPUT
-               msgfail "exitcode $EXITCODE"
+               msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
        fi
        aptautotest 'testsuccess' "$@"
 }
@@ -1264,14 +1286,12 @@ testwarning() {
        local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
        if "$@" >${OUTPUT} 2>&1; then
                if expr match "$1" '^apt.*' >/dev/null; then
-                       if grep -q -E '^E: ' "$OUTPUT"; then
-                               echo >&2
-                               cat >&2 $OUTPUT
-                               msgfail 'successful run, but output contains errors'
+                       if grep -q -E ' runtime error: ' "$OUTPUT"; then
+                               msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
+                       elif grep -q -E '^E: ' "$OUTPUT"; then
+                               msgfailoutput 'successful run, but output contains errors' "$OUTPUT" "$@"
                        elif ! grep -q -E '^W: ' "$OUTPUT"; then
-                               echo >&2
-                               cat >&2 $OUTPUT
-                               msgfail 'successful run, but output contains no warnings'
+                               msgfailoutput 'successful run, but output contains no warnings' "$OUTPUT" "$@"
                        else
                                msgpass
                        fi
@@ -1295,16 +1315,14 @@ testfailure() {
        local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
        if "$@" >${OUTPUT} 2>&1; then
                local EXITCODE=$?
-               echo >&2
-               cat >&2 $OUTPUT
-               msgfail "exitcode $EXITCODE"
+               msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
        else
                local EXITCODE=$?
                if expr match "$1" '^apt.*' >/dev/null; then
-                       if ! grep -q -E '^E: ' "$OUTPUT"; then
-                               echo >&2
-                               cat >&2 $OUTPUT
-                               msgfail "run failed with exitcode ${EXITCODE}, but with no errors"
+                       if grep -q -E ' runtime error: ' "$OUTPUT"; then
+                               msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
+                       elif ! grep -q -E '^E: ' "$OUTPUT"; then
+                               msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
                        else
                                msgpass
                        fi
index c39a2ac68a16bef50d93a791c53e9dbd1aeed1d8..6c6a376116f88f9838727183f29e13ed332dcf57 100755 (executable)
@@ -46,7 +46,11 @@ for testcase in $(run-parts --list $DIR | grep '/test-'); do
        if ! ${testcase}; then
                FAIL=$((FAIL+1))
                FAILED_TESTS="$FAILED_TESTS $(basename $testcase)"
-               echo >&2 "$(basename $testcase) ... FAIL"
+               if [ "$MSGLEVEL" -le 2 ]; then
+                       printf >&2 "\n${CHIGH}Running $(basename $testcase) -> FAILED${CRESET}"
+               else
+                       echo >&2 "${CHIGH}Running $(basename $testcase) -> FAILED${CRESET}"
+               fi
        else
                PASS=$((PASS+1))
        fi
index 98f7c84d0f4e0458b9be0e2bdfc27372a27f70fc..457bff9d3e68739a8556fa460346599a181e5967 100755 (executable)
@@ -26,10 +26,10 @@ touch rootdir/var/cache/apt/archives/foo_4_all.deb
 
 testsuccess aptget clean
 
-testsuccess test ! -e rootdir/var/lib/apt/lists/partial/http.debian.net_debian_dists_sid_main_i18n_Translation-en
-testsuccess test ! -e rootdir/var/cache/apt/archives/foo_1_all.deb
-testsuccess test ! -e rootdir/var/cache/apt/archives/foo_2_all.deb
-testsuccess test ! -e rootdir/var/cache/apt/archives/foo_3_all.deb
-testsuccess test ! -e rootdir/var/cache/apt/archives/foo_4_all.deb
+testfailure test -e rootdir/var/lib/apt/lists/partial/http.debian.net_debian_dists_sid_main_i18n_Translation-en
+testfailure test -e rootdir/var/cache/apt/archives/foo_1_all.deb
+testfailure test -e rootdir/var/cache/apt/archives/foo_2_all.deb
+testfailure test -e rootdir/var/cache/apt/archives/foo_3_all.deb
+testfailure test -e rootdir/var/cache/apt/archives/foo_4_all.deb
 
 
index e6ac530a6145620c7b6910a7b032df5a1834edea..b6b7b7909a8883a01b349cb533a7b648ccaa590c 100755 (executable)
@@ -41,7 +41,7 @@ gpg:              unchanged: 1' aptkey --fakeroot update
 
        testaptkeys 'pub   2048R/DBAC8DAE 2010-08-18'
 
-       testsuccess test ! -e rootdir/etc/apt/trusted.gpg
+       testfailure test -e rootdir/etc/apt/trusted.gpg
        testsuccess aptkey --fakeroot add ./keys/rexexpired.pub
        msgtest 'Check if trusted.gpg is created with permissions set to' '0644'
        if [ "$(stat -c '%a' rootdir/etc/apt/trusted.gpg )" = '644' ]; then
@@ -78,7 +78,7 @@ pub   2048R/DBAC8DAE 2010-08-18'
        cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
        testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
        testempty aptkey list
-       testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
+       testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
        testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
 
        msgtest 'Test key removal with' 'long key ID'
@@ -86,7 +86,7 @@ pub   2048R/DBAC8DAE 2010-08-18'
        cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
        testsuccess --nomsg aptkey --fakeroot del 5A90D141DBAC8DAE
        testempty aptkey list
-       testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
+       testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
        testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
 
        msgtest 'Test key removal with' 'fingerprint'
@@ -94,7 +94,7 @@ pub   2048R/DBAC8DAE 2010-08-18'
        cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
        testsuccess --nomsg aptkey --fakeroot del 34A8E9D18DB320F367E8EAA05A90D141DBAC8DAE
        testempty aptkey list
-       testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
+       testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
        testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
 
        msgtest 'Test key removal with' 'single key in softlink'
@@ -102,7 +102,7 @@ pub   2048R/DBAC8DAE 2010-08-18'
        ln -s $(readlink -f ./keys/joesixpack.pub) rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
        testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
        testempty aptkey list
-       testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
+       testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
        testsuccess test -L rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
 
        cleanplate
@@ -125,7 +125,7 @@ pub   2048R/528144E2 2011-01-16'
        testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
        testaptkeys 'pub   2048R/528144E2 2011-01-16'
        testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
-       testsuccess test ! -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
+       testfailure test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
        testsuccess test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
 
        msgtest 'Test key removal with' 'multiple files including key'
@@ -134,7 +134,7 @@ pub   2048R/528144E2 2011-01-16'
        cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
        testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
        testaptkeys 'pub   2048R/528144E2 2011-01-16'
-       testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
+       testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
        testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
        testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
 
index 4b0ead54a72bfc1824403eef512ab35354d00132..21b0249703e89c4e405a70240e47d3f01d169f40 100755 (executable)
@@ -18,7 +18,7 @@ testauthfailure() {
        testfailure apthelper download-file "${1}/bash" ./downloaded/bash
        # crappy test, but http and https output are wastely different…
        testsuccess grep 401 rootdir/tmp/testfailure.output
-       testsuccess test ! -s ./downloaded/bash
+       testfailure test -s ./downloaded/bash
 }
 
 testauthsuccess() {
index e50c84dbf593515ab2e6c9093d715995869f72ce..0f458e099b285d0a02af404e140e42b93b02bfbb 100755 (executable)
@@ -54,7 +54,7 @@ echo "Dir::Bin::Methods \"${COPYMETHODS}\";" >> aptconfig.conf
 cd downloaded
 testequal "E: The method driver $(readlink -f './../')/rootdir/usr/lib/apt/methods/https could not be found.
 N: Is the package apt-transport-https installed?" aptget download apt -q=0
-testsuccess test ! -e apt_1.0_all.deb
+testfailure test -e apt_1.0_all.deb
 cd - >/dev/null
 
 # revert to all methods