1#!/bin/sh
2
3# TODO: Move to a common file tests can source; need more framework...
4failed=0
5check() {
6    diff -u $expected $actual
7    if [ $? -ne 0 ]; then
8        failed=$((failed + 1))
9    fi
10}
11
12folders=$MH_TEST_DIR/Mail/.folders
13
14expected=$MH_TEST_DIR/$$.expected
15actual=$MH_TEST_DIR/$$.actual
16
17# make second folder
18cp -r $MH_TEST_DIR/Mail/inbox $MH_TEST_DIR/Mail/foo1
19cp -r $MH_TEST_DIR/Mail/inbox $MH_TEST_DIR/Mail/foo2
20# but only list inbox and foo2 in .folders, and sorted differently
21cat > $folders <<EOF
22inbox
23foo2
24EOF
25
26# test with no desired messages
27cat > $expected <<EOF
28 total      0.
29EOF
30new aseq > $actual 2>&1
31check
32new -folders $folders aseq > $actual 2>&1
33check
34
35# test fnext/fprev with no desired messages
36cat /dev/null > $expected
37fnext aseq > $actual 2>&1
38check
39fprev aseq > $actual 2>&1
40check
41
42# add 1 desired message in each folder
43echo 'aseq: 1' > $MH_TEST_DIR/Mail/inbox/.mh_sequences
44echo 'aseq: 1' > $MH_TEST_DIR/Mail/foo1/.mh_sequences
45echo 'aseq: 1' > $MH_TEST_DIR/Mail/foo2/.mh_sequences
46
47# test with all folders
48cat > $expected <<EOF
49foo1       1.  1
50foo2       1.  1
51inbox      1.* 1
52 total      3.
53EOF
54new aseq > $actual 2>&1
55check
56
57# test with .folders
58cat > $expected <<EOF
59inbox      1.* 1
60foo2       1.  1
61 total      2.
62EOF
63new -folders $folders aseq > $actual 2>&1
64check
65
66# add 2 desired messages to another sequence in each folder
67echo 'bseq: 3-4' >> $MH_TEST_DIR/Mail/inbox/.mh_sequences
68echo 'bseq: 3-4' >> $MH_TEST_DIR/Mail/foo1/.mh_sequences
69echo 'bseq: 3-4' >> $MH_TEST_DIR/Mail/foo2/.mh_sequences
70
71# test listing aseq and bseq
72cat > $expected <<EOF
73foo1       3.  1 3-4
74foo2       3.  1 3-4
75inbox      3.* 1 3-4
76 total      9.
77EOF
78new aseq bseq > $actual 2>&1
79check
80
81# set aseq bseq as unseen
82echo 'Unseen-Sequence: aseq bseq' >>"$MMH/profile"
83new > $actual 2>&1
84check
85
86# test unseen
87cat > $expected <<EOF
88
893 aseq bseq messages in foo1
90   1  2006-09-29 00:00  Test1              Testing message 1
91   3  2006-09-29 00:00  Test3              Testing message 3
92   4  2006-09-29 00:00  Test4              Testing message 4
93
943 aseq bseq messages in foo2
95   1  2006-09-29 00:00  Test1              Testing message 1
96   3  2006-09-29 00:00  Test3              Testing message 3
97   4  2006-09-29 00:00  Test4              Testing message 4
98
993 aseq bseq messages in inbox (*: current folder)
100   1  2006-09-29 00:00  Test1              Testing message 1
101   3  2006-09-29 00:00  Test3              Testing message 3
102   4  2006-09-29 00:00  Test4              Testing message 4
103EOF
104unseen > $actual 2>&1
105check
106
107# test fnext with the current folder not in the list
108echo 'Current-Folder: foo1' >"$MMH/context"
109echo 'inbox  1 3-4' > $expected
110fnext -folders $folders > $actual 2>&1
111check
112
113# test fprev with the current folder not in the list
114echo 'Current-Folder: foo1' >"$MMH/context"
115echo 'inbox  1 3-4' > $expected
116fprev -folders $folders > $actual 2>&1
117check
118
119# test fnext with current folder in the middle of the list
120echo 'Current-Folder: foo2' >"$MMH/context"
121echo 'inbox  1 3-4' > $expected
122fnext > $actual 2>&1
123check
124
125# test fprev with current folder in the middle of the list
126echo 'Current-Folder: foo2' >"$MMH/context"
127echo 'foo1  1 3-4' > $expected
128fprev > $actual 2>&1
129check
130
131# test fprev with current folder at the beginning of the list
132echo 'Current-Folder: foo1' >"$MMH/context"
133echo 'inbox  1 3-4' > $expected
134fprev > $actual 2>&1
135check
136
137# test fnext with current folder at the end of the list
138echo 'Current-Folder: inbox' >"$MMH/context"
139echo 'foo1  1 3-4' > $expected
140fnext > $actual 2>&1
141check
142
143# test fnext with no current folder
144rm "$MMH/context"
145echo 'foo1  1 3-4' > $expected
146fnext > $actual 2>&1
147check
148
149# test fnext with only one folder in the list
150cat > $folders <<EOF
151inbox
152EOF
153echo 'inbox  1 3-4' > $expected
154fnext -folders $folders > $actual 2>&1
155check
156
157exit $failed
158