1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
#!/bin/sh
######################################################
#
# Test fmtdump
#
######################################################
set -e
if test -z "${MH_OBJ_DIR}"; then
srcdir=`dirname $0`/../..
MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
fi
. "$MH_OBJ_DIR/test/common.sh"
setup_test
# Use proper program, likely not the first one on PATH.
fmtdump="${MH_LIBEXEC_DIR}/fmtdump"
check_exit '-eq 1' "$fmtdump" -
check_exit '-eq 1' "$fmtdump" -form
check_exit '-eq 1' "$fmtdump" -format
check_exit '-eq 1' "$fmtdump" foo bar
check_exit '-eq 0' "$fmtdump" -format '
%4{} %(eq) %(getenv) %(decodecomp{}) %(trim{}) %(putaddr)
%(putlit) %(zputlit) %(compval{}) %(num)
%(plus) %(minus) %(multiply) %(divide) %(modulo)
%(charleft) %(kilo) %(kibi)
%(month{}) %(tzone{}) %(day{}) %(weekday{}) %(tws{}) %(pretty{})
%(sec{}) %(min{}) %(hour{}) %(year{}) %(yday{}) %(wday{})
%(clock{}) %(rclock{}) %(sday{}) %(dst{}) %(szone{})
%(date2local{}) %(date2gmt{})
'
check_exit '-eq 0' "$fmtdump" -format '
%(addr{}) %(pers{}) %(mbox{}) %(host{}) %(path{}) %(gname{})
%(note{}) %(proper{}) %(type{}) %(ingrp{}) %(nohost{})
%(formataddr) %(concataddr) %(getmymbox{}) %(getmyaddr{})
%<(null)%> %<(gt)%> %<(match)%> %<(amatch)%>
%(null) %(nonnull) %(ne) %(gt) %(match) %(amatch)
'
check_exit '-eq 0' "$fmtdump" -format "`printf '\302\010\014\015\011\177'`"
expected=$MH_TEST_DIR/$$.expected
expected_err=$MH_TEST_DIR/$$.expected_err
actual=$MH_TEST_DIR/$$.actual
actual_err=$MH_TEST_DIR/$$.actual_err
# check -help
start_test "-help"
cat >$expected <<EOF
Usage: fmtdump [switches]
switches are:
-form formatfile
-(forma)t string
-version
-help
EOF
#### Skip nmh intro text.
"$fmtdump" -help 2>&1 | sed '/^$/,$d' >"$actual"
check "$expected" "$actual"
# check -version
start_test "-version"
case `$fmtdump -v` in
fmtdump\ --*) ;;
* ) printf '%s: fmtdump -v generated unexpected output\n' "$0" >&2
failed=`expr ${failed:-0} + 1`;;
esac
# check unknown switch
start_test "unknown switch"
run_test "$fmtdump -nonexistent" 'fmtdump: -nonexistent unknown'
# check with no switches
start_test "with no switches"
cat >$expected <<EOF
LV_DAT, value dat[0]
NUMF, width 4, fill ' '
LV_DAT, value dat[1]
IF_V_NE 0 continue else goto L0
CHAR '+'
GOTO L1
L0: CHAR ' '
L1: LS_COMP, comp "replied"
IF_S continue else goto L2
CHAR '-'
GOTO L3
L2: CHAR ' '
L3: PARSEDATE, c_name "date", c_type <DATE>
LV_MON, c_name "date", c_type <DATE>
NUMF, width 2, fill '0'
CHAR '/'
PARSEDATE, c_name "date", c_type <DATE>
LV_MDAY, c_name "date", c_type <DATE>
NUMF, width 2, fill '0'
LS_COMP, comp "date", c_type <DATE>
IF_S continue else goto L4
CHAR ' '
GOTO L5
L4: CHAR '*'
L5: MYMBOX, c_name "from", c_type <ADDR>
LV_COMPFLAG, comp "from", c_type <ADDR>
IF_V_NE 0 continue else goto L6
LS_COMP, comp "to", c_type <ADDR>
IF_S continue else goto L6
LIT "To:"
PARSEADDR, c_name "to", c_type <ADDR>
LS_FRIENDLY, c_name "to", c_type <ADDR>
LS_DECODE
STRF, width 14, fill ' '
L6: IF_V_EQ 0 continue else goto L7
PARSEADDR, c_name "from", c_type <ADDR>
LS_FRIENDLY, c_name "from", c_type <ADDR>
LS_DECODE
STRF, width 17, fill ' '
L7: LIT " "
LS_COMP, comp "subject"
LS_DECODE
STR
LS_COMP, comp "body"
IF_S continue else goto L8
LIT "<<"
COMP, comp "body"
LIT ">>"
L8: CHAR '\n'
DONE
EOF
run_prog $fmtdump >$actual 2>&1
check $expected $actual
# check -form
start_test "-form"
cat >$expected <<EOF
LV_DAT, value dat[0]
NUMF, width 4, fill ' '
LV_DAT, value dat[1]
IF_V_NE 0 continue else goto L0
CHAR '+'
GOTO L1
L0: CHAR ' '
L1: LS_COMP, comp "replied"
IF_S continue else goto L2
CHAR '-'
GOTO L3
L2: CHAR ' '
L3: PARSEDATE, c_name "date", c_type <DATE>
LV_MON, c_name "date", c_type <DATE>
NUMF, width 2, fill '0'
CHAR '/'
PARSEDATE, c_name "date", c_type <DATE>
LV_MDAY, c_name "date", c_type <DATE>
NUMF, width 2, fill '0'
LS_COMP, comp "date", c_type <DATE>
IF_S continue else goto L4
CHAR ' '
GOTO L5
L4: CHAR '*'
L5: MYMBOX, c_name "from", c_type <ADDR>
LV_COMPFLAG, comp "from", c_type <ADDR>
IF_V_NE 0 continue else goto L6
LS_COMP, comp "to", c_type <ADDR>
IF_S continue else goto L6
LIT "To:"
PARSEADDR, c_name "to", c_type <ADDR>
LS_FRIENDLY, c_name "to", c_type <ADDR>
LS_DECODE
LS_UNQUOTE
STRF, width 14, fill ' '
L6: IF_V_EQ 0 continue else goto L7
PARSEADDR, c_name "from", c_type <ADDR>
LS_FRIENDLY, c_name "from", c_type <ADDR>
LS_DECODE
LS_UNQUOTE
STRF, width 17, fill ' '
L7: LIT " "
LS_COMP, comp "subject"
LS_DECODE
STR
LS_COMP, comp "body"
IF_S continue else goto L8
LIT "<<"
COMP, comp "body"
LIT ">>"
L8: CHAR '\n'
DONE
EOF
run_prog $fmtdump -form "$MH_INST_DIR${nmhetcdir}/scan.default" >$actual 2>&1
check $expected $actual
# check -format
start_test "-format"
cat >$expected <<EOF
LS_LIT str "1234567890"
IF_S continue else goto L0
LV_STRLEN
NUM
L0: DONE
EOF
run_prog $fmtdump -format '%<(lit 1234567890)%(strlen)%>' >$actual 2>&1
check $expected $actual
finish_test
exit ${failed:-0}
|