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