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 212 213 214 215 216 217 218 219 220 221 222 223
|
#!/bin/sh
# $MawkId: mawktest,v 1.36 2014/09/07 22:05:34 tom Exp $
###############################################################################
# copyright 2008-2012,2014, Thomas E. Dickey
# copyright 2010, Guido Berhoerster
# copyright 2010, Jonathan Nieder
# copyright 2005, Aleksey Cheusov
# copyright 1996, Michael D. Brennan
#
# This is a source file for mawk, an implementation of
# the AWK programming language.
#
# Mawk is distributed without warranty under the terms of
# the GNU General Public License, version 2, 1991.
###############################################################################
# This is a simple test that a new made mawk seems to
# be working OK.
# It's certainly not exhaustive, but the last two tests in
# particular use most features.
#
# It needs to be run from mawk/test
# and mawk needs to be in mawk/test or in PATH
# POSIX shells have functions...
Fail() {
echo "?? fail $*"
FAIL=`expr $FAIL + 1`
ERRS=`expr $ERRS + 1`
}
Begin() {
echo
echo "$*"
OK=OK
FAIL=0
}
Finish() {
if test $FAIL = 1
then
echo "$* had one failure"
elif test $FAIL != 0
then
echo "$* had $FAIL failures"
else
echo "$* OK"
fi
}
ERRS=0
Summary() {
if test $ERRS = 1
then
echo "$* had one failure"
elif test $ERRS != 0
then
echo "$* had $ERRS failures"
else
echo "$* OK"
fi
}
PROG="${MAWK:-../mawk}"
PATH=/bin:/usr/bin
export PATH
MAWKBINMODE=7
export MAWKBINMODE
if test $# != 0 ; then
SRC=$1
else
SRC=..
fi
dat=mawktest.dat
nulldat=mawknull.dat
STDOUT=${TMPDIR-/tmp}/mawk-out$$
STDERR=${TMPDIR-/tmp}/mawk-err$$
# The ulimit command interfers with valgrind (uncomment for ad hoc testing).
#ulimit -v 25000
trap 'echo mawk_test failed ; rm -f $STDOUT $STDERR; exit 1' 0
# find out which mawk we're testing
$PROG -W version
NULLS=`$PROG -W version 2>&1 |fgrep regex |fgrep 'internal' 2>/dev/null`
#################################
Begin "testing input and field splitting"
LC_ALL=C $PROG -f wc.awk $dat | cmp -s - wc-awk.out || Fail "wc.awk"
LC_ALL=C $PROG -f null-rs.awk null-rs.dat | cmp -s - null-rs.out || Fail "null-rs.awk"
LC_ALL=C $PROG -F '(a?)*b' -f wc.awk $dat > $STDOUT
LC_ALL=C $PROG -F 'a*b' -f wc.awk $dat | cmp -s - $STDOUT || Fail "case 2"
LC_ALL=C $PROG -F '(a?)+b' -f wc.awk $dat > $STDOUT
LC_ALL=C $PROG -F 'a*b' -f wc.awk $dat | cmp -s - $STDOUT || Fail "case 3"
LC_ALL=C $PROG -F '[^^]' -f wc.awk $dat > $STDOUT
LC_ALL=C $PROG -F '(.)' -f wc.awk $dat | cmp -s - $STDOUT || Fail "case 4"
LC_ALL=C $PROG -F '[^]]' -f wc.awk $dat > $STDOUT
LC_ALL=C $PROG -F '[[#a-zA-Z0-9/*!=<>+,;.&_%(){}" -]' -f wc.awk $dat |
cmp -s - $STDOUT || Fail "case 5"
LC_ALL=C $PROG -F '[a[]' -f wc.awk $dat > $STDOUT
LC_ALL=C $PROG -F '[[a]' -f wc.awk $dat | cmp -s - $STDOUT || Fail "case 6"
LC_ALL=C $PROG -F '(])' -f wc.awk $dat > $STDOUT
LC_ALL=C $PROG -F '[]]' -f wc.awk $dat | cmp -s - $STDOUT || Fail "case 7"
# check that the regexp [\ does not make mawk segfault
LC_ALL=C $PROG -F '[\' 2> $STDERR || Fail "case 8"
LC_ALL=C $PROG -F '(^)?)' -f wc.awk $dat > $STDOUT
LC_ALL=C $PROG -F ')' -f wc.awk $dat | cmp -s - $STDOUT || Fail "case 9"
echo baaab | LC_ALL=C $PROG -F 'a*+' '{print NF}' > $STDOUT
echo baaab | LC_ALL=C $PROG -F 'a*' '{print NF}' | cmp -s - $STDOUT || Fail "case 10"
if test -n "$NULLS" ; then
LC_ALL=C $PROG -F '\000' -f nulls0.awk $nulldat > $STDOUT
LC_ALL=C $PROG -F '[\000 ]' -f nulls0.awk $nulldat >> $STDOUT
if ( cmp -s nulls.out $STDOUT )
then
echo "... $PROG supports matches with NUL bytes"
else
echo "... $PROG does NOT supports matches with NUL bytes"
fi
fi
Finish "input and field splitting"
#####################################
Begin "testing regular expression matching"
LC_ALL=C $PROG -f reg0.awk $dat > $STDOUT
LC_ALL=C $PROG -f reg1.awk $dat >> $STDOUT
LC_ALL=C $PROG -f reg2.awk $dat >> $STDOUT
LC_ALL=C $PROG -f reg3.awk $dat >> $STDOUT
LC_ALL=C $PROG -f reg4.awk $dat >> $STDOUT
LC_ALL=C $PROG -f reg5.awk $dat >> $STDOUT
LC_ALL=C $PROG -f reg6.awk $dat >> $STDOUT
LC_ALL=C $PROG -f reg7.awk $dat >> $STDOUT
cmp -s reg-awk.out $STDOUT || Fail "reg0-reg7 case"
echo "''Italics with an apostrophe' embedded''" |
LC_ALL=C $PROG -f noloop.awk || Fail "noloop2 test"
echo "''Italics with an apostrophe'' embedded''" |
LC_ALL=C $PROG -f noloop.awk || Fail "noloop1 test"
LC_ALL=C $PROG '/^[^^]*$/' $dat > $STDOUT
cmp -s $dat $STDOUT || Fail "case 1"
LC_ALL=C $PROG '!/^[^]]*$/' $dat > $STDOUT
LC_ALL=C $PROG '/]/' $dat | cmp -s - $STDOUT || Fail "case 2"
LC_ALL=C $PROG '/[a[]/' $dat > $STDOUT
LC_ALL=C $PROG '/[[a]/' $dat | cmp -s - $STDOUT || Fail "case 3"
LC_ALL=C $PROG '/]/' $dat > $STDOUT
LC_ALL=C $PROG '/[]]/' $dat | cmp -s - $STDOUT || Fail "case 4"
echo aaa | LC_ALL=C $PROG '/a*+/' > $STDOUT
echo aaa | LC_ALL=C $PROG '/a*/' | cmp -s - $STDOUT || Fail "case 5"
echo aaa | cmp -s - $STDOUT || Fail "case 6"
Finish "regular expression matching"
#######################################
if [ -c /dev/full ]; then
Begin "testing checking for write errors"
# Check for write errors noticed when closing the file
LC_ALL=C $PROG '{print}' <full-awk.dat >/dev/full 2>/dev/null && Fail "case 1"
# Check for write errors noticed on writing
# The file has to be bigger than the buffer size of the libc
LC_ALL=C $PROG '{print}' <$SRC/scan.c >/dev/full 2>/dev/null && Fail "case 2"
Finish "checking for write errors"
else
echo
echo "No /dev/full - check for write errors skipped"
fi
#######################################
Begin "testing arrays and flow of control"
LC_ALL=C $PROG -f wfrq0.awk $dat | cmp -s - wfrq-awk.out || Fail
Finish "array test"
#######################################
Begin "testing nextfile"
LC_ALL=C $PROG -f nextfile.awk full-awk.dat $dat | cmp -s - nextfile.out || Fail
Finish "nextfile test"
#################################
Begin "testing function calls and general stress test"
LC_ALL=C $PROG -f $SRC/examples/decl.awk $dat | cmp -s - decl-awk.out || Fail
Finish "general stress test"
Summary "tested $PROG"
trap 0
rm -f $STDOUT
exit $ERRS
|