Added "-d --" to invocation of ls when figuring out what files
[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
31 mhpath -help > $actual 2>&1
32 check $expected $actual
33
34 # check -version
35 case `mhpath -v` in
36   mhpath\ --*) ;;
37   *          ) echo "$0: mhpath -v generated unexpected output" 1>&2
38                failed=`expr ${failed:-0} + 1`;;
39 esac
40
41 # check +
42 run_test "mhpath +" "$MH_TEST_DIR/Mail"
43
44 # check with no options
45 folder -fast +inbox > /dev/null
46 run_test "mhpath" "$MH_TEST_DIR/Mail/inbox"
47
48 # check +inbox
49 run_test "mhpath +inbox" "$MH_TEST_DIR/Mail/inbox"
50
51 # check all
52 cat > $expected <<EOF
53 $MH_TEST_DIR/Mail/inbox/1
54 $MH_TEST_DIR/Mail/inbox/2
55 $MH_TEST_DIR/Mail/inbox/3
56 $MH_TEST_DIR/Mail/inbox/4
57 $MH_TEST_DIR/Mail/inbox/5
58 $MH_TEST_DIR/Mail/inbox/6
59 $MH_TEST_DIR/Mail/inbox/7
60 $MH_TEST_DIR/Mail/inbox/8
61 $MH_TEST_DIR/Mail/inbox/9
62 $MH_TEST_DIR/Mail/inbox/10
63 EOF
64 mhpath all > $actual 2>&1
65 check $expected $actual
66
67 # check message number greater than highest
68 run_test "mhpath 11" "mhpath: message 11 out of range 1-10"
69 run_test "mhpath 10 11" "mhpath: message 11 out of range 1-10"
70
71 # check range with message number greater than highest
72 cat > $expected <<EOF
73 $MH_TEST_DIR/Mail/inbox/1
74 $MH_TEST_DIR/Mail/inbox/2
75 $MH_TEST_DIR/Mail/inbox/3
76 $MH_TEST_DIR/Mail/inbox/4
77 $MH_TEST_DIR/Mail/inbox/5
78 $MH_TEST_DIR/Mail/inbox/6
79 $MH_TEST_DIR/Mail/inbox/7
80 $MH_TEST_DIR/Mail/inbox/8
81 $MH_TEST_DIR/Mail/inbox/9
82 $MH_TEST_DIR/Mail/inbox/10
83 EOF
84 mhpath 1-99999 > $actual 2>&1
85 check $expected $actual
86
87 # check new
88 run_test "mhpath new" "$MH_TEST_DIR/Mail/inbox/11"
89
90 # check multiple msgs, including new
91 cat > $expected <<EOF
92 $MH_TEST_DIR/Mail/inbox/1
93 $MH_TEST_DIR/Mail/inbox/10
94 $MH_TEST_DIR/Mail/inbox/11
95 EOF
96 mhpath first last new > $actual 2>&1
97 check $expected $actual
98
99 # check invalid message list using names
100 run_test "mhpath last-new" "mhpath: bad message list last-new"
101
102 # check cur
103 folder +inbox 5 > /dev/null
104 run_test "mhpath cur" "$MH_TEST_DIR/Mail/inbox/5"
105
106 # check prev
107 run_test "mhpath prev" "$MH_TEST_DIR/Mail/inbox/4"
108
109 # check next
110 run_test "mhpath next" "$MH_TEST_DIR/Mail/inbox/6"
111
112 # check invalid message list using numbers
113 rmm 1-2
114 run_test "mhpath 1-2" "mhpath: no messages in range 1-2"
115
116 # check ignoring of out-of-range message numbers in ranges
117 run_test "mhpath 1-3" "$MH_TEST_DIR/Mail/inbox/3"
118 run_test "mhpath first-3" "$MH_TEST_DIR/Mail/inbox/3"
119 run_test "mhpath 10-11" "$MH_TEST_DIR/Mail/inbox/10"
120 run_test "mhpath last-11" "$MH_TEST_DIR/Mail/inbox/10"
121
122 # check reference to existing messages
123 cat > $expected <<EOF
124 $MH_TEST_DIR/Mail/inbox/3
125 $MH_TEST_DIR/Mail/inbox/4
126 EOF
127 mhpath first:2 > $actual 2>&1
128 check $expected $actual
129
130 # check reference to non-existant messages
131 cat > $expected <<EOF
132 $MH_TEST_DIR/Mail/inbox/1
133 $MH_TEST_DIR/Mail/inbox/2
134 EOF
135 mhpath 1 2 > $actual 2>&1
136 check $expected $actual
137
138
139 exit $failed