1e6d6c189SCody Peter Mello#!/bin/bash 2e6d6c189SCody Peter Mello 3e6d6c189SCody Peter Melloif [[ -z "$AWK" || -z "$WORKDIR" ]]; then 4e6d6c189SCody Peter Mello printf '$AWK and $WORKDIR must be set\n' >&2 5e6d6c189SCody Peter Mello exit 1 6e6d6c189SCody Peter Mellofi 7e6d6c189SCody Peter Mello 8e6d6c189SCody Peter MelloTEMPLS=$WORKDIR/test.temp.ls 9e6d6c189SCody Peter MelloTEMPSH=$WORKDIR/test.temp.sh 10e6d6c189SCody Peter MelloTEMPOUT=$WORKDIR/test.temp.out 11e6d6c189SCody Peter Mello 12e6d6c189SCody Peter MelloTEMP0=$WORKDIR/test.temp.0 13e6d6c189SCody Peter MelloTEMP1=$WORKDIR/test.temp.1 14e6d6c189SCody Peter MelloTEMP2=$WORKDIR/test.temp.2 15e6d6c189SCody Peter Mello 16e6d6c189SCody Peter MelloRESULT=0 17e6d6c189SCody Peter Mello 18e6d6c189SCody Peter Mellofail() { 19e6d6c189SCody Peter Mello echo "$1" >&2 20e6d6c189SCody Peter Mello RESULT=1 21e6d6c189SCody Peter Mello} 22e6d6c189SCody Peter Mello 23e6d6c189SCody Peter Melloecho T.errmsg: check some error messages 24e6d6c189SCody Peter Mello 25e6d6c189SCody Peter Mellols > $TEMPLS 26e6d6c189SCody Peter Mello$AWK ' 27e6d6c189SCody Peter Mello$1 ~ /^#/ { 28e6d6c189SCody Peter Mello next 29e6d6c189SCody Peter Mello} 30e6d6c189SCody Peter Mello{ pat = $0 31e6d6c189SCody Peter Mello prog = "" 32e6d6c189SCody Peter Mello while (getline x > 0 && x != "") 33e6d6c189SCody Peter Mello prog = prog "\n" x 34e6d6c189SCody Peter Mello print sprintf("\n%s '"'"'%s'"'"' < '$TEMPLS' >> /dev/null 2> '$TEMPOUT'", 35e6d6c189SCody Peter Mello ENVIRON["AWK"], prog) 36e6d6c189SCody Peter Mello print sprintf("grep '"'"'%s'"'"' '$TEMPOUT' >> /dev/null || fail '"'"'BAD: %s'"'"' failed", pat, pat) 37e6d6c189SCody Peter Mello} 38e6d6c189SCody Peter Mello' > $TEMPSH <<\!!!! 39e6d6c189SCody Peter Melloillegal primary in regular expression 40e6d6c189SCody Peter Mello/(/ 41e6d6c189SCody Peter Mello 42*3ee4fc2aSCody Peter Melloillegal break, continue, next or nextfile from BEGIN 43*3ee4fc2aSCody Peter MelloBEGIN { nextfile } 44*3ee4fc2aSCody Peter Mello 45*3ee4fc2aSCody Peter Melloillegal break, continue, next or nextfile from END 46*3ee4fc2aSCody Peter MelloEND { nextfile } 47*3ee4fc2aSCody Peter Mello 48*3ee4fc2aSCody Peter Mellonextfile is illegal inside a function 49*3ee4fc2aSCody Peter Mellofunction foo() { nextfile } 50*3ee4fc2aSCody Peter Mello 51*3ee4fc2aSCody Peter Melloduplicate argument 52*3ee4fc2aSCody Peter Mellofunction f(i,j,i) { return i } 53*3ee4fc2aSCody Peter Mello 54e6d6c189SCody Peter Mellononterminated character class 55e6d6c189SCody Peter Mello/[[/ 56e6d6c189SCody Peter Mello 57*3ee4fc2aSCody Peter Mellononterminated character class 58*3ee4fc2aSCody Peter Mello/[]/ 59*3ee4fc2aSCody Peter Mello 60*3ee4fc2aSCody Peter Mellononterminated character class 61*3ee4fc2aSCody Peter Mello/[\ 62*3ee4fc2aSCody Peter Mello 63e6d6c189SCody Peter Mellononterminated character class 64e6d6c189SCody Peter MelloBEGIN { s = "[x"; if (1 ~ s) print "foo"} 65e6d6c189SCody Peter Mello 66e6d6c189SCody Peter Mellosyntax error in regular expression 67e6d6c189SCody Peter MelloBEGIN { if ("x" ~ /$^/) print "ugh" } 68e6d6c189SCody Peter Mello 69e6d6c189SCody Peter Mellosyntax error in regular expression 70e6d6c189SCody Peter Mello/((.)/ 71e6d6c189SCody Peter Mello 72e6d6c189SCody Peter Mellodivision by zero 73e6d6c189SCody Peter MelloBEGIN { print 1/0 } 74e6d6c189SCody Peter Mello 75e6d6c189SCody Peter Mellodivision by zero in /= 76e6d6c189SCody Peter MelloBEGIN { x = 1; print x /= 0 } 77e6d6c189SCody Peter Mello 78e6d6c189SCody Peter Mellodivision by zero in %= 79e6d6c189SCody Peter MelloBEGIN { x = 1; print x %= 0 } 80e6d6c189SCody Peter Mello 81e6d6c189SCody Peter Mellodivision by zero in mod 82e6d6c189SCody Peter MelloBEGIN { print 1%0 } 83e6d6c189SCody Peter Mello 84e6d6c189SCody Peter Mellocan.t read value.* array name. 85e6d6c189SCody Peter MelloBEGIN { x[1] = 0; split("a b c", y, x) } 86e6d6c189SCody Peter Mello 87e6d6c189SCody Peter Mellocan.t read value.* function 88e6d6c189SCody Peter Mellofunction f(){}; {split($0, x, f)} 89e6d6c189SCody Peter Mello 90e6d6c189SCody Peter Mellocan.t assign.* a function 91e6d6c189SCody Peter Mellofunction f(){}; {f = split($0, x)} 92e6d6c189SCody Peter Mello 93e6d6c189SCody Peter Mellocan.t assign to x; it.s an array name. 94e6d6c189SCody Peter Mello{x = split($0, x)} 95e6d6c189SCody Peter Mello 96e6d6c189SCody Peter Mellois a function, not an array 97e6d6c189SCody Peter Mellofunction f(){}; {split($0, f)} 98e6d6c189SCody Peter Mello 99e6d6c189SCody Peter Mellofunction f called with 1 args, uses only 0 100e6d6c189SCody Peter MelloBEGIN { f(f) } 101e6d6c189SCody Peter Mellofunction f() { print "x" } 102e6d6c189SCody Peter Mello 103e6d6c189SCody Peter Mellocan.t use function f as argument in f 104e6d6c189SCody Peter MelloBEGIN { f(f) } 105e6d6c189SCody Peter Mellofunction f() { print "x" } 106e6d6c189SCody Peter Mello 107e6d6c189SCody Peter Mellox is an array, not a function 108e6d6c189SCody Peter Mello{ split($0, x) }; function x() {} 109e6d6c189SCody Peter Mello 110e6d6c189SCody Peter Melloillegal nested function 111e6d6c189SCody Peter Mellofunction x() { function g() {} } 112e6d6c189SCody Peter Mello 113e6d6c189SCody Peter Melloreturn not in function 114e6d6c189SCody Peter Mello{ return } 115e6d6c189SCody Peter Mello 116*3ee4fc2aSCody Peter Mellobreak illegal outside 117*3ee4fc2aSCody Peter Mello{ break } 118*3ee4fc2aSCody Peter Mello 119*3ee4fc2aSCody Peter Mellocontinue illegal outside 120*3ee4fc2aSCody Peter Mello{ continue } 121*3ee4fc2aSCody Peter Mello 122*3ee4fc2aSCody Peter Mellonon-terminated string 123*3ee4fc2aSCody Peter Mello{ print "abc 124*3ee4fc2aSCody Peter Mello} 125*3ee4fc2aSCody Peter Mello 126e6d6c189SCody Peter Melloillegal field $(foo) 127e6d6c189SCody Peter MelloBEGIN { print $"foo" } 128e6d6c189SCody Peter Mello 129e6d6c189SCody Peter Mellonext is illegal inside a function 130e6d6c189SCody Peter MelloBEGIN { f() } 131e6d6c189SCody Peter Mellofunction f() { next } 132e6d6c189SCody Peter Mello 133e6d6c189SCody Peter Mellonot enough args in printf(%s) 134e6d6c189SCody Peter MelloBEGIN { printf("%s") } 135e6d6c189SCody Peter Mello 136*3ee4fc2aSCody Peter Melloweird printf conversion 137*3ee4fc2aSCody Peter MelloBEGIN { printf("%z", "foo")} 138*3ee4fc2aSCody Peter Mello 139e6d6c189SCody Peter Mellofunction f has .* arguments, limit .* 140e6d6c189SCody Peter Mellofunction f(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10, 141e6d6c189SCody Peter Mello c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10, 142e6d6c189SCody Peter Mello e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10) {} 143e6d6c189SCody Peter MelloBEGIN { f(123) } 144e6d6c189SCody Peter Mello 145e6d6c189SCody Peter Mellobailing out 146e6d6c189SCody Peter Mello])} 147e6d6c189SCody Peter Mello 148e6d6c189SCody Peter Mellobailing out 149e6d6c189SCody Peter Mello{ print }} 150e6d6c189SCody Peter Mello 151e6d6c189SCody Peter Mellobailing out 152e6d6c189SCody Peter Mello{ print }}} 153e6d6c189SCody Peter Mello 154e6d6c189SCody Peter Mellobailing out 155e6d6c189SCody Peter Mello] 156e6d6c189SCody Peter Mello 157e6d6c189SCody Peter Mellobailing out 158e6d6c189SCody Peter Mello[ 159e6d6c189SCody Peter Mello 160e6d6c189SCody Peter Mellobailing out 161e6d6c189SCody Peter Melloa & b 162e6d6c189SCody Peter Mello 163e6d6c189SCody Peter Melloextra ) 164e6d6c189SCody Peter Mello{ x = 1) } 165e6d6c189SCody Peter Mello 166e6d6c189SCody Peter Melloillegal statement 167e6d6c189SCody Peter Mello{ print ))} 168e6d6c189SCody Peter Mello 169e6d6c189SCody Peter Melloillegal statement 170e6d6c189SCody Peter Mello{{ print } 171e6d6c189SCody Peter Mello 172e6d6c189SCody Peter Melloillegal statement 173e6d6c189SCody Peter Mello{{{ print } 174e6d6c189SCody Peter Mello 175e6d6c189SCody Peter Melloillegal .*next.* from BEGIN 176e6d6c189SCody Peter MelloBEGIN { next } 177e6d6c189SCody Peter Mello 178e6d6c189SCody Peter Melloillegal .*next.* from END 179e6d6c189SCody Peter MelloEND { next; print NR } 180e6d6c189SCody Peter Mello 181e6d6c189SCody Peter Mellocan.t open file /etc/passwd 182e6d6c189SCody Peter MelloBEGIN { print "abc" >"/etc/passwd" } 183e6d6c189SCody Peter Mello 184e6d6c189SCody Peter Melloyou can.t define function f more than once 185e6d6c189SCody Peter Mellofunction f() { print 1 } 186e6d6c189SCody Peter Mellofunction f() { print 2 } 187e6d6c189SCody Peter Mello 188e6d6c189SCody Peter Mellofunction mp called with 1 args, uses only 0 189e6d6c189SCody Peter Mellofunction mp(){ cnt++;} 190e6d6c189SCody Peter MelloBEGIN { mp(xx) } 191e6d6c189SCody Peter Mello 192e6d6c189SCody Peter Melloindex.*doesn.t permit regular expressions 193e6d6c189SCody Peter MelloBEGIN { index("abc", /a/) } 194e6d6c189SCody Peter Mello 195e6d6c189SCody Peter Mellolog argument out of domain 196e6d6c189SCody Peter MelloBEGIN { print log(-1) } 197e6d6c189SCody Peter Mello 198e6d6c189SCody Peter Melloexp result out of range 199e6d6c189SCody Peter MelloBEGIN {print exp(1000)} 200e6d6c189SCody Peter Mello 201e6d6c189SCody Peter Mellonull file name in print or getline 202e6d6c189SCody Peter MelloBEGIN { print >foo } 203e6d6c189SCody Peter Mello 204e6d6c189SCody Peter Mellofunction has too many arguments 205e6d6c189SCody Peter MelloBEGIN { length("abc", "def") } 206e6d6c189SCody Peter Mello 207e6d6c189SCody Peter Mellocalling undefined function foo 208e6d6c189SCody Peter MelloBEGIN { foo() } 209e6d6c189SCody Peter Mello 210*3ee4fc2aSCody Peter Mellocannot delete SYMTAB or its elements 211*3ee4fc2aSCody Peter MelloBEGIN { delete SYMTAB } 212*3ee4fc2aSCody Peter Mello 213*3ee4fc2aSCody Peter Mellocannot delete SYMTAB or its elements 214*3ee4fc2aSCody Peter MelloBEGIN { delete SYMTAB["OFS"] } 215*3ee4fc2aSCody Peter Mello 216e6d6c189SCody Peter Mello# I am pretty certain that this test is _meant_ to fail, 217e6d6c189SCody Peter Mello# to allow checking whether anything is happening. Uncomment 218e6d6c189SCody Peter Mello# below to check whether the script then fails: 219e6d6c189SCody Peter Mello# 220e6d6c189SCody Peter Mello# this should print a BAD message 221e6d6c189SCody Peter Mello# BEGIN { print } 222e6d6c189SCody Peter Mello!!!! 223e6d6c189SCody Peter Mello 224e6d6c189SCody Peter Mello 225e6d6c189SCody Peter Melloecho ' running tests in test.temp.sh' 226e6d6c189SCody Peter Mellosource $TEMPSH 227e6d6c189SCody Peter Mello 228e6d6c189SCody Peter Mello[[ $? -eq 139 ]] && fail 'BAD: someone dropped core' 1>&2 229e6d6c189SCody Peter Mello 230e6d6c189SCody Peter Melloecho xxx > $TEMP0 231e6d6c189SCody Peter Mello$AWK '{print x}' x='a 232e6d6c189SCody Peter Mellob' $TEMP0 > $TEMP1 2> $TEMP2 233e6d6c189SCody Peter Mellogrep 'newline in string' $TEMP2 >/dev/null || fail 'BAD: T.errmsg newline in string' 234e6d6c189SCody Peter Mello 235*3ee4fc2aSCody Peter Mello$AWK -safe 'BEGIN{"date" | getline}' > $TEMP0 2> $TEMP2 236*3ee4fc2aSCody Peter Mellogrep 'cmd | getline is unsafe' $TEMP2 >/dev/null || fail 'BAD: T.errmsg cmd|getline unsafe' 237*3ee4fc2aSCody Peter Mello 238*3ee4fc2aSCody Peter Mello$AWK -safe 'BEGIN{print >"'$TEMP0'"}' > $TEMP0 2> $TEMP2 239*3ee4fc2aSCody Peter Mellogrep 'print > is unsafe' $TEMP2 >/dev/null || fail 'BAD: T.errmsg print > unsafe' 240*3ee4fc2aSCody Peter Mello 241*3ee4fc2aSCody Peter Mello$AWK -safe 'BEGIN{print >> "'$TEMP0'"}' > $TEMP0 2> $TEMP2 242*3ee4fc2aSCody Peter Mellogrep 'print >> is unsafe' $TEMP2 >/dev/null || fail 'BAD: T.errmsg print >> unsafe' 243*3ee4fc2aSCody Peter Mello 244*3ee4fc2aSCody Peter Mello$AWK -safe 'BEGIN{print | "'$TEMP0'"}' > $TEMP0 2> $TEMP2 245*3ee4fc2aSCody Peter Mellogrep 'print | is unsafe' $TEMP2 >/dev/null || fail 'BAD: T.errmsg print | unsafe' 246*3ee4fc2aSCody Peter Mello 247*3ee4fc2aSCody Peter Mello$AWK -safe 'BEGIN {system("date")}' > $TEMP0 2> $TEMP2 248*3ee4fc2aSCody Peter Mellogrep 'system is unsafe' $TEMP2 >/dev/null || fail 'BAD: T.errmsg system unsafe' 249*3ee4fc2aSCody Peter Mello 250e6d6c189SCody Peter Melloexit $RESULT 251