]> git.saurik.com Git - apt.git/commitdiff
improve stdout/stderr usage correctness in test framework
authorDavid Kalnischkies <david@kalnischkies.de>
Fri, 17 Jan 2014 00:02:47 +0000 (01:02 +0100)
committerDavid Kalnischkies <david@kalnischkies.de>
Fri, 17 Jan 2014 00:02:47 +0000 (01:02 +0100)
Also adds a friendly note about how many tests were run/passed so that
the end of the testrun isn't all that negative by just showing fails.
(It now tells us that we have 111 tests at the moment!)

Git-Dch: Ignore

test/integration/framework
test/integration/run-tests
test/integration/test-apt-get-download

index 1db1946db81b6ddc26a58762561c4ec4f6af829a..8d9f99d64493e622fd01162e15aaffc8de7954da 100644 (file)
@@ -19,24 +19,24 @@ fi
 
 msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
 msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
-msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; }
-msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
-msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
-msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; }
+msgmsg() { echo "${CMSG}$1${CNORMAL}"; }
+msginfo() { echo "${CINFO}I: $1${CNORMAL}"; }
+msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}"; }
+msgdone() { echo "${CDONE}DONE${CNORMAL}"; }
 msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
-msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
-msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
-msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
+msgnmsg() { echo -n "${CMSG}$1${CNORMAL}"; }
+msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}"; }
+msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}"; }
 msgtest() {
        while [ -n "$1" ]; do
-               echo -n "${CINFO}$1${CCMD} " >&2;
-               echo -n "$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} " >&2;
+               echo -n "${CINFO}$1${CCMD} "
+               echo -n "$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} "
                shift
                if [ -n "$1" ]; then shift; else break; fi
        done
-       echo -n "…${CNORMAL} " >&2;
+       echo -n "…${CNORMAL} "
 }
-msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
+msgpass() { echo "${CPASS}PASS${CNORMAL}"; }
 msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
 msgfail() {
        if [ $# -gt 0 ]; then echo "${CFAIL}FAIL: $*${CNORMAL}" >&2;
@@ -57,7 +57,7 @@ if [ $MSGLEVEL -le 2 ]; then
        msgmsg() { true; }
        msgnmsg() { true; }
        msgtest() { true; }
-       msgpass() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
+       msgpass() { echo -n " ${CPASS}P${CNORMAL}"; }
        msgskip() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
        if [ -n "$CFAIL" ]; then
                msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
@@ -81,7 +81,7 @@ msgdone() {
           [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
                true;
        else
-               echo "${CDONE}DONE${CNORMAL}" >&2;
+               echo "${CDONE}DONE${CNORMAL}";
        fi
 }
 
index 7316016e2c3dac61eb0f4c56f951157c9521f94f..881c1c56b1efeebd8aec36384d847fdd2cdbbd63 100755 (executable)
@@ -2,6 +2,9 @@
 set -e
 
 FAIL=0
+PASS=0
+ALL=0
+
 FAILED_TESTS=""
 DIR=$(readlink -f $(dirname $0))
 if [ "$1" = "-q" ]; then
@@ -29,18 +32,23 @@ for testcase in $(run-parts --list $DIR | grep '/test-'); do
                echo "${CTEST}Run Testcase ${CHIGH}$(basename ${testcase})${CRESET}"
        fi
        if ! ${testcase}; then
-                 FAIL=$((FAIL+1))
-                 FAILED_TESTS="$FAILED_TESTS $(basename $testcase)"
-                 echo "$(basename $testcase) ... FAIL"
-        fi
+               FAIL=$((FAIL+1))
+               FAILED_TESTS="$FAILED_TESTS $(basename $testcase)"
+               echo >&2 "$(basename $testcase) ... FAIL"
+       else
+               PASS=$((PASS+1))
+       fi
+       ALL=$((ALL+1))
        if [ "$MSGLEVEL" -le 2 ]; then
                echo
        fi
 done
 
-echo "failures: $FAIL"
-if [ -n "$FAILED_TESTS" ]; then 
-    echo "Failed tests: $FAILED_TESTS";
+echo >&2 "Statistics: $ALL tests were run: $PASS successfully and $FAIL failed"
+if [ -n "$FAILED_TESTS" ]; then
+       echo >&2 "Failed tests: $FAILED_TESTS"
+else
+       echo >&2 'All tests seem to have been run successfully. What could possibly go wrong?'
 fi
 # ensure we don't overflow
 exit $((FAIL <= 255 ? FAIL : 255))
index 6eac079f3c9c8d6d7d7f446e4a9f601858d09efd..fce0be01853b3fe37a7f1cb6720ca39aaa244bda 100755 (executable)
@@ -19,7 +19,8 @@ testdownload() {
                APT="${APT}/${3}"
        fi
        msgtest "Test download of package file $1 with" "$APT"
-       aptget -qq download ${APT} && test -f $1 && msgpass || msgfail
+       testsuccess --nomsg aptget download ${APT}
+       testsuccess test -f $1
        rm $1
 }