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