Fixed description of n with mhstore -clobber auto/suffix.
[mmh] / test / pick / test-pick
index 6ee4449..9b737ce 100755 (executable)
@@ -22,8 +22,10 @@ actual=$MH_TEST_DIR/$$.actual
 # Add an 11th message.
 sed \
   -e 's/10/11/g' \
-  -e 's/^To:\(.*\)/To:\1\nCc: <another@example.com>/' \
-  -e 's/^\(Date:.*\)2006\( 00:00:\)00/\12008\200\nDelivery-Date: \12009\241/' \
+  -e 's/^To:\(.*\)/To:\1\
+Cc: <another@example.com>/' \
+  -e 's/^\(Date:.*\)2006\( 00:00:\)00/\12008\200\
+Delivery-Date: \12009\241/' \
   $MH_TEST_DIR/Mail/inbox/10 >$MH_TEST_DIR/Mail/inbox/11
 
 # Test message specification.
@@ -85,6 +87,7 @@ NOT
 EOF
 check $expected $actual
 
+set +e
 
 # Produce 0 if no messages match and standard output is not a tty.
 # Note that there is an error message on stderr, but it's redirected
@@ -95,18 +98,20 @@ cat >$expected <<EOF
 EOF
 check $expected $actual
 
-# Produce no standard output if no messages match and standard output
-# is a tty.  To test that, move stderr to stdout.
-echo `pick -subject message.3 -and -from Test4 >&2-` >$actual
-cat >$expected <<EOF
-
-EOF
-check $expected $actual
+if test -w /dev/tty && printf '' >/dev/tty; then
+  # Produce no standard output if no messages match and standard
+  # output is a tty.  To test that even when run with stdout
+  # detached, write directly to /dev/tty.  Can't capture the
+  # output so hopefully the user will notice it.
+  pick -subject message.3 -and -from Test4 >/dev/tty 2>/dev/null
+else
+  echo "$0: skip tty test because can't write to /dev/tty"
+fi
 
 # Also, check that the exit status is 1.
-set +e
-pick -subject message.3 -and -from Test4 2>/dev/null
+pick -subject message.3 -and -from Test4 >/dev/null 2>&1
 run_test "echo $?" '1'
+
 set -e
 
 # Test -cc.
@@ -131,42 +136,47 @@ run_test 'pick -to some -nolist' '11 hits'
 run_test 'pick -to user@example.com -nolist' '11 hits'
 
 # Test -after.
-pick -after '28 Sep 2008' >$actual 2>&1
+pick -after '28 Sep 2008 00:00:00' >$actual 2>&1
 cat >$expected <<EOF
 11
 EOF
 check $expected $actual
+
 # Invert exit status so execution doesn't terminate due to -e.
-! pick -after '29 Sep 2008' >$actual 2>/dev/null
+set +e
+pick -after '29 Sep 2008 00:00:00' >$actual 2>/dev/null
+set -e
 cat >$expected <<EOF
 0
 EOF
 check $expected $actual
 
 # Test -before.  While -after doesn't include the specified date, -before does.
-pick -before '29 Sep 2008' last:3 >$actual 2>&1
+pick -before '29 Sep 2008 00:00:01' last:3 >$actual 2>&1
 cat >$expected <<EOF
 9
 10
 11
 EOF
 check $expected $actual
-pick -before '28 Sep 2008' last:3 >$actual 2>&1
+pick -before '28 Sep 2008 00:00:00:' last:3 >$actual 2>&1
 cat >$expected <<EOF
 9
 10
 EOF
 check $expected $actual
-# Invert exit status so execution doesn't terminate due to -e.
-! pick -before '28 Sep 2006' last:3 >$actual 2>/dev/null
+set +e
+pick -before '28 Sep 2006 00:00:00' last:3 >$actual 2>/dev/null
+set -e
 cat >$expected <<EOF
 0
 EOF
 check $expected $actual
 
 # Test -datefield.
-# Invert exit status so execution doesn't terminate due to -e.
-! pick -datefield date -after '29 Sep 2008 00:00:00' >$actual 2>/dev/null
+set +e
+pick -datefield date -after '29 Sep 2008 00:00:00' >$actual 2>/dev/null
+set -e
 cat >$expected <<EOF
 0
 EOF