1*23f24377SWarner Loshecho T.errmsg: check some error messages 2*23f24377SWarner Losh 3*23f24377SWarner Loshawk=${awk-../a.out} 4*23f24377SWarner Losh 5*23f24377SWarner Loshls >glop 6*23f24377SWarner Loshawk=$awk awk ' 7*23f24377SWarner Losh{ pat = $0 8*23f24377SWarner Losh prog = "" 9*23f24377SWarner Losh while (getline x > 0 && x != "") 10*23f24377SWarner Losh prog = prog "\n" x 11*23f24377SWarner Losh print sprintf("\n%s '"'"'%s'"'"' <glop >>devnull 2>foo", 12*23f24377SWarner Losh ENVIRON["awk"], prog) 13*23f24377SWarner Losh print sprintf("grep '"'"'%s'"'"' foo >>devnull || echo '"'"'BAD: %s'"'"' failed", pat, pat) 14*23f24377SWarner Losh} 15*23f24377SWarner Losh' >foo.sh <<\!!!! 16*23f24377SWarner Loshillegal primary in regular expression 17*23f24377SWarner Losh/(/ 18*23f24377SWarner Losh 19*23f24377SWarner Loshillegal break, continue, next or nextfile from BEGIN 20*23f24377SWarner LoshBEGIN { nextfile } 21*23f24377SWarner Losh 22*23f24377SWarner Loshillegal break, continue, next or nextfile from END 23*23f24377SWarner LoshEND { nextfile } 24*23f24377SWarner Losh 25*23f24377SWarner Loshnextfile is illegal inside a function 26*23f24377SWarner Loshfunction foo() { nextfile } 27*23f24377SWarner Losh 28*23f24377SWarner Loshduplicate argument 29*23f24377SWarner Loshfunction f(i,j,i) { return i } 30*23f24377SWarner Losh 31*23f24377SWarner Loshnonterminated character class 32*23f24377SWarner Losh/[[/ 33*23f24377SWarner Losh 34*23f24377SWarner Loshnonterminated character class 35*23f24377SWarner Losh/[]/ 36*23f24377SWarner Losh 37*23f24377SWarner Loshnonterminated character class 38*23f24377SWarner Losh/[\ 39*23f24377SWarner Losh 40*23f24377SWarner Loshnonterminated character class 41*23f24377SWarner LoshBEGIN { s = "[x"; if (1 ~ s) print "foo"} 42*23f24377SWarner Losh 43*23f24377SWarner Loshsyntax error in regular expression 44*23f24377SWarner LoshBEGIN { if ("x" ~ /$^/) print "ugh" } 45*23f24377SWarner Losh 46*23f24377SWarner Loshsyntax error in regular expression 47*23f24377SWarner Losh/((.)/ 48*23f24377SWarner Losh 49*23f24377SWarner Loshdivision by zero 50*23f24377SWarner LoshBEGIN { print 1/0 } 51*23f24377SWarner Losh 52*23f24377SWarner Loshdivision by zero in /= 53*23f24377SWarner LoshBEGIN { x = 1; print x /= 0 } 54*23f24377SWarner Losh 55*23f24377SWarner Loshdivision by zero in %= 56*23f24377SWarner LoshBEGIN { x = 1; print x %= 0 } 57*23f24377SWarner Losh 58*23f24377SWarner Loshdivision by zero in mod 59*23f24377SWarner LoshBEGIN { print 1%0 } 60*23f24377SWarner Losh 61*23f24377SWarner Loshcan.t read value.* array name. 62*23f24377SWarner LoshBEGIN { x[1] = 0; split("a b c", y, x) } 63*23f24377SWarner Losh 64*23f24377SWarner Loshcan.t read value.* function 65*23f24377SWarner Loshfunction f(){}; {split($0, x, f)} 66*23f24377SWarner Losh 67*23f24377SWarner Loshcan.t assign.* a function 68*23f24377SWarner Loshfunction f(){}; {f = split($0, x)} 69*23f24377SWarner Losh 70*23f24377SWarner Loshcan.t assign to x; it.s an array name. 71*23f24377SWarner Losh{x = split($0, x)} 72*23f24377SWarner Losh 73*23f24377SWarner Loshis a function, not an array 74*23f24377SWarner Loshfunction f(){}; {split($0, f)} 75*23f24377SWarner Losh 76*23f24377SWarner Loshfunction f called with 1 args, uses only 0 77*23f24377SWarner LoshBEGIN { f(f) } 78*23f24377SWarner Loshfunction f() { print "x" } 79*23f24377SWarner Losh 80*23f24377SWarner Loshcan.t use function f as argument in f 81*23f24377SWarner LoshBEGIN { f(f) } 82*23f24377SWarner Loshfunction f() { print "x" } 83*23f24377SWarner Losh 84*23f24377SWarner Loshx is an array, not a function 85*23f24377SWarner Losh{ split($0, x) }; function x() {} 86*23f24377SWarner Losh 87*23f24377SWarner Loshillegal nested function 88*23f24377SWarner Loshfunction x() { function g() {} } 89*23f24377SWarner Losh 90*23f24377SWarner Loshreturn not in function 91*23f24377SWarner Losh{ return } 92*23f24377SWarner Losh 93*23f24377SWarner Loshbreak illegal outside 94*23f24377SWarner Losh{ break } 95*23f24377SWarner Losh 96*23f24377SWarner Loshcontinue illegal outside 97*23f24377SWarner Losh{ continue } 98*23f24377SWarner Losh 99*23f24377SWarner Loshnon-terminated string 100*23f24377SWarner Losh{ print "abc 101*23f24377SWarner Losh} 102*23f24377SWarner Losh 103*23f24377SWarner Loshillegal field $(foo) 104*23f24377SWarner LoshBEGIN { print $"foo" } 105*23f24377SWarner Losh 106*23f24377SWarner Loshnext is illegal inside a function 107*23f24377SWarner LoshBEGIN { f() } 108*23f24377SWarner Loshfunction f() { next } 109*23f24377SWarner Losh 110*23f24377SWarner Loshnot enough args in printf(%s) 111*23f24377SWarner LoshBEGIN { printf("%s") } 112*23f24377SWarner Losh 113*23f24377SWarner Loshweird printf conversion 114*23f24377SWarner LoshBEGIN { printf("%z", "foo")} 115*23f24377SWarner Losh 116*23f24377SWarner Loshfunction f has .* arguments, limit .* 117*23f24377SWarner Loshfunction f(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10, 118*23f24377SWarner Losh c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10, 119*23f24377SWarner Losh e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10) {} 120*23f24377SWarner LoshBEGIN { f(123) } 121*23f24377SWarner Losh 122*23f24377SWarner Loshbailing out 123*23f24377SWarner Losh])} 124*23f24377SWarner Losh 125*23f24377SWarner Loshbailing out 126*23f24377SWarner Losh{ print }} 127*23f24377SWarner Losh 128*23f24377SWarner Loshbailing out 129*23f24377SWarner Losh{ print }}} 130*23f24377SWarner Losh 131*23f24377SWarner Loshbailing out 132*23f24377SWarner Losh] 133*23f24377SWarner Losh 134*23f24377SWarner Loshbailing out 135*23f24377SWarner Losh[ 136*23f24377SWarner Losh 137*23f24377SWarner Loshbailing out 138*23f24377SWarner Losha & b 139*23f24377SWarner Losh 140*23f24377SWarner Loshextra ) 141*23f24377SWarner Losh{ x = 1) } 142*23f24377SWarner Losh 143*23f24377SWarner Loshillegal statement 144*23f24377SWarner Losh{ print ))} 145*23f24377SWarner Losh 146*23f24377SWarner Loshillegal statement 147*23f24377SWarner Losh{{ print } 148*23f24377SWarner Losh 149*23f24377SWarner Loshillegal statement 150*23f24377SWarner Losh{{{ print } 151*23f24377SWarner Losh 152*23f24377SWarner Loshillegal .*next.* from BEGIN 153*23f24377SWarner LoshBEGIN { next } 154*23f24377SWarner Losh 155*23f24377SWarner Loshillegal .*next.* from END 156*23f24377SWarner LoshEND { next; print NR } 157*23f24377SWarner Losh 158*23f24377SWarner Loshcan.t open file ./nonexistentdir/foo 159*23f24377SWarner LoshBEGIN { print "abc" >"./nonexistentdir/foo" } 160*23f24377SWarner Losh 161*23f24377SWarner Loshyou can.t define function f more than once 162*23f24377SWarner Loshfunction f() { print 1 } 163*23f24377SWarner Loshfunction f() { print 2 } 164*23f24377SWarner Losh 165*23f24377SWarner Loshfunction mp called with 1 args, uses only 0 166*23f24377SWarner Loshfunction mp(){ cnt++;} 167*23f24377SWarner LoshBEGIN { mp(xx) } 168*23f24377SWarner Losh 169*23f24377SWarner Loshindex.*doesn.t permit regular expressions 170*23f24377SWarner LoshBEGIN { index("abc", /a/) } 171*23f24377SWarner Losh 172*23f24377SWarner Loshlog argument out of domain 173*23f24377SWarner LoshBEGIN { print log(-1) } 174*23f24377SWarner Losh 175*23f24377SWarner Loshexp result out of range 176*23f24377SWarner LoshBEGIN {print exp(1000)} 177*23f24377SWarner Losh 178*23f24377SWarner Loshnull file name in print or getline 179*23f24377SWarner LoshBEGIN { print >foo } 180*23f24377SWarner Losh 181*23f24377SWarner Loshfunction has too many arguments 182*23f24377SWarner LoshBEGIN { length("abc", "def") } 183*23f24377SWarner Losh 184*23f24377SWarner Loshcalling undefined function foo 185*23f24377SWarner LoshBEGIN { foo() } 186*23f24377SWarner Losh 187*23f24377SWarner Loshthis should print a BAD message 188*23f24377SWarner LoshBEGIN { print } 189*23f24377SWarner Losh!!!! 190*23f24377SWarner Losh 191*23f24377SWarner Losh 192*23f24377SWarner Loshecho ' running tests in foo.sh' 193*23f24377SWarner Loshsh foo.sh 194*23f24377SWarner Losh 195*23f24377SWarner Loshtest -r core && echo BAD: someone dropped core 1>&2 196*23f24377SWarner Losh 197*23f24377SWarner Loshecho xxx >foo0 198*23f24377SWarner Losh$awk '{print x}' x='a 199*23f24377SWarner Loshb' foo0 >foo1 2>foo2 200*23f24377SWarner Loshgrep 'newline in string' foo2 >/dev/null || echo 'BAD: T.errmsg newline in string' 201*23f24377SWarner Losh 202*23f24377SWarner Losh$awk -safe 'BEGIN{"date" | getline}' >foo 2>foo2 203*23f24377SWarner Loshgrep 'cmd | getline is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg cmd|getline unsafe' 204*23f24377SWarner Losh 205*23f24377SWarner Losh$awk -safe 'BEGIN{print >"foo"}' >foo 2>foo2 206*23f24377SWarner Loshgrep 'print > is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg print > unsafe' 207*23f24377SWarner Losh 208*23f24377SWarner Losh$awk -safe 'BEGIN{print >> "foo"}' >foo 2>foo2 209*23f24377SWarner Loshgrep 'print >> is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg print >> unsafe' 210*23f24377SWarner Losh 211*23f24377SWarner Losh$awk -safe 'BEGIN{print | "foo"}' >foo 2>foo2 212*23f24377SWarner Loshgrep 'print | is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg print | unsafe' 213*23f24377SWarner Losh 214*23f24377SWarner Losh$awk -safe 'BEGIN {system("date")}' >foo 2>foo2 215*23f24377SWarner Loshgrep 'system is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg system unsafe' 216