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