54a1a125b030e83b59ec7b427753a4bb4d6b4550
[mmh] / test / mhpath / test-mhpath
1 #!/bin/sh
2 ######################################################
3 #
4 # Test mhpath
5 #
6 ######################################################
7
8 set -e
9
10 if test -z "${MH_OBJ_DIR}"; then
11     srcdir=`dirname $0`/../..
12     MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
13 fi
14
15 . "$MH_OBJ_DIR/test/common.sh"
16
17 setup_test
18
19 expected=$MH_TEST_DIR/$$.expected
20 actual=$MH_TEST_DIR/$$.actual
21
22
23 # check -help
24 cat > $expected <<EOF
25 Usage: mhpath [+folder] [msgs] [switches]
26   switches are:
27   -version
28   -help
29 EOF
30 # The exit status is 1 with -help, so temporarily disable -e.
31 set +e
32 mhpath -help > $actual 2>&1
33 set -e
34 check $expected $actual
35
36 # check -version
37 if mhpath -v | grep '^mhpath --' > /dev/null; then
38   :
39 else
40   echo "$0: mhpath -v generated unexpected output" 1>&2
41   failed=`expr ${failed:-0} + 1`
42 fi
43
44 # check +
45 run_test "mhpath +" "$MH_TEST_DIR/Mail"
46
47 # check with no options
48 folder -fast +inbox > /dev/null
49 run_test "mhpath" "$MH_TEST_DIR/Mail/inbox"
50
51 # check +inbox
52 run_test "mhpath +inbox" "$MH_TEST_DIR/Mail/inbox"
53
54 # check all
55 cat > $expected <<EOF
56 $MH_TEST_DIR/Mail/inbox/1
57 $MH_TEST_DIR/Mail/inbox/2
58 $MH_TEST_DIR/Mail/inbox/3
59 $MH_TEST_DIR/Mail/inbox/4
60 $MH_TEST_DIR/Mail/inbox/5
61 $MH_TEST_DIR/Mail/inbox/6
62 $MH_TEST_DIR/Mail/inbox/7
63 $MH_TEST_DIR/Mail/inbox/8
64 $MH_TEST_DIR/Mail/inbox/9
65 $MH_TEST_DIR/Mail/inbox/10
66 EOF
67 mhpath all > $actual 2>&1
68 check $expected $actual
69
70 # check message number greater than highest
71 run_test "mhpath 11" "mhpath: message 11 out of range 1-10"
72 run_test "mhpath 10 11" "mhpath: message 11 out of range 1-10"
73
74 # check range with message number greater than highest
75 cat > $expected <<EOF
76 $MH_TEST_DIR/Mail/inbox/1
77 $MH_TEST_DIR/Mail/inbox/2
78 $MH_TEST_DIR/Mail/inbox/3
79 $MH_TEST_DIR/Mail/inbox/4
80 $MH_TEST_DIR/Mail/inbox/5
81 $MH_TEST_DIR/Mail/inbox/6
82 $MH_TEST_DIR/Mail/inbox/7
83 $MH_TEST_DIR/Mail/inbox/8
84 $MH_TEST_DIR/Mail/inbox/9
85 $MH_TEST_DIR/Mail/inbox/10
86 EOF
87 mhpath 1-99999 > $actual 2>&1
88 check $expected $actual
89
90 # check new
91 run_test "mhpath new" "$MH_TEST_DIR/Mail/inbox/11"
92
93 # check multiple msgs, including new
94 cat > $expected <<EOF
95 $MH_TEST_DIR/Mail/inbox/1
96 $MH_TEST_DIR/Mail/inbox/10
97 $MH_TEST_DIR/Mail/inbox/11
98 EOF
99 mhpath first last new > $actual 2>&1
100 check $expected $actual
101
102 # check invalid message list using names
103 run_test "mhpath last-new" "mhpath: bad message list last-new"
104
105 # check cur
106 folder +inbox 5 > /dev/null
107 run_test "mhpath cur" "$MH_TEST_DIR/Mail/inbox/5"
108
109 # check prev
110 run_test "mhpath prev" "$MH_TEST_DIR/Mail/inbox/4"
111
112 # check next
113 run_test "mhpath next" "$MH_TEST_DIR/Mail/inbox/6"
114
115 # check invalid message list using numbers
116 rmm 1-2
117 run_test "mhpath 1-2" "mhpath: no messages in range 1-2"
118
119 # check ignoring of out-of-range message numbers in ranges
120 run_test "mhpath 1-3" "$MH_TEST_DIR/Mail/inbox/3"
121 run_test "mhpath first-3" "$MH_TEST_DIR/Mail/inbox/3"
122 run_test "mhpath 10-11" "$MH_TEST_DIR/Mail/inbox/10"
123 run_test "mhpath last-11" "$MH_TEST_DIR/Mail/inbox/10"
124
125 # check reference to existing messages
126 cat > $expected <<EOF
127 $MH_TEST_DIR/Mail/inbox/3
128 $MH_TEST_DIR/Mail/inbox/4
129 EOF
130 mhpath first:2 > $actual 2>&1
131 check $expected $actual
132
133 # check reference to non-existant messages
134 cat > $expected <<EOF
135 $MH_TEST_DIR/Mail/inbox/1
136 $MH_TEST_DIR/Mail/inbox/2
137 EOF
138 mhpath 1 2 > $actual 2>&1
139 check $expected $actual
140
141
142 exit $failed