Fixed the test framework by adjusting it to mmh.
authormarkus schnalke <meillo@marmaro.de>
Thu, 27 Nov 2014 23:07:13 +0000 (00:07 +0100)
committermarkus schnalke <meillo@marmaro.de>
Thu, 27 Nov 2014 23:07:13 +0000 (00:07 +0100)
In the same go: Cleaned up its code a bit and added a summary to
test/runalltests.

Adjusting the individual tests to mmh still needs to be done. ... and
afterwards we can ;dd a lot more of them. :-) (But before we write our
own tests, we first incorporate all the ones they've added to nmh in
the meanwhile. ;-) )

test/README
test/common.sh
test/runalltests
test/runtest
test/setup-test
test/teardown-test

index 94b5ab1..e37a4ee 100644 (file)
@@ -1,30 +1,25 @@
-nmh unit test suite.
+Mmh test suite.
 
 
-
-       The testcases are not maintained in mmh, currently.
-       Thus, they likely are broken.     --meillo 2012-04
-
-
-The purpose of these tests is to verify the functionality of the nmh
+The purpose of these tests is to verify the functionality of the mmh
 commands.  The goal of the suite is to create an environment where testing
 commands.  The goal of the suite is to create an environment where testing
-nmh commands is easy and useful.  Each test is a shell script, and is
+mmh commands is easy and useful.  Each test is a shell script, and is
 launched via the 'sh' command. The script should run the test and report
 the result by one of:
 
   * for a test pass: exit with status 0
   * where a test has been skipped (perhaps because it depends on an
 launched via the 'sh' command. The script should run the test and report
 the result by one of:
 
   * for a test pass: exit with status 0
   * where a test has been skipped (perhaps because it depends on an
-    external program which can't be found): print "Test $0 SKIP (reason)"
-    and exit with status 120
+    external program which can't be found) execute: `test_skip "reason"'.
+    (test_skip() is defined in common.sh; it exits with status 120)
   * for a test fail: exit with some status other than 0 or 120
 
 The Suite is arranged as such:
 
 setup-test
   * for a test fail: exit with some status other than 0 or 120
 
 The Suite is arranged as such:
 
 setup-test
-    Create the unit test framework.  This will re-generate your configure
+    Create the test framework.  This will re-generate your configure
     script and make files.
 
 teardown-test
     script and make files.
 
 teardown-test
-    Remove the temporary files created as part of the unit tests.
+    Remove the temporary files created as part of the tests.
 
 runtest
     Run a single test.
 
 runtest
     Run a single test.
@@ -34,8 +29,8 @@ runalltests
 
 tests
     Directory containing the tests.  All files found in this and all
 
 tests
     Directory containing the tests.  All files found in this and all
-    subsequent directories which have the name test-* will be treated as a
-    single test.
+    sub-directories which have the name test-* will be treated as one
+    test each.
 
 Complex tests may be given their own directory as long as there is a file
 named 'test-*' in the directory which will launch the test.
 
 Complex tests may be given their own directory as long as there is a file
 named 'test-*' in the directory which will launch the test.
index 5d46c8c..7f09867 100644 (file)
@@ -1,52 +1,54 @@
-# Common helper routines for test shell scripts -- intended to be sourced by them
-test_skip ()
+# Common helper routines for test shell scripts
+# -- intended to be sourced by them
+
+test_skip()
 {
 {
-  WHY="$1"
-  echo "$Test $0 SKIP ($WHY)"
-  exit 120
+       WHY="$1"
+       echo "Test $0 SKIP ($WHY)"
+       exit 120
 }
 
 # portable implementation of 'which' utility
 findprog()
 {
 }
 
 # portable implementation of 'which' utility
 findprog()
 {
-  FOUND=
-  PROG="$1"
-  IFS_SAVE="$IFS"
-  IFS=:
-  for D in $PATH; do
-    if [ -z "$D" ]; then
-      D=.
-    fi
-    if [ -f "$D/$PROG" ] && [ -x "$D/$PROG" ]; then
-      printf '%s\n' "$D/$PROG"
-      break
-    fi
-  done
-  IFS="$IFS_SAVE"
+       FOUND=
+       PROG="$1"
+       IFS_SAVE="$IFS"
+       IFS=:
+       for D in $PATH; do
+               if [ -z "$D" ]; then
+                       D=.
+               fi
+               if [ -f "$D/$PROG" ] && [ -x "$D/$PROG" ]; then
+                       printf '%s\n' "$D/$PROG"
+                       break
+               fi
+       done
+       IFS="$IFS_SAVE"
 }
 
 }
 
-require_prog ()
+require_prog()
 {
 {
-  if [ -z "$(findprog $1)" ]; then
-    test_skip "missing $1"
-  fi
+       if [ -z "$(findprog $1)" ]; then
+               test_skip "missing $1"
+       fi
 }
 
 # Some stuff for doing silly progress indicators
 }
 
 # Some stuff for doing silly progress indicators
-progress_update ()
+progress_update()
 {
 {
-  THIS="$1"
-  FIRST="$2"
-  LAST="$3"
-  RANGE="$(($LAST - $FIRST))"
-  PROG="$(($THIS - $FIRST))"
-  # this automatically rounds to nearest integer
-  PERC="$(((100 * $PROG) / $RANGE))"
-  # note \r so next update will overwrite
-  printf "%3d%%\r" $PERC
+       THIS="$1"
+       FIRST="$2"
+       LAST="$3"
+       RANGE="$(expr $LAST - $FIRST ||:)"
+       PROG="$(expr $THIS - $FIRST ||:)"
+       # this automatically rounds to nearest integer
+       PERC="$(expr 100 \* $PROG / $RANGE ||:)"
+       # note \r so next update will overwrite
+       printf "%3d%%\r" $PERC
 }
 
 }
 
-progress_done ()
+progress_done()
 {
 {
-  printf "100%%\n"
+       printf "100%%\n"
 }
 }
index 0497c52..279ced5 100755 (executable)
@@ -1,7 +1,35 @@
 #!/bin/sh
 
 #!/bin/sh
 
+passed=0
+failed=0
+skipped=0
+
 # Note that we ignore *~ files as these are probably editor backups
 for i in `find tests -name 'test-*[!~]' -type f`;
 do
 # Note that we ignore *~ files as these are probably editor backups
 for i in `find tests -name 'test-*[!~]' -type f`;
 do
-    ./runtest $i
+       ./runtest "$i"
+       case $? in
+       0)      passed="`expr $passed + 1`" ;;
+       1)      failed="`expr $failed + 1`" ;;
+       2)      skipped="`expr $skipped + 1`" ;;
+       esac
 done
 done
+
+awk -v passed="$passed" -v failed="$failed" -v skipped="$skipped" '
+BEGIN {
+       sum = passed + failed + skipped;
+       if (failed > 0) {
+               smilie = ":-("
+       } else if (sum == passed) {
+               smilie = ":-)"
+       } else {
+               # we either passed the tests or managed to sneak around them
+               smilie = ";-)"
+       }
+       printf("\n%s  %s\n", "SUMMARY", smilie);
+       printf("%-12s %4d = %d%%\n", "Passed", passed, passed/sum*100);
+       printf("%-12s %4d = %d%%\n", "Failed", failed, failed/sum*100);
+       printf("%-12s %4d = %d%%\n", "Skipped", skipped, skipped/sum*100);
+       printf("%-12s %4d\n", "Total", sum);
+}
+'
index 0b18653..edab162 100755 (executable)
@@ -2,56 +2,68 @@
 
 set -e
 
 
 set -e
 
-if [ ! -e test-temp-dir ]; then
-   echo "test-temp-dir not found: running setup-test"
-   ./setup-test
+export MH_TEST_COMMON="$PWD/common.sh"
+
+if [ ! -f test-temp-dir ]; then
+       echo "test-temp-dir not found: running setup-test"
+       ./setup-test
 fi
 
 export MH_TEST_DIR=`cat test-temp-dir`
 
 fi
 
 export MH_TEST_DIR=`cat test-temp-dir`
 
-if [ ! -e "$MH_TEST_DIR/bld/Makefile" ]; then
-   echo "temporary directory missing or broken: running setup-test"
-   ./setup-test
-   export MH_TEST_DIR=`cat test-temp-dir`
+if [ ! -f "$MH_TEST_DIR/build/Makefile" ]; then
+       echo "temporary directory missing or broken: running setup-test"
+       ./setup-test
+       export MH_TEST_DIR=`cat test-temp-dir`
 fi
 
 fi
 
-export MH=$MH_TEST_DIR/Mail/.mh_profile
-export PATH=$MH_TEST_DIR/bin:$PATH
-
-export MH_TEST_COMMON=$PWD/common.sh
+unset MMHP MMHC
+export PATH="$MH_TEST_DIR/bin:$PATH"
+export MMH="$MH_TEST_DIR/.mmh"
+MAILDIR="$MH_TEST_DIR/Mail"
 
 # clean old test data
 
 # clean old test data
-rm -rf $MH_TEST_DIR/Mail
-# setup test data
-mkdir $MH_TEST_DIR/Mail
-echo "Path: $MH_TEST_DIR/Mail" > $MH
-folder -create +inbox > /dev/null
+rm -rf "$MAILDIR" "$MMH"
+
+# setup mmh
+mkdir "$MAILDIR" "$MMH"
+cat >"$MMH/profile" <<-!
+       Path: $MAILDIR
+       Inbox: +inbox
+!
+folder -create `mhparam inbox` >/dev/null
+folder -create `mhparam trashfolder` >/dev/null
+folder -create `mhparam draftfolder` >/dev/null
+
 # create 10 basic messages
 for i in `seq 1 10`;
 do
 # create 10 basic messages
 for i in `seq 1 10`;
 do
-    cat > $MH_TEST_DIR/Mail/inbox/$i <<EOF
-From: Test$i <test$i@example.com>
-To: Some User <user@example.com>
-Date: Fri, 29 Sep 2006 00:00:00
-Subject: Testing message $i
-
-This is message number $i
-EOF
+       cat >"$MAILDIR/inbox/$i" <<-!
+               From: Test$i <test$i@example.com>
+               To: Some User <user@example.com>
+               Date: Fri, 29 Sep 2006 00:00:00
+               Subject: Testing message $i
+
+               This is message number $i
+       !
 done
 
 # now run the test
 set +e
 done
 
 # now run the test
 set +e
-/bin/sh $1
+/bin/sh "$1"
 return_value=$?
 set -e
 
 if [ $return_value -eq 0 ] ; then
 return_value=$?
 set -e
 
 if [ $return_value -eq 0 ] ; then
-    echo Test $1 PASS
+       printf "Test %s:\tPASS\n" "$1"
+       exit 0
 elif [ $return_value -eq 120 ]; then
 elif [ $return_value -eq 120 ]; then
-    # indicates test was skipped (eg needed program not found)
-    # test itself should have printed a message about this,
-    # so print nothing here.
-    :
+       # indicates test was skipped (eg needed program not found)
+       # test itself should have printed a message about this,
+       # so print nothing here.
+       :
+       exit 2
 else
 else
-    echo Test $1 FAIL
+       printf "Test %s:\tFAIL\n" "$1"
+       exit 1
 fi
 fi
index fab26a0..ffd9e64 100755 (executable)
@@ -2,21 +2,25 @@
 
 set -e
 
 
 set -e
 
-if TEMPDIR=`cat test-temp-dir 2> /dev/null` \
-   && [ -e $TEMPDIR/bld/Makefile ]; then
-    (cd $TEMPDIR/bld && make all install)
-    exit
+if TEMPDIR="`cat test-temp-dir 2>/dev/null`" \
+               && [ -f "$TEMPDIR/build/Makefile" ]; then
+       (cd "$TEMPDIR/build" && make all install)
+       exit
 fi
 
 fi
 
-TEMPDIR=`mktemp -d /tmp/nmh-test-XXXXXXXX`
-echo $TEMPDIR > test-temp-dir
+TEMPDIR="`mktemp -d /tmp/mmh-test-XXXXXXXX`"
+echo "$TEMPDIR" >test-temp-dir
 
 cd ..
 
 cd ..
-if ! [ -e configure ]; then
-    ./autogen.sh
+srcdir="$PWD"
+if [ ! -f configure ]; then
+       ./autogen.sh
 fi
 fi
-srcdir=$PWD
-mkdir $TEMPDIR/bld
-cd $TEMPDIR/bld
-$srcdir/configure --prefix=$TEMPDIR --with-locking=fcntl --enable-debug
-make install
+if [ -f Makefile ]; then
+       make -s clean
+fi
+
+mkdir "$TEMPDIR/build"
+cd "$TEMPDIR/build"
+"$srcdir/configure" -q --prefix="$TEMPDIR" --enable-debug
+make -s all install
index 7e169e4..8c930b1 100755 (executable)
@@ -1,4 +1,4 @@
 #!/bin/sh
 
 #!/bin/sh
 
-rm -rf `cat test-temp-dir`
+rm -rf "`cat test-temp-dir`"
 rm -f test-temp-dir
 rm -f test-temp-dir