]> diplodocus.org Git - nmh/blob - test/mhparam/test-mhparam
Get coverage of quite a few of the `ambiguous switch' case.
[nmh] / test / mhparam / test-mhparam
1 #!/bin/sh
2 ######################################################
3 #
4 # Test mhparam
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 ! mhparam - >/dev/null 2>&1 # gcov
20
21 expected=$MH_TEST_DIR/$$.expected
22 expected_err=$MH_TEST_DIR/$$.expected_err
23 actual=$MH_TEST_DIR/$$.actual
24 actual_err=$MH_TEST_DIR/$$.actual_err
25
26
27 # check -help
28 cat >$expected <<EOF
29 Usage: mhparam [profile-components] [switches]
30 switches are:
31 -[no]components
32 -all
33 -version
34 -help
35 -(debug)
36 EOF
37
38 #### Skip nmh intro text.
39 mhparam -help | sed '/^$/,$d' >"$actual" 2>&1
40 check "$expected" "$actual"
41
42 # check -version
43 case `mhparam -v` in
44 mhparam\ --*) ;;
45 * ) echo "$0: mhparam -v generated unexpected output" 1>&2
46 failed=`expr ${failed:-0} + 1`;;
47 esac
48
49 # check unknown option
50 run_test 'mhparam -nonexistent' 'mhparam: -nonexistent unknown'
51
52 # check -all
53 cp "$MH" $expected
54 # -all adds current folder and Version
55 echo 'Current-Folder: '`folder -f` >>$expected
56 echo "Version: nmh-$MH_VERSION" >>$expected
57 run_prog mhparam -all >$actual
58 check $expected $actual 'keep first'
59
60 # check -all with a component
61 echo 'mhparam: profile-components ignored with -all' >$expected_err
62 run_prog mhparam -all path >$actual 2>$actual_err
63 check $expected $actual 'keep first'
64 check $expected_err $actual_err
65
66 # check -all with -components
67 echo 'mhparam: -components ignored with -all' >$expected_err
68 run_prog mhparam -all -components >$actual 2>$actual_err
69 check $expected $actual
70 check $expected_err $actual_err
71
72 # check one component
73 run_test 'mhparam path' "$MH_TEST_DIR/Mail"
74
75 # check more than one component, which enables -component
76 echo 'AliasFile: aliases' >>"$MH"
77 run_test 'mhparam path AliasFile' "path: $MH_TEST_DIR/Mail
78 AliasFile: aliases"
79
80 # check each component in procs array in uip/mhparam.c
81 # The tests don't override these, so they're default or configured values.
82 # Note that cat is hardcoded here because the testsuite uses it for moreproc.
83 cat >$expected <<EOF
84 context
85 .mh_sequences
86 $MH_INST_DIR$bindir/mhbuild
87 $MH_INST_DIR$bindir/refile
88 700
89 $bindir/inc
90 more
91 $MH_INST_DIR$bindir/mhmail
92 $MH_INST_DIR$nmhlibexecdir/mhl
93 cat
94 600
95 $bindir/packf
96 $MH_INST_DIR$nmhlibexecdir/post
97 $MH_INST_DIR$bindir/send
98 $MH_INST_DIR$bindir/mhshow
99 $MH_INST_DIR$nmhlibexecdir/mhl
100 nmh-$MH_VERSION
101 $MH_INST_DIR$bindir/whatnow
102 $MH_INST_DIR$bindir/whom
103 $nmhetcdirinst
104 $MH_LIBEXEC_DIR
105 fcntl
106 ${default_locking}
107 EOF
108
109 run_prog mhparam -nocomponent \
110 context \
111 mh-sequences \
112 buildmimeproc \
113 fileproc \
114 foldprot \
115 incproc \
116 lproc \
117 mailproc \
118 mhlproc \
119 moreproc \
120 msgprot \
121 packproc \
122 postproc \
123 sendproc \
124 showmimeproc \
125 showproc \
126 version \
127 whatnowproc \
128 whomproc \
129 etcdir \
130 libexecdir \
131 datalocking \
132 spoollocking >$actual 2>&1
133
134 check $expected $actual
135
136 #### This exits with non-zero status, so let run_test squash that:
137 run_test 'mhparam formatproc rmmproc' ''
138
139 #### Test sbackup separately because it's only passed as a -D compile option.
140 case `mhparam sbackup` in
141 ,|\#) ;;
142 * ) echo mhparam sbackup failed
143 failed=`expr ${failed:-0} + 1` ;;
144 esac
145
146 # check -component
147 run_test 'mhparam -component Path' "Path: $MH_TEST_DIR/Mail"
148
149 # check -component, note that component name of argument is echoed exactly
150 run_test 'mhparam -component path' "path: $MH_TEST_DIR/Mail"
151 run_test 'mhparam -component PATH' "PATH: $MH_TEST_DIR/Mail"
152
153 # check -nocomponent
154 run_test 'mhparam -component -nocomponent path' "$MH_TEST_DIR/Mail"
155 run_test 'mhparam -nocomponent path AliasFile' "$MH_TEST_DIR/Mail
156 aliases"
157
158 # check nonexistent component
159 run_test 'mhparam nonexistent' ''
160
161 # check that return status counts nonexistent components
162 set +e
163 mhparam path context nonexistent1 nonexistent2 nonexistent3 >/dev/null
164 run_test "echo $?" 3
165 set -e
166
167 # mhparam -debug
168 # Some of its output depends on configure options, so don't bother to
169 # check for correctness here.
170 mhparam -debug >/dev/null
171
172 # check with text file that does not end with newline
173 printf 'Editor: emacs' >>"$MH"
174 run_test 'mhparam -nocomponent editor' 'emacs'
175
176 exit $failed