#!/bin/rcecho T.expr: tests of miscellaneous expressions >[1=2] $awk 'BEGIN { FS = "\t" awk = ENVIRON["awk"]}NF == 0 || $1 ~ /^#/ { next}$1 ~ /try/ { # new test nt++ sub(/try /, "") prog = $0 printf("%3d %s\n", nt, prog) prog = sprintf("%s -F''\\t'' ''%s''", awk, prog) # print "prog is", prog nt2 = 1 while (getline > 0) { if (NF == 0) # blank line terminates a sequence break input = $1 for (i = 2; i < NF; i++) # input data input = input "\t" $i test = sprintf("echo ''%s'' | %s >foo1."nt"."nt2"; ", input, prog) if ($NF == "\"\"") output = ">foo2."nt"."nt2";" else output = sprintf("echo ''%s'' >foo2."nt"."nt2"; ", $NF) gsub(/\\t/, "\t", output) gsub(/\\n/, "\n", output) run = sprintf("cmp foo1."nt"."nt2 " foo2."nt"."nt2 " || echo BAD: T.expr: %d.%d >[1=2]", nt, nt2) # print "input is", input # print "test is", test # print "output is", output # print "run is", run system(test output run) nt2++ } tt += nt2}END { print tt, "tests" }' <<'!!!!'# General format:# try program as rest of line# $1 $2 $3 output1 (\t for tab, \n for newline,# $1 $2 $3 output2 ("" for null)# ... terminated by blank line # try another program... # this one (3 & 4) may "fail" if a negative 0 is printed as -0,# but i think this might be a type-coercion problem. try { print $1, +$1, -$1, - -$1 }1 1 1 -1 1-1 -1 -1 1 -10 0 0 0 0x x 0 0 0 try { printf("%d %ld %lld %zd %jd %hd %hhd\n", $1, $1, $1, $1, $1, $1, $1) }1 1 1 1 1 1 1 110 10 10 10 10 10 10 1010000 10000 10000 10000 10000 10000 10000 10000 try { printf("%x %lx %llx %zx %jx %hx %hhx\n", $1, $1, $1, $1, $1, $1, $1) }1 1 1 1 1 1 1 110 a a a a a a a10000 2710 2710 2710 2710 2710 2710 2710 try { if ($1 ~ $2) print 1; else print 0 }a \141 1a \142 0a \x61 1a \x061 0a \x62 00 \060 10 \60 10 \0060 0Z \x5a 1Z \x5A 1 try { print $1 ~ $2 }a \141 1a \142 0a \x61 1a \x061 0a \x62 00 \060 10 \60 10 \0060 0Z \x5a 1Z \x5A 1 # $f[1]++ => ($f[1])++try { f[1]=1; f[2]=2; print $f[1], $f[1]++, $f[2], f[1], f[2] }111 222 333 111 111 222 2 2 !!!!
#!/bin/rc
echo T.expr: tests of miscellaneous expressions >[1=2]
$awk '
BEGIN {
FS = "\t"
awk = ENVIRON["awk"]
}
NF == 0 || $1 ~ /^#/ {
next
}
$1 ~ /try/ { # new test
nt++
sub(/try /, "")
prog = $0
printf("%3d %s\n", nt, prog)
prog = sprintf("%s -F''\\t'' ''%s''", awk, prog)
# print "prog is", prog
nt2 = 1
while (getline > 0) {
if (NF == 0) # blank line terminates a sequence
break
input = $1
for (i = 2; i < NF; i++) # input data
input = input "\t" $i
test = sprintf("echo ''%s'' | %s >foo1."nt"."nt2"; ",
input, prog)
if ($NF == "\"\"")
output = ">foo2."nt"."nt2";"
else
output = sprintf("echo ''%s'' >foo2."nt"."nt2"; ", $NF)
gsub(/\\t/, "\t", output)
gsub(/\\n/, "\n", output)
run = sprintf("cmp foo1."nt"."nt2 " foo2."nt"."nt2 " || echo BAD: T.expr: %d.%d >[1=2]",
nt, nt2)
# print "input is", input
# print "test is", test
# print "output is", output
# print "run is", run
system(test output run)
nt2++
}
tt += nt2
}
END { print tt, "tests" }
' <<'!!!!'
# General format:
# try program as rest of line
# $1 $2 $3 output1 (\t for tab, \n for newline,
# $1 $2 $3 output2 ("" for null)
# ... terminated by blank line
# try another program...
# this one (3 & 4) may "fail" if a negative 0 is printed as -0,
# but i think this might be a type-coercion problem.
try { print $1, +$1, -$1, - -$1 }
1 1 1 -1 1
-1 -1 -1 1 -1
0 0 0 0 0
x x 0 0 0
try { printf("%d %ld %lld %zd %jd %hd %hhd\n", $1, $1, $1, $1, $1, $1, $1) }
1 1 1 1 1 1 1 1
10 10 10 10 10 10 10 10
10000 10000 10000 10000 10000 10000 10000 10000
try { printf("%x %lx %llx %zx %jx %hx %hhx\n", $1, $1, $1, $1, $1, $1, $1) }
1 1 1 1 1 1 1 1
10 a a a a a a a
10000 2710 2710 2710 2710 2710 2710 2710
try { if ($1 ~ $2) print 1; else print 0 }
a \141 1
a \142 0
a \x61 1
a \x061 0
a \x62 0
0 \060 1
0 \60 1
0 \0060 0
Z \x5a 1
Z \x5A 1
try { print $1 ~ $2 }
a \141 1
a \142 0
a \x61 1
a \x061 0
a \x62 0
0 \060 1
0 \60 1
0 \0060 0
Z \x5a 1
Z \x5A 1
# $f[1]++ => ($f[1])++
try { f[1]=1; f[2]=2; print $f[1], $f[1]++, $f[2], f[1], f[2] }
111 222 333 111 111 222 2 2
!!!!