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
}
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
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 <<EOF
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 <<EOF
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 <<EOF
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 <<EOF