set -e
-if test -z "${MH_OBJ_DIR}"; then
+if test -z "$MH_OBJ_DIR"; then
srcdir=`dirname $0`/../..
MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
fi
setup_test
+check_exit '-eq 1' sortm -
+
expected=$MH_TEST_DIR/$$.expected
actual=$MH_TEST_DIR/$$.actual
cd $MH_TEST_DIR
# check -help
+start_test "-help"
cat >"$expected" <<EOF
Usage: sortm [+folder] [msgs] [switches]
switches are:
-nolimit
-[no]verbose
-[no]all
+ -[no]check
-version
-help
EOF
-sortm -help >"$actual" 2>&1
+#### Skip nmh intro text.
+run_prog sortm -help 2>&1 | sed '/^$/,$d' >"$actual"
check "$expected" "$actual"
# check -version
+start_test "-version"
case `sortm -version` in
sortm\ --*) ;;
* ) echo "$0: sortm -v generated unexpected output" 1>&2
EOF
# check with no options
+start_test "with no options"
cat >"$expected" <<EOF
1 09/28 Test12 common subject<<This is message number 12 >>
2 09/29 Test1 Testing message 1<<This is message number 1 >>
12 09/29 Test11 Re: common subject<<This is message number 11 >>
EOF
-sortm
-scan >"$actual"
+run_prog sortm
+scan -width 80 >"$actual"
check "$expected" "$actual"
# check +folder
+start_test "+folder"
cat >"$expected" <<EOF
1 09/28 Test12 common subject<<This is message number 12 >>
2+ 09/29 Test1 Testing message 1<<This is message number 1 >>
EOF
refile first +inbox; folder -pack >/dev/null
-sortm +inbox
-scan >"$actual"
+run_prog sortm +inbox
+scan -width 80 >"$actual"
check "$expected" "$actual"
# check -verbose
+start_test "-verbose"
cat >"$expected" <<EOF
sorting by datefield date
renaming message chain from 12 to 1
EOF
refile first +inbox; folder -pack >/dev/null
-sortm -verbose >"$actual"
-scan >>"$actual"
+run_prog sortm -verbose >"$actual"
+scan -width 80 >>"$actual"
check "$expected" "$actual"
# check -noverbose
+start_test "-noverbose"
cat >"$expected" <<EOF
1 09/28 Test12 common subject<<This is message number 12 >>
2+ 09/29 Test1 Testing message 1<<This is message number 1 >>
EOF
refile first +inbox; folder -pack >/dev/null
-sortm -verbose -noverbose >"$actual"
-scan >>"$actual"
+run_prog sortm -verbose -noverbose >"$actual"
+scan -width 80 >>"$actual"
check "$expected" "$actual"
# check msgs
+start_test "msgs"
cat >"$expected" <<EOF
1 09/28 Test12 common subject<<This is message number 12 >>
2 09/29 Test2 Testing message 2<<This is message number 2 >>
EOF
refile first +inbox; folder -pack >/dev/null
-sortm first last
-scan >"$actual"
+run_prog sortm first last
+scan -width 80 >"$actual"
check "$expected" "$actual"
# check -datefield
+start_test "-datefield"
cat >"$expected" <<EOF
1 09/29 Test11 Re: common subject<<This is message number 11 >>
2 09/29 Test2 Testing message 2<<This is message number 2 >>
12+ 09/29 Test1 Testing message 1<<This is message number 1 >>
EOF
-sortm -datefield Alt-Date 1 11
-scan >"$actual"
+run_prog sortm -datefield Alt-Date 1 11
+scan -width 80 >"$actual"
check "$expected" "$actual"
# check -textfield subject (datefield major, subjects grouped)
+start_test "-textfield subject (datefield major, subjects grouped)"
cat >"$expected" <<EOF
1 09/28 Test12 common subject<<This is message number 12 >>
2 09/29 Test11 Re: common subject<<This is message number 11 >>
12+ 09/29 Test1 Testing message 1<<This is message number 1 >>
EOF
-sortm -textfield subject
-scan >"$actual"
+run_prog sortm -textfield subject
+scan -width 80 >"$actual"
check "$expected" "$actual"
# check -nolimit
+start_test "-nolimit"
cat >"$expected" <<EOF
1 09/28 Test12 common subject<<This is message number 12 >>
2 09/29 Test11 Re: common subject<<This is message number 11 >>
12+ 09/29 Test1 Testing message 1<<This is message number 1 >>
EOF
-sortm -textfield subject -limit 0 -nolimit
-scan >"$actual"
+run_prog sortm -textfield subject -limit 0 -nolimit
+scan -width 80 >"$actual"
check "$expected" "$actual"
# check -textfield subject -limit 0 (subject sort)
+start_test "-textfield subject -limit 0 (subject sort)"
cat >"$expected" <<EOF
1 09/29 Test11 Re: common subject<<This is message number 11 >>
2 09/28 Test12 common subject<<This is message number 12 >>
EOF
refile 2-7 +inbox; refile 1 +inbox; folder -pack last >/dev/null
-sortm -textfield subject -limit 0
-scan >"$actual"
+run_prog sortm -textfield subject -limit 0
+scan -width 80 >"$actual"
check "$expected" "$actual"
# check -textfield -limit 0 (text sort)
+start_test "-textfield -limit 0 (text sort)"
cat >"$expected" <<EOF
1 09/29 Test10 Testing message 10<<This is message number 10 >>
2 09/29 Test11 Re: common subject<<This is message number 11 >>
EOF
refile 2-7 +inbox; refile 1 +inbox; folder -pack last >/dev/null
-sortm -textfield from -limit 0
-scan >"$actual"
+run_prog sortm -textfield from -limit 0
+scan -width 80 >"$actual"
check "$expected" "$actual"
# check -textfield with finite -limit that doesn't cover message 13
+start_test "-textfield with finite -limit that doesn't cover message 13"
cat >$MH_TEST_DIR/Mail/inbox/13 <<EOF || exit 1
From: Test13 <test13@example.com>
To: Some User <user@example.com>
EOF
refile 2-7 +inbox; refile 1 +inbox; folder -pack last >/dev/null
-sortm -textfield subject -limit 10
-scan >"$actual"
+run_prog sortm -textfield subject -limit 10
+scan -width 80 >"$actual"
check "$expected" "$actual"
# check -textfield with finite -limit that does cover message 13
+start_test "-textfield with finite -limit that does cover message 13"
cat >"$expected" <<EOF
1 09/28 Test12 common subject<<This is message number 12 >>
2 09/29 Test11 Re: common subject<<This is message number 11 >>
EOF
refile 2-7 +inbox; refile 1 +inbox; folder -pack last >/dev/null
-sortm -textfield subject -limit 60
-scan >"$actual"
+run_prog sortm -textfield subject -limit 60
+scan -width 80 >"$actual"
check "$expected" "$actual"
# check -notextfield
+start_test "-notextfield"
cat >"$expected" <<EOF
1 09/28 Test12 common subject<<This is message number 12 >>
2 09/29 Test10 Testing message 10<<This is message number 10 >>
EOF
refile 2-7 +inbox; refile 1 +inbox; folder -pack last >/dev/null
-sortm -textfield subject -limit 60 -notextfield
-scan >"$actual"
+run_prog sortm -textfield subject -limit 60 -notextfield
+scan -width 80 >"$actual"
check "$expected" "$actual"
# check -noall
+start_test "-noall"
run_test 'sortm -noall' 'sortm: must specify messages to sort with -noall'
# check -all
+start_test "-all"
cat >"$expected" <<EOF
1 09/28 Test12 common subject<<This is message number 12 >>
2+ 09/29 Test10 Testing message 10<<This is message number 10 >>
EOF
refile first +inbox; folder -pack >/dev/null
-sortm -noall -all
-scan >"$actual"
+run_prog sortm -noall -all
+scan -width 80 >"$actual"
+check "$expected" "$actual"
+
+# check -check
+start_test "-check"
+cat >"$expected" <<EOF
+sortm: can't parse date field in message 14, will use file modification time
+sortm: errors found, no messages sorted
+EOF
+
+sed -e 's/Sep//' $MH_TEST_DIR/Mail/inbox/7 > $MH_TEST_DIR/Mail/inbox/14
+set +e
+run_prog sortm -check >"$actual" 2>&1
+set -e
+check "$expected" "$actual"
+
+cat >"$expected" <<EOF
+ 1 09/28 Test12 common subject<<This is message number 12 >>
+ 2+ 09/29 Test10 Testing message 10<<This is message number 10 >>
+ 3 09/29 Test5 Testing message 5<<This is message number 5 >>
+ 4 09/29 Test6 Testing message 6<<This is message number 6 >>
+ 5 09/29 Test7 Testing message 7<<This is message number 7 >>
+ 6 09/29 Test8 Testing message 8<<This is message number 8 >>
+ 7 09/29 Test9 Testing message 9<<This is message number 9 >>
+ 8 09/29 Test1 Testing message 1<<This is message number 1 >>
+ 9 09/29 Test2 Testing message 2<<This is message number 2 >>
+ 10 09/29 Test3 Testing message 3<<This is message number 3 >>
+ 11 09/29 Test4 Testing message 4<<This is message number 4 >>
+ 12 09/29 Test11 Re: common subject<<This is message number 11 >>
+ 13 10/31 Test13 Re: common subject<<This is message number 13 >>
+ 14 01/00 Test9 Testing message 9<<This is message number 9 >>
+EOF
+scan -width 80 >"$actual"
+check "$expected" "$actual"
+
+# check -nocheck
+start_test "-nocheck"
+cat >"$expected" <<EOF
+ 1 09/28 Test12 common subject<<This is message number 12 >>
+ 2+ 09/29 Test10 Testing message 10<<This is message number 10 >>
+ 3 09/29 Test5 Testing message 5<<This is message number 5 >>
+ 4 09/29 Test6 Testing message 6<<This is message number 6 >>
+ 5 09/29 Test7 Testing message 7<<This is message number 7 >>
+ 6 09/29 Test8 Testing message 8<<This is message number 8 >>
+ 7 09/29 Test9 Testing message 9<<This is message number 9 >>
+ 8 09/29 Test1 Testing message 1<<This is message number 1 >>
+ 9 09/29 Test2 Testing message 2<<This is message number 2 >>
+ 10 09/29 Test3 Testing message 3<<This is message number 3 >>
+ 11 09/29 Test4 Testing message 4<<This is message number 4 >>
+ 12 09/29 Test11 Re: common subject<<This is message number 11 >>
+ 13 10/31 Test13 Re: common subject<<This is message number 13 >>
+ 14 01/00 Test9 Testing message 9<<This is message number 9 >>
+EOF
+
+sed -e 's/Sep//' $MH_TEST_DIR/Mail/inbox/7 > $MH_TEST_DIR/Mail/inbox/14
+run_test 'sortm -check -nocheck' \
+ "sortm: can't parse date field in message 14, will use file \
+modification time"
+scan -width 80 >"$actual"
check "$expected" "$actual"
+finish_test
exit ${failed:-0}