1 1.1 christos #!/bin/sh 2 1.1 christos 3 1.1 christos echo T.misc: miscellaneous buglets now watched for 4 1.1 christos 5 1.1 christos awk=${awk-../a.out} 6 1.1 christos 7 1.1 christos rm -f core 8 1.1 christos 9 1.1 christos echo 'The big brown over the lazy doe 10 1.1 christos The big brown over the lazy dog 11 1.1 christos x 12 1.1 christos The big brown over the lazy dog' >foo 13 1.1 christos echo 'failed 14 1.1 christos succeeded 15 1.1 christos failed 16 1.1 christos succeeded' >foo1 17 1.1 christos $awk '{ if (match($0, /^The big brown over the lazy dog/) == 0) { 18 1.1 christos printf("failed\n") 19 1.1 christos } else { 20 1.1 christos printf("succeeded\n") 21 1.1 christos } 22 1.1 christos } ' foo >foo2 23 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc ghosh RE bug' 24 1.1 christos 25 1.1 christos echo '123 26 1.1 christos 1234567890 27 1.1 christos 12345678901' >foo 28 1.1 christos echo '12345678901' >foo1 29 1.1 christos $awk 'length($0) > 10' foo >foo2 30 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc last number bug' 31 1.1 christos 32 1.1 christos # check some \ sequences in strings (ascii) 33 1.1 christos echo HIJKL >foo1 34 1.1 christos echo foo | $awk '{ print "H\x49\x4a\x4BL" }' >foo2 35 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc hex string cvt' 36 1.1 christos 37 1.1 christos echo 012x45 >foo1 38 1.1 christos $awk 'BEGIN { print "0\061\62x\0645" }' >foo2 39 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc oct string cvt' 40 1.1 christos 41 1.1 christos # $i++ means ($i)++ 42 1.1 christos echo 3 5 | $awk '{ i = 1; print $i++ ; print $1, i }' >foo1 43 1.1 christos echo '3 44 1.1 christos 4 1' >foo2 45 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc bad field increment' 46 1.1 christos 47 1.1 christos # makes sure that fields are recomputed even if self-assignment 48 1.1 christos # take into account that subtracting from NF now rebuilds the record 49 1.1 christos echo 'a b c 50 1.1 christos s p q r 51 1.1 christos x y z' >foo 52 1.1 christos echo 'a 53 1.1 christos s p 54 1.1 christos x' >foo1 55 1.1 christos $awk '{ NF -= 2; $1 = $1; print }' <foo >foo2 56 1.1 christos diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad field self-assignment" 57 1.1 christos 58 1.1 christos echo '1 59 1.1 christos 1' >foo1 60 1.1 christos $awk 'BEGIN {x = 1; print x; x = x; print x}' >foo2 61 1.1 christos diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad self-assignment" 62 1.1 christos 63 1.1 christos echo 573109312 | $awk '{print $1*4}' >foo1 64 1.1 christos echo 2292437248 >foo2 65 1.1 christos diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad overflow" 66 1.1 christos 67 1.1 christos # note that there are 8-bit characters in the echo 68 1.1 christos # some shells will probably screw this up. 69 1.1 christos echo '# 70 1.1 christos code 1 71 1.1 christos code 2' | 72 1.1 christos $awk '/^#/' >foo1 73 1.1 christos echo '#' >foo2 74 1.1 christos diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad match of 8-bit char" 75 1.1 christos 76 1.1 christos echo hello | 77 1.1 christos $awk 'BEGIN { FILENAME = "/etc/passwd" } 78 1.1 christos { print $0 }' >/dev/null 79 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc /etc/passwd dropped core"; fi 80 1.1 christos 81 1.1 christos echo hello | 82 1.1 christos $awk ' function foo(foo) { 83 1.1 christos foo = 1 84 1.1 christos foo() 85 1.1 christos } 86 1.1 christos { foo(bar) } 87 1.1 christos ' >/dev/null 2>&1 88 1.1 christos if test -r core; then 89 1.1 christos echo 1>&2 "BAD: T.misc function foo(foo) dropped core" 90 1.1 christos rm -f core 91 1.1 christos fi 92 1.1 christos 93 1.1 christos echo '2 94 1.1 christos 10' | 95 1.1 christos $awk '{ x[NR] = $0 } # test whether $0 is NUM as well as STR 96 1.1 christos END { if (x[1] > x[2]) print "BAD: T.misc: $0 is not NUM" }' 97 1.1 christos 98 1.1 christos 99 1.1 christos $awk 'BEGIN { 100 1.1 christos npad = substr("alexander" " ",1,15) 101 1.1 christos print npad 102 1.1 christos }' >foo 103 1.1 christos grep '\\' foo && echo 1>&2 "BAD: T.misc alexander fails" 104 1.1 christos 105 1.1 christos # This should give an error about function arguments 106 1.1 christos $awk ' 107 1.1 christos function foo(x) { print "x is" x } 108 1.1 christos BEGIN { foo(foo) } 109 1.1 christos ' 2>foo 110 1.1 christos grep "can't use function foo" foo >/dev/null || echo 1>&2 "BAD: T.misc fcn args" 111 1.1 christos 112 1.1 christos 113 1.1 christos # gawk defref test; should give error about undefined function 114 1.1 christos $awk 'BEGIN { foo() }' 2>foo 115 1.1 christos grep "calling undefined function foo" foo >/dev/null || echo 1>&2 "BAD: T.misc undefined function" 116 1.1 christos 117 1.1 christos 118 1.1 christos # gawk arrayparm test; should give error about function 119 1.1 christos $awk ' 120 1.1 christos BEGIN { 121 1.1 christos foo[1]=1; 122 1.1 christos foo[2]=2; 123 1.1 christos bug1(foo); 124 1.1 christos } 125 1.1 christos function bug1(i) { 126 1.1 christos for (i in foo) { 127 1.1 christos bug2(i); 128 1.1 christos delete foo[i]; 129 1.1 christos print i,1,bot[1]; 130 1.1 christos } 131 1.1 christos } 132 1.1 christos function bug2(arg) { 133 1.1 christos bot[arg]=arg; 134 1.1 christos } 135 1.1 christos ' 2>foo 136 1.1 christos grep "can.t assign to foo" foo >/dev/null || echo 1>&2 "BAD: T.misc foo bug" 137 1.1 christos 138 1.1 christos 139 1.1 christos # This should be a syntax error 140 1.1 christos $awk ' 141 1.1 christos !x = y 142 1.1 christos ' 2>foo 143 1.1 christos grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error !x=y fails" 144 1.1 christos 145 1.1 christos # This should print bbb 146 1.1 christos $awk ' 147 1.1 christos BEGIN { up[1] = "a" 148 1.1 christos for (i in up) gsub("a", "A", x) 149 1.1 christos print x x "bbb" 150 1.1 christos exit 151 1.1 christos } 152 1.1 christos ' >foo 153 1.1 christos grep bbb foo >/dev/null || echo 1>&2 "BAD: T.misc gsub failed" 154 1.1 christos 155 1.1 christos echo yes | 156 1.1 christos $awk ' 157 1.1 christos BEGIN { 158 1.1 christos printf "push return" >"/dev/null" 159 1.1 christos getline ans <"/dev/null" 160 1.1 christos } ' 161 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc getline ans dropped core"; fi 162 1.1 christos 163 1.1 christos $awk 'BEGIN { unireghf() } 164 1.1 christos function unireghf(hfeed) { hfeed[1] = 0 }' 165 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc unireghf dropped core"; fi 166 1.1 christos 167 1.1 christos echo x | $awk '/[/]/' 2>foo 168 1.1 christos grep 'nonterminated character class' foo >/dev/null || error 'BAD: T.misc nonterminated fails' 169 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc nonterminated dropped core"; fi 170 1.1 christos 171 1.1 christos $awk ' 172 1.1 christos function f() { return 12345 } 173 1.1 christos BEGIN { printf "<%s>\n", f() } 174 1.1 christos ' >foo 175 1.1 christos grep '<12345>' foo >/dev/null || echo 'BAD: T.misc <12345> fails' 176 1.1 christos 177 1.1 christos echo 'abc 178 1.1 christos def 179 1.1 christos 180 1.1 christos ghi 181 1.1 christos jkl' >foo 182 1.1 christos $awk ' 183 1.1 christos BEGIN { RS = "" 184 1.1 christos while (getline <"foo") 185 1.1 christos print 186 1.1 christos }' >foo1 187 1.1 christos $awk 'END {print NR}' foo1 | grep 4 >/dev/null || echo 'BAD: T.misc abcdef fails' 188 1.1 christos 189 1.1.1.2 christos # Test for RS regex matching an empty record at EOF 190 1.1.1.2 christos echo a | $awk 1 RS='a\n' > foo1 191 1.1.1.2 christos cat << \EOF > foo2 192 1.1.1.2 christos 193 1.1.1.2 christos EOF 194 1.1.1.2 christos diff foo1 foo2 || echo 'BAD: T.misc RS regex matching an empty record at EOF fails' 195 1.1.1.2 christos 196 1.1.1.2 christos # Test for RS regex being reapplied 197 1.1.1.2 christos echo aaa1a2a | $awk 1 RS='^a' >foo1 198 1.1.1.2 christos cat << \EOF > foo2 199 1.1.1.2 christos 200 1.1.1.2 christos aa1a2a 201 1.1.1.2 christos 202 1.1.1.2 christos EOF 203 1.1.1.2 christos diff foo1 foo2 || echo 'BAD: T.misc ^regex reapplied fails' 204 1.1.1.2 christos 205 1.1.1.2 christos # ^-anchored RS matching should be active at the start of each input file 206 1.1.1.2 christos tee foo1 foo2 >foo3 << \EOF 207 1.1.1.2 christos aaa 208 1.1.1.2 christos EOF 209 1.1.1.2 christos $awk 1 RS='^a' foo1 foo2 foo3 >foo4 210 1.1.1.2 christos cat << \EOF > foo5 211 1.1.1.2 christos 212 1.1.1.2 christos aa 213 1.1.1.2 christos 214 1.1.1.2 christos 215 1.1.1.2 christos aa 216 1.1.1.2 christos 217 1.1.1.2 christos 218 1.1.1.2 christos aa 219 1.1.1.2 christos 220 1.1.1.2 christos EOF 221 1.1.1.2 christos diff foo4 foo5 || echo 'BAD: T.misc ^RS matches the start of every input file fails' 222 1.1 christos 223 1.1 christos # The following should not produce a warning about changing a constant 224 1.1 christos # nor about a curdled tempcell list 225 1.1 christos $awk 'function f(x) { x = 2 } 226 1.1 christos BEGIN { f(1) }' >foo 227 1.1 christos grep '^' foo && echo 'BAD: test constant change fails' 228 1.1 christos 229 1.1 christos # The following should not produce a warning about a curdled tempcell list 230 1.1 christos $awk 'function f(x) { x } 231 1.1 christos BEGIN { f(1) }' >foo 232 1.1 christos grep '^' foo && echo 'BAD: test tempcell list fails' 233 1.1 christos 234 1.1 christos $awk 'BEGIN { print 9, a=10, 11; print a; exit }' >foo1 235 1.1 christos echo '9 10 11 236 1.1 christos 10' >foo2 237 1.1 christos diff foo1 foo2 || echo 'BAD: T.misc (embedded expression)' 238 1.1 christos 239 1.1 christos echo "abc defgh ijkl" | $awk ' 240 1.1 christos { $1 = ""; line = $0; print line; print $0; $0 = line; print $0 }' >foo1 241 1.1 christos echo " defgh ijkl 242 1.1 christos defgh ijkl 243 1.1 christos defgh ijkl" >foo2 244 1.1 christos diff foo1 foo2 || echo 'BAD: T.misc (assignment to $0)' 245 1.1 christos 246 1.1 christos $awk ' 247 1.1 christos function min(a, b) 248 1.1 christos { 249 1.1 christos if (a < b) 250 1.1 christos return a 251 1.1 christos else 252 1.1 christos return b 253 1.1 christos } 254 1.1 christos BEGIN { exit } 255 1.1 christos ' 256 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc function min dropped core"; fi 257 1.1 christos 258 1.1 christos # The following should not give a syntax error message: 259 1.1 christos $awk ' 260 1.1 christos function expand(chart) { 261 1.1 christos getline chart < "CHAR.ticks" 262 1.1 christos } 263 1.1 christos ' >foo 264 1.1 christos grep '^' foo >/dev/null && echo 'BAD: T.misc expand error' 265 1.1 christos 266 1.1 christos $awk 'BEGIN { print 1e40 }' >/dev/null 267 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc 1E40 dropped core"; fi 268 1.1 christos 269 1.1 christos # The following syntax error should not dump core: 270 1.1 christos $awk ' 271 1.1 christos $NF==3 {first=1} 272 1.1 christos $NF==2 && first==0 && (abs($1-o1)>120||abs($2-o2)>120) {print $0} 273 1.1 christos $NF==2 {o1=%1; o2=$2; first=0} 274 1.1 christos ' 2>/dev/null 275 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc first/abs dropped core"; fi 276 1.1 christos 277 1.1 christos # The following syntax error should not dump core: 278 1.1 christos $awk '{ n = split($1, address, !); print address[1] }' 2>foo 279 1.1 christos grep 'illegal statement' foo >/dev/null || echo 'BAD: T.misc split error' 280 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc split! dropped core"; fi 281 1.1 christos 282 1.1 christos # The following should cause a syntax error message 283 1.1 christos $awk 'BEGIN {"hello"}' 2>foo 284 1.1 christos grep 'illegal statement' foo >/dev/null || echo 'BAD: T.misc hello error' 285 1.1 christos 286 1.1 christos # The following should give a syntax error message: 287 1.1 christos $awk ' 288 1.1 christos function pile(c, r) { 289 1.1 christos r = ++pile[c] 290 1.1 christos } 291 1.1 christos 292 1.1 christos { pile($1) } 293 1.1 christos ' 2>foo 294 1.1 christos grep 'context is' foo >/dev/null || echo 'BAD: T.misc pile error' 295 1.1 christos 296 1.1 christos # This should complain about missing atan2 argument: 297 1.1 christos $awk 'BEGIN { atan2(1) }' 2>foo 298 1.1 christos grep 'requires two arg' foo >/dev/null || echo 'BAD: T.misc atan2 error' 299 1.1 christos 300 1.1 christos # This should not core dump: 301 1.1 christos $awk 'BEGIN { f() } 302 1.1 christos function f(A) { delete A[1] } 303 1.1 christos ' 304 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc delete dropped core"; fi 305 1.1 christos 306 1.1 christos # nasty one: should not be able to overwrite constants 307 1.1 christos $awk 'BEGIN { gsub(/ana/,"anda","banana") 308 1.1 christos printf "the monkey ate a %s\n", "banana" } 309 1.1 christos ' >/dev/null 2>foo 310 1.1 christos grep 'syntax error' foo >/dev/null || echo 'BAD: T.misc gsub banana error' 311 1.1 christos 312 1.1 christos # nasty one: should not be able to overwrite constants 313 1.1 christos $awk 'BEGIN { sub(/ana/,"anda","banana") 314 1.1 christos printf "the monkey ate a %s\n", "banana" } 315 1.1 christos ' >/dev/null 2>foo 316 1.1 christos grep 'syntax error' foo >/dev/null || echo 'BAD: T.misc sub banana error' 317 1.1 christos 318 1.1 christos # line numbers used to double-count comments 319 1.1 christos $awk '# 320 1.1 christos # 321 1.1 christos # 322 1.1 christos /x 323 1.1 christos ' >/dev/null 2>foo 324 1.1 christos grep 'line [45]' foo >/dev/null || echo 'BAD: T.misc lineno' 325 1.1 christos 326 1.1 christos echo 'x \y' >foo1 330 1.1 christos $awk 'BEGIN { print "x\f\r\b\v\a\\y" }' >foo2 331 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc weird chars' 332 1.1 christos 333 1.1 christos echo 0 >foo1 334 1.1 christos $awk ' BEGIN { exit } 335 1.1 christos { print } 336 1.1 christos END { print NR }' >foo2 337 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc BEGIN exit' 338 1.1 christos 339 1.1 christos echo 1 >foo1 340 1.1 christos $awk ' { exit } 341 1.1 christos END { print NR }' /etc/passwd >foo2 342 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit' 343 1.1 christos 344 1.1 christos echo 1 >foo1 345 1.1 christos $awk ' {i = 1; while (i <= NF) {if (i == NF) exit; i++ } } 346 1.1 christos END { print NR }' /etc/passwd >foo2 347 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 2' 348 1.1 christos 349 1.1 christos echo 1 >foo1 350 1.1 christos $awk ' function f() { 351 1.1 christos i = 1; while (i <= NF) {if (i == NF) return NR; i++ } 352 1.1 christos } 353 1.1 christos { if (f() == 1) exit } 354 1.1 christos END { print NR }' /etc/passwd >foo2 355 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc while return' 356 1.1 christos 357 1.1 christos echo 1 >foo1 358 1.1 christos $awk ' function f() { 359 1.1 christos split("a b c", arr) 360 1.1 christos for (i in arr) {if (i == 3) return NR; i++ } 361 1.1 christos } 362 1.1 christos { if (f() == 1) exit } 363 1.1 christos END { print NR }' /etc/passwd >foo2 364 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc while return' 365 1.1 christos 366 1.1 christos echo 1 >foo1 367 1.1 christos $awk ' {i = 1; do { if (i == NF) exit; i++ } while (i <= NF) } 368 1.1 christos END { print NR }' /etc/passwd >foo2 369 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 3' 370 1.1 christos 371 1.1 christos echo 1 >foo1 372 1.1 christos $awk ' function f() { 373 1.1 christos i = 1; do { if (i == NF) return NR; i++ } while (i <= NF) 374 1.1 christos } 375 1.1 christos { if (f() == 1) exit } 376 1.1 christos END { print NR }' /etc/passwd >foo2 377 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc do return' 378 1.1 christos 379 1.1 christos echo 1 >foo1 380 1.1 christos $awk ' {i = 1; do { if (i == NF) break; i++ } while (i <= NF); exit } 381 1.1 christos END { print NR }' /etc/passwd >foo2 382 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 4' 383 1.1 christos 384 1.1 christos echo 1 >foo1 385 1.1 christos $awk ' { n = split($0, x) 386 1.1 christos for (i in x) { 387 1.1 christos if (i == 1) 388 1.1 christos exit } } 389 1.1 christos END { print NR }' /etc/passwd >foo2 390 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 5' 391 1.1 christos 392 1.1 christos echo XXXXXXXX >foo1 393 1.1 christos $awk 'BEGIN { s = "ab\fc\rd\be" 394 1.1 christos t = s; gsub("[" s "]", "X", t); print t }' >foo2 395 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc weird escapes in char class' 396 1.1 christos 397 1.1 christos $awk '{}' /etc/passwd glop/glop >foo 2>foo2 398 1.1 christos grep "can't open.*glop" foo2 >/dev/null || echo "BAD: T.misc can't open" 399 1.1 christos 400 1.1 christos echo ' 401 1.1 christos 402 1.1 christos 403 1.1 christos a 404 1.1 christos aa 405 1.1 christos 406 1.1 christos b 407 1.1 christos 408 1.1 christos 409 1.1 christos c 410 1.1 christos 411 1.1 christos ' >foo 412 1.1 christos echo 3 >foo1 413 1.1 christos $awk 'BEGIN { RS = "" }; END { print NR }' foo >foo2 414 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc RS botch' 415 1.1 christos 416 1.1 christos $awk 'BEGIN \ 417 1.1 christos { 418 1.1.1.3 christos print "hello, world" 419 1.1 christos } 420 1.1.1.3 christos }}}' >foo1 2>foo2 421 1.1.1.3 christos grep 'source line 5' foo2 >/dev/null 2>&1 || echo 'BAD: T.misc continuation line number' 422 1.1.1.3 christos 423 1.1.1.3 christos $awk 'BEGIN { 424 1.1.1.3 christos if () { 425 1.1.1.3 christos print "foo" 426 1.1 christos } 427 1.1 christos }' >foo1 2>foo2 428 1.1 christos grep 'syntax error at source line 2' foo2 >/dev/null 2>&1 || echo 'BAD: T.misc syntax error line number' 429 1.1 christos 430 1.1 christos echo 111 222 333 >foo 431 1.1 christos $awk '{ f[1]=1; f[2]=2; print $f[1], $f[1]++, $f[2], f[1], f[2] }' foo >foo2 432 1.1 christos echo 111 111 222 2 2 >foo1 433 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc $f[1]++' 434 1.1 christos 435 1.1 christos 436 1.1 christos # These should be syntax errors 437 1.1 christos $awk . 2>foo 438 1.1 christos grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error . fails" 439 1.1 christos 440 1.1 christos $awk .. 2>foo 441 1.1 christos grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error .. fails" 442 1.1 christos 443 1.1 christos $awk .E. 2>foo 444 1.1 christos grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error .E. fails" 445 1.1 christos 446 1.1 christos $awk .++. 2>foo 447 1.1 christos grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error .++. fails" 448 1.1 christos 449 1.1 christos 450 1.1 christos 451 1.1 christos # These should be syntax errors 452 1.1 christos $awk '$' 2>foo 453 1.1 christos grep "unexpected" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error $ fails" 454 1.1 christos 455 1.1 christos $awk '{print $' 2>foo 456 1.1 christos grep "unexpected" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error $2 fails" 457 1.1 christos 458 1.1 christos $awk '"' 2>foo 459 1.1 christos grep "non-terminated" foo >/dev/null || echo 1>&2 "BAD: T.misc bare quote fails" 460 1.1 christos 461 1.1 christos 462 1.1 christos # %c of 0 is explicit null byte 463 1.1 christos 464 1.1 christos ./echo '3' >foo1 465 1.1 christos $awk 'BEGIN {printf("%c%c\n", 0, 0) }' | wc | $awk '{print $3}' >foo2 466 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc null byte' 467 1.1 christos 468 1.1 christos # non-terminated RE 469 1.1 christos 470 1.1 christos $awk /xyz >foo 2>&1 471 1.1 christos grep "non-terminated" foo >/dev/null || echo 1>&2 "BAD: T.misc non-terminated RE" 472 1.1 christos 473 1.1 christos # next several were infinite loops, found by brian tsang. 474 1.1 christos # this is his example: 475 1.1 christos 476 1.1 christos $awk 'BEGIN { 477 1.1 christos switch (substr("x",1,1)) { 478 1.1 christos case /ask.com/: 479 1.1 christos break 480 1.1 christos case "google": 481 1.1 christos break 482 1.1 christos } 483 1.1 christos }' >foo 2>&1 484 1.1 christos grep "illegal statement" foo >/dev/null || echo 1>&2 "BAD: T.misc looping syntax error 1" 485 1.1 christos 486 1.1 christos $awk 'BEGIN { s { c /./ } }' >foo 2>&1 487 1.1 christos grep "illegal statement" foo >/dev/null || echo 1>&2 "BAD: T.misc looping syntax error 2" 488 1.1 christos 489 1.1 christos $awk 'BEGIN { s { c /../ } }' >foo 2>&1 490 1.1 christos grep "illegal statement" foo >/dev/null || echo 1>&2 "BAD: T.misc looping syntax error 3" 491 1.1 christos 492 1.1 christos $awk 'BEGIN {printf "%2$s %1$s\n", "a", "b"}' >foo 2>&1 493 1.1 christos grep "'$' not permitted in awk formats" foo >/dev/null || echo 1>&2 "BAD: T.misc '$' not permitted in formats" 494 1.1 christos 495 1.1 christos echo 'a 496 1.1 christos b c 497 1.1 christos de fg hi' >foo0 498 1.1 christos $awk 'END { print NF, $0 }' foo0 >foo1 499 1.1 christos awk '{ print NF, $0 }' foo0| tail -1 >foo2 500 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc END must preserve $0' 501 1.1 christos 502 1.1 christos echo 'fg hi' >foo0 503 1.1 christos $awk 'END { print NF, $0 }' foo0 >foo1 504 1.1 christos awk '{ print NF, $0 }' foo0| tail -1 >foo2 505 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc END must preserve $0' 506 1.1 christos 507 1.1 christos echo '' >foo0 508 1.1 christos $awk 'END { print NF, $0 }' foo0 >foo1 509 1.1 christos awk '{ print NF, $0 }' foo0| tail -1 >foo2 510 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc END must preserve $0' 511 1.1 christos 512 1.1 christos # Check for nonzero exit status on I/O error. 513 1.1.1.2 christos echo 'E 2' >foo1 514 1.1.1.2 christos (trap '' PIPE; "$awk" 'BEGIN { print "hi"; }' 2>/dev/null; echo "E $?" >foo2) | : 515 1.1.1.2 christos cmp -s foo1 foo2 || echo 'BAD: T.misc exit status on I/O error' 516 1.1.1.2 christos 517 1.1.1.2 christos # Check for clobbering of the lexer's regular expression buffer. 518 1.1.1.2 christos # If the output is "a1" instead of "1b", /b/ clobbered /a/. 519 1.1.1.2 christos echo 1b >foo1 520 1.1.1.2 christos echo ab | $awk '{ sub(/a/, "b" ~ /b/); print }' >foo2 521 1.1.1.2 christos cmp -s foo1 foo2 || echo 'BAD: T.misc lexer regex buffer clobbered' 522 1.1.1.2 christos 523 1.1.1.2 christos # Check handling of octal \OOO and hex \xHH esc. seqs. in strings. 524 1.1.1.2 christos echo 'hello888 525 1.1.1.2 christos hello 526 1.1.1.2 christos hello 527 1.1.1.2 christos helloxGOO 528 1.1.1.2 christos hello 529 1.1.1.2 christos 0A' > foo1 530 1.1.1.2 christos $awk 'BEGIN { print "hello\888" }' > foo2 531 1.1.1.2 christos $awk 'BEGIN { print "hello\x000A" }' >> foo2 532 1.1.1.2 christos $awk 'BEGIN { printf "hello\x0A" }' >> foo2 533 $awk 'BEGIN { print "hello\xGOO" }' >> foo2 534 $awk 'BEGIN { print "hello\x0A0A" }' >> foo2 535 cmp -s foo1 foo2 || echo 'BAD: T.misc escape sequences in strings mishandled' 536