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