| 1 |
#!/bin/sh |
| 2 |
# $MawkId: mawktest,v 1.60 2026/01/30 01:22:58 tom Exp $ |
| 3 |
############################################################################### |
| 4 |
# copyright 2008-2024,2026, Thomas E. Dickey |
| 5 |
# copyright 2010, Guido Berhoerster |
| 6 |
# copyright 2010, Jonathan Nieder |
| 7 |
# copyright 2005, Aleksey Cheusov |
| 8 |
# copyright 1996, Michael D. Brennan |
| 9 |
# |
| 10 |
# This is a source file for mawk, an implementation of |
| 11 |
# the AWK programming language. |
| 12 |
# |
| 13 |
# Mawk is distributed without warranty under the terms of |
| 14 |
# the GNU General Public License, version 2, 1991. |
| 15 |
############################################################################### |
| 16 |
|
| 17 |
# This is a simple test check if a newly built mawk is working properly. |
| 18 |
# It's certainly not exhaustive! |
| 19 |
# |
| 20 |
# It must be run from mawk/test |
| 21 |
# and mawk must be in mawk/test or in PATH |
| 22 |
|
| 23 |
: "${FGREP:=grep -F}" |
| 24 |
|
| 25 |
MYTEMP=`mktemp -d 2>/dev/null` |
| 26 |
if [ -z "$MYTEMP" ] |
| 27 |
then |
| 28 |
MYTEMP=${TMPDIR-/tmp}/mawktest$$ |
| 29 |
fi |
| 30 |
mkdir -p "$MYTEMP" || exit |
| 31 |
trap 'echo mawktest failed ; rm -rf "$MYTEMP"; exit 1' 0 |
| 32 |
|
| 33 |
STDOUT=$MYTEMP/mawk-out |
| 34 |
STDERR=$MYTEMP/mawk-err |
| 35 |
|
| 36 |
# POSIX shells have functions... |
| 37 |
Fail() { |
| 38 |
echo "?? fail $*" |
| 39 |
FAIL=`expr "$FAIL" + 1` |
| 40 |
ERRS=`expr "$ERRS" + 1` |
| 41 |
} |
| 42 |
|
| 43 |
Begin() { |
| 44 |
echo |
| 45 |
echo "$*" |
| 46 |
FAIL=0 |
| 47 |
} |
| 48 |
|
| 49 |
Finish() { |
| 50 |
if [ "$FAIL" = 1 ] |
| 51 |
then |
| 52 |
echo "$* had one failure" |
| 53 |
elif [ "$FAIL" != 0 ] |
| 54 |
then |
| 55 |
echo "$* had $FAIL failures" |
| 56 |
else |
| 57 |
echo "$* OK" |
| 58 |
fi |
| 59 |
} |
| 60 |
|
| 61 |
ERRS=0 |
| 62 |
|
| 63 |
Summary() { |
| 64 |
if [ "$ERRS" = 1 ] |
| 65 |
then |
| 66 |
echo "$* had one failure" |
| 67 |
elif [ "$ERRS" != 0 ] |
| 68 |
then |
| 69 |
echo "$* had $ERRS failures" |
| 70 |
else |
| 71 |
echo "$* OK" |
| 72 |
fi |
| 73 |
} |
| 74 |
|
| 75 |
if [ -f ../mawk ] |
| 76 |
then |
| 77 |
PROG="${AWK:-../mawk}" |
| 78 |
else |
| 79 |
PROG="${AWK:-mawk}" |
| 80 |
fi |
| 81 |
|
| 82 |
MAWKBINMODE=7 |
| 83 |
export MAWKBINMODE |
| 84 |
|
| 85 |
if test $# != 0 ; then |
| 86 |
SRC=$1 |
| 87 |
else |
| 88 |
SRC=.. |
| 89 |
fi |
| 90 |
|
| 91 |
dat=mawktest.dat |
| 92 |
nulldat=mawknull.dat |
| 93 |
|
| 94 |
# The ulimit command interferes with valgrind (uncomment for ad hoc testing). |
| 95 |
#ulimit -v 25000 |
| 96 |
|
| 97 |
# find out which mawk we're testing |
| 98 |
MAWKS=no |
| 99 |
if $PROG -W version </dev/null |
| 100 |
then |
| 101 |
( $PROG -W version </dev/null 2>&1 |head -n 1 |grep mawk >/dev/null ) && MAWKS=yes |
| 102 |
NULLS=`$PROG -W version 2>&1 </dev/null |$FGREP regex |$FGREP 'internal' 2>/dev/null` |
| 103 |
else |
| 104 |
NULLS= |
| 105 |
fi |
| 106 |
|
| 107 |
################################# |
| 108 |
|
| 109 |
Begin "testing input and field splitting" |
| 110 |
|
| 111 |
LC_ALL=C $PROG -f wc.awk $dat | cmp -s - wc-awk.out || Fail "wc.awk" |
| 112 |
LC_ALL=C $PROG -f null-rs.awk null-rs.dat | cmp -s - null-rs.out || Fail "null-rs.awk" |
| 113 |
|
| 114 |
LC_ALL=C $PROG -F '(a?)*b' -f wc.awk $dat > "$STDOUT" |
| 115 |
LC_ALL=C $PROG -F 'a*b' -f wc.awk $dat | cmp -s - "$STDOUT" || Fail "case 2" |
| 116 |
|
| 117 |
LC_ALL=C $PROG -F '(a?)+b' -f wc.awk $dat > "$STDOUT" |
| 118 |
LC_ALL=C $PROG -F 'a*b' -f wc.awk $dat | cmp -s - "$STDOUT" || Fail "case 3" |
| 119 |
LC_ALL=C $PROG -F 'a{0,}b' -f wc.awk $dat | cmp -s - "$STDOUT" || Fail "case 3b" |
| 120 |
|
| 121 |
LC_ALL=C $PROG -F '[^^]' -f wc.awk $dat > "$STDOUT" |
| 122 |
LC_ALL=C $PROG -F '(.)' -f wc.awk $dat | cmp -s - "$STDOUT" || Fail "case 4" |
| 123 |
|
| 124 |
LC_ALL=C $PROG -F '[^]]' -f wc.awk $dat > "$STDOUT" |
| 125 |
LC_ALL=C $PROG -F '[[#a-zA-Z0-9/*!=<>+,;.&_%(){}" -]' -f wc.awk $dat | cmp -s - "$STDOUT" || Fail "case 5" |
| 126 |
|
| 127 |
LC_ALL=C $PROG -F '[a[]' -f wc.awk $dat > "$STDOUT" |
| 128 |
LC_ALL=C $PROG -F '[[a]' -f wc.awk $dat | cmp -s - "$STDOUT" || Fail "case 6" |
| 129 |
if test "$MAWKS" = "yes" ; then |
| 130 |
LC_ALL=C $PROG -F 'a|\[' -f wc.awk $dat | cmp -s - "$STDOUT" || Fail "case 6b" |
| 131 |
else |
| 132 |
echo "...skipping case 6b: escaped-bracket test" |
| 133 |
fi |
| 134 |
|
| 135 |
LC_ALL=C $PROG -F '(])' -f wc.awk $dat > "$STDOUT" |
| 136 |
LC_ALL=C $PROG -F '[]]' -f wc.awk $dat | cmp -s - "$STDOUT" || Fail "case 7" |
| 137 |
LC_ALL=C $PROG -F '\]' -f wc.awk $dat | cmp -s - "$STDOUT" || Fail "case 7b" |
| 138 |
|
| 139 |
# check that the regexp [\ does not make mawk segfault |
| 140 |
if test "$MAWKS" = "yes" ; then |
| 141 |
LC_ALL=C $PROG -F "[\\" 2> "$STDERR" || Fail "case 8" |
| 142 |
fi |
| 143 |
|
| 144 |
LC_ALL=C $PROG -F '(^)?)' -f wc.awk $dat > "$STDOUT" |
| 145 |
LC_ALL=C $PROG -F ')' -f wc.awk $dat | cmp -s - "$STDOUT" || Fail "case 9" |
| 146 |
|
| 147 |
echo baaab | LC_ALL=C $PROG -F 'a*+' '{print NF}' > "$STDOUT" |
| 148 |
echo baaab | LC_ALL=C $PROG -F 'a*' '{print NF}' | cmp -s - "$STDOUT" || Fail "case 10" |
| 149 |
|
| 150 |
#LC_ALL=C $PROG -F '[\\\\]' -f wc.awk $dat > "$STDOUT" |
| 151 |
#LC_ALL=C $PROG -F '(\\\\)' -f wc.awk | cmp -s - "$STDOUT" || Fail "case 11" |
| 152 |
#LC_ALL=C $PROG -F '\\\\' -f wc.awk | cmp -s - "$STDOUT" || Fail "case 11b" |
| 153 |
|
| 154 |
if test -n "$NULLS" ; then |
| 155 |
LC_ALL=C $PROG -F '\000' -f nulls0.awk $nulldat > "$STDOUT" |
| 156 |
LC_ALL=C $PROG -F '[\000 ]' -f nulls0.awk $nulldat >> "$STDOUT" |
| 157 |
if ( cmp -s nulls.out "$STDOUT" ) |
| 158 |
then |
| 159 |
echo "... $PROG supports matches with NUL bytes" |
| 160 |
else |
| 161 |
echo "... $PROG does NOT supports matches with NUL bytes" |
| 162 |
fi |
| 163 |
fi |
| 164 |
|
| 165 |
Finish "input and field splitting" |
| 166 |
|
| 167 |
##################################### |
| 168 |
|
| 169 |
Begin "testing regular expression matching" |
| 170 |
|
| 171 |
{ |
| 172 |
LC_ALL=C $PROG -f reg0.awk $dat |
| 173 |
LC_ALL=C $PROG -f reg1.awk $dat |
| 174 |
LC_ALL=C $PROG -f reg2.awk $dat |
| 175 |
LC_ALL=C $PROG -f reg3.awk $dat |
| 176 |
LC_ALL=C $PROG -f reg4.awk $dat |
| 177 |
LC_ALL=C $PROG -f reg5.awk $dat |
| 178 |
LC_ALL=C $PROG -f reg6.awk $dat |
| 179 |
LC_ALL=C $PROG -f reg7.awk $dat |
| 180 |
} > "$STDOUT" |
| 181 |
|
| 182 |
cmp -s reg-awk.out "$STDOUT" || Fail "reg0-reg7 case" |
| 183 |
|
| 184 |
echo "''Italics with an apostrophe' embedded''" | |
| 185 |
LC_ALL=C $PROG -f noloop.awk || Fail "noloop2 test" |
| 186 |
echo "''Italics with an apostrophe'' embedded''" | |
| 187 |
LC_ALL=C $PROG -f noloop.awk || Fail "noloop1 test" |
| 188 |
|
| 189 |
LC_ALL=C $PROG '/^[^^]*$/' $dat > "$STDOUT" |
| 190 |
cmp -s $dat "$STDOUT" || Fail "case 1" |
| 191 |
|
| 192 |
LC_ALL=C $PROG '!/^[^]]*$/' $dat > "$STDOUT" |
| 193 |
LC_ALL=C $PROG '/]/' $dat | cmp -s - "$STDOUT" || Fail "case 2" |
| 194 |
|
| 195 |
LC_ALL=C $PROG '/[a[]/' $dat > "$STDOUT" |
| 196 |
LC_ALL=C $PROG '/[[a]/' $dat | cmp -s - "$STDOUT" || Fail "case 3" |
| 197 |
|
| 198 |
LC_ALL=C $PROG '/]/' $dat > "$STDOUT" |
| 199 |
LC_ALL=C $PROG '/[]]/' $dat | cmp -s - "$STDOUT" || Fail "case 4" |
| 200 |
|
| 201 |
echo aaa | LC_ALL=C $PROG '/a*+/' > "$STDOUT" |
| 202 |
echo aaa | LC_ALL=C $PROG '/a*/' | cmp -s - "$STDOUT" || Fail "case 5" |
| 203 |
echo aaa | cmp -s - "$STDOUT" || Fail "case 6" |
| 204 |
|
| 205 |
Finish "regular expression matching" |
| 206 |
|
| 207 |
####################################### |
| 208 |
|
| 209 |
if [ -c /dev/full ]; then |
| 210 |
Begin "testing checking for write errors" |
| 211 |
# Check for write errors noticed when closing the file |
| 212 |
LC_ALL=C $PROG '{print}' <full-awk.dat >/dev/full 2>/dev/null && Fail "case 1" |
| 213 |
# Check for write errors noticed on writing |
| 214 |
# The file has to be bigger than the buffer size of the libc |
| 215 |
LC_ALL=C $PROG '{print}' <"$SRC"/scan.c >/dev/full 2>/dev/null && Fail "case 2" |
| 216 |
|
| 217 |
Finish "checking for write errors" |
| 218 |
else |
| 219 |
echo |
| 220 |
echo "No /dev/full - check for write errors skipped" |
| 221 |
fi |
| 222 |
|
| 223 |
####################################### |
| 224 |
|
| 225 |
Begin "testing arrays and flow of control" |
| 226 |
|
| 227 |
LC_ALL=C $PROG -f wfrq0.awk $dat | cmp -s - wfrq-awk.out || Fail "wfrq-awk" |
| 228 |
|
| 229 |
Finish "array test" |
| 230 |
|
| 231 |
####################################### |
| 232 |
|
| 233 |
Begin "testing nextfile" |
| 234 |
|
| 235 |
LC_ALL=C $PROG -f nextfile.awk full-awk.dat $dat | cmp -s - nextfile.out || Fail "nextfile.awk" |
| 236 |
|
| 237 |
Finish "nextfile test" |
| 238 |
|
| 239 |
################################# |
| 240 |
|
| 241 |
Begin "testing function calls and general stress test" |
| 242 |
|
| 243 |
LC_ALL=C $PROG -f "$SRC"/examples/decl.awk $dat | cmp -s - decl-awk.out || Fail "examples/decl.awk" |
| 244 |
|
| 245 |
Finish "general stress test" |
| 246 |
|
| 247 |
################################# |
| 248 |
|
| 249 |
Begin "testing r{n,m} repetitions" |
| 250 |
|
| 251 |
LC_ALL=C $PROG -f repetitions.awk repetitions.dat | cmp -s - repetitions.out || Fail "repetitions.awk" |
| 252 |
LC_ALL=C $PROG -f interval0.awk repetitions.dat | cmp -s - interval0.out || Fail "interval0.awk" |
| 253 |
|
| 254 |
Finish "repetitions test" |
| 255 |
|
| 256 |
################################# |
| 257 |
|
| 258 |
################################# |
| 259 |
|
| 260 |
Begin "character-classes demo" |
| 261 |
LC_ALL=C $PROG -f cclass.awk mawktest.dat | cmp -s - cclass.out || Fail "cclass.awk" |
| 262 |
Finish "character-classes demo" |
| 263 |
|
| 264 |
################################# |
| 265 |
|
| 266 |
################################# |
| 267 |
Begin "long-lines test" |
| 268 |
AWK=$PROG ./longline.sh | cmp -s - longline.out || Fail "longline.awk" |
| 269 |
Finish "long-lines test" |
| 270 |
|
| 271 |
################################# |
| 272 |
|
| 273 |
################################# |
| 274 |
|
| 275 |
not_a_sign() { |
| 276 |
sed -e 's/[-+][Ii]nf/inf/g' -e 's/[-+][Nn]a[Nn]/nan/g' nan-$1.out >$MYTEMP/ref.log |
| 277 |
sed -e 's/[-+][Ii]nf/inf/g' -e 's/[-+][Nn]a[Nn]/nan/g' $MYTEMP/result >$MYTEMP/cmp.log |
| 278 |
if cmp -s $MYTEMP/ref.log $MYTEMP/cmp.log |
| 279 |
then |
| 280 |
echo "? different signs of Inf/NaN in $1 test" |
| 281 |
else |
| 282 |
Fail "nan.awk ($1)" |
| 283 |
fi |
| 284 |
} |
| 285 |
|
| 286 |
Begin "not-a-number demo" |
| 287 |
LC_ALL=C $PROG --posix -f nan.awk | tee $MYTEMP/result | cmp -s - nan-posix.out || not_a_sign "posix" |
| 288 |
LC_ALL=C $PROG -f nan.awk | tee $MYTEMP/result | cmp -s - nan-legacy.out || not_a_sign "legacy" |
| 289 |
Finish "not-a-number demo" |
| 290 |
|
| 291 |
################################# |
| 292 |
|
| 293 |
echo |
| 294 |
echo "##################################################" |
| 295 |
Summary "tested $PROG" |
| 296 |
echo "##################################################" |
| 297 |
|
| 298 |
trap 0 |
| 299 |
rm -rf "$MYTEMP" |
| 300 |
exit "$ERRS" |
| 301 |
# vile: ts=4 sw=4 |