From: David Levine Date: Sat, 18 Feb 2012 23:30:47 +0000 (-0600) Subject: Consolidated runtest and check_string test functions. X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=4d6cfbb1c9b425cb693e5189a19e132c67f5494a;p=mmh Consolidated runtest and check_string test functions. --- diff --git a/test/common.sh.in b/test/common.sh.in index 2308d70..fb24d74 100644 --- a/test/common.sh.in +++ b/test/common.sh.in @@ -93,18 +93,19 @@ check() { fi } -#### check_string() requires two arguments, the first is a program and -#### arguments, the second is its expected one-line output string. If -#### the actual output does not match that string, an error message is -#### printed and global variable "failed" is incremented. -check_string() { +#### run_test() requires two arguments, the first is a program and +#### arguments, the second is its expected one-line output string. +#### If the actual output does not match that string: +#### an error message is printed and global variable "failed" is incremented; +#### if there is an optional third argument, it is used in the error message. +run_test() { #### Invert exit status to prevent triggering immediate exit due to set -e. - ! actual_output=`$1 2>&1` - if test "$actual_output" != "$2"; then - echo "$0: \"$1\" should have produced:" 1>&2 - echo " $2" 1>&2 - echo "but instead produced:" 1>&2 - echo " $actual_output" 1>&2 + ! actual_output="`$1 2>&1`" + if test x"$actual_output" != x"$2"; then + echo "$0: ${3:-\"$1\"} expected:" 1>&2 + echo " '$2'" 1>&2 + echo "but instead got:" 1>&2 + echo " '$actual_output'" 1>&2 failed=`expr ${failed:-0} + 1` fi } diff --git a/test/format/test-myname b/test/format/test-myname index 2cc3ce0..dc86ea5 100755 --- a/test/format/test-myname +++ b/test/format/test-myname @@ -15,24 +15,17 @@ setup_test unset SIGNATURE -runtest() -{ - testoutput=$(${MH_LIB_DIR}/ap -format "%(myname)" ignore) - - if [ x"$1" != x"${testoutput}" ]; then - echo "For $2, expected $1 but got ${testoutput}" - exit 1 - fi -} - -runtest "$(${MH_OBJ_DIR}/test/getfullname)" "GECOS field test" +run_test "${MH_LIB_DIR}/ap -format %(myname) ignore" \ + "`${MH_OBJ_DIR}/test/getfullname`" "GECOS field test" echo "Signature: Some Random Name 1" >> ${MH} -runtest "Some Random Name 1" "MH Profile Signature test" +run_test "${MH_LIB_DIR}/ap -format %(myname) ignore" \ + "Some Random Name 1" "MH Profile Signature test" export SIGNATURE="Some Random Name 2" -runtest "${SIGNATURE}" "SIGNATURE Environment test" +run_test "${MH_LIB_DIR}/ap -format %(myname) ignore" \ + "${SIGNATURE}" "SIGNATURE Environment test" -exit 0 +exit $failed diff --git a/test/mhpath/test-mhpath b/test/mhpath/test-mhpath index 2f88eb0..71ee9ea 100755 --- a/test/mhpath/test-mhpath +++ b/test/mhpath/test-mhpath @@ -39,14 +39,14 @@ if ! mhpath -v | grep '^mhpath --' > /dev/null; then fi # check + -check_string "mhpath +" "$MH_TEST_DIR/Mail" +run_test "mhpath +" "$MH_TEST_DIR/Mail" # check with no options folder -fast +inbox > /dev/null -check_string "mhpath" "$MH_TEST_DIR/Mail/inbox" +run_test "mhpath" "$MH_TEST_DIR/Mail/inbox" # check +inbox -check_string "mhpath +inbox" "$MH_TEST_DIR/Mail/inbox" +run_test "mhpath +inbox" "$MH_TEST_DIR/Mail/inbox" # check all cat > $expected < $actual 2>&1 check $expected $actual # check message number greater than highest -check_string "mhpath 11" "mhpath: message 11 out of range 1-10" -check_string "mhpath 10 11" "mhpath: message 11 out of range 1-10" +run_test "mhpath 11" "mhpath: message 11 out of range 1-10" +run_test "mhpath 10 11" "mhpath: message 11 out of range 1-10" # check range with message number greater than highest cat > $expected < $actual 2>&1 check $expected $actual # check new -check_string "mhpath new" "$MH_TEST_DIR/Mail/inbox/11" +run_test "mhpath new" "$MH_TEST_DIR/Mail/inbox/11" # check multiple msgs, including new cat > $expected < $actual 2>&1 check $expected $actual # check invalid message list using names -check_string "mhpath last-new" "mhpath: bad message list last-new" +run_test "mhpath last-new" "mhpath: bad message list last-new" # check cur folder +inbox 5 > /dev/null -check_string "mhpath cur" "$MH_TEST_DIR/Mail/inbox/5" +run_test "mhpath cur" "$MH_TEST_DIR/Mail/inbox/5" # check prev -check_string "mhpath prev" "$MH_TEST_DIR/Mail/inbox/4" +run_test "mhpath prev" "$MH_TEST_DIR/Mail/inbox/4" # check next -check_string "mhpath next" "$MH_TEST_DIR/Mail/inbox/6" +run_test "mhpath next" "$MH_TEST_DIR/Mail/inbox/6" # check invalid message list using numbers rmm 1-2 -check_string "mhpath 1-2" "mhpath: no messages in range 1-2" +run_test "mhpath 1-2" "mhpath: no messages in range 1-2" # check ignoring of out-of-range message numbers in ranges -check_string "mhpath 1-3" "$MH_TEST_DIR/Mail/inbox/3" -check_string "mhpath first-3" "$MH_TEST_DIR/Mail/inbox/3" -check_string "mhpath 10-11" "$MH_TEST_DIR/Mail/inbox/10" -check_string "mhpath last-11" "$MH_TEST_DIR/Mail/inbox/10" +run_test "mhpath 1-3" "$MH_TEST_DIR/Mail/inbox/3" +run_test "mhpath first-3" "$MH_TEST_DIR/Mail/inbox/3" +run_test "mhpath 10-11" "$MH_TEST_DIR/Mail/inbox/10" +run_test "mhpath last-11" "$MH_TEST_DIR/Mail/inbox/10" # check reference to existing messages cat > $expected <