ref: 3996048a7ae210a0212743aa555dfb11a05574b1
parent: f01859c469dac3ed01d36a656cce03f0b63abae1
author: qwx <qwx@sciops.net>
date: Sat Oct 11 02:20:22 EDT 2025
add more tests
--- /dev/null
+++ b/test/T.errmsg
@@ -1,0 +1,207 @@
+#!/bin/rc
+echo T.errmsg: check some error messages
+
+ls >foo.glop
+awk=$awk awk '
+{ pat = $0+ prog = ""
+ while (getline x > 0 && x != "")
+ prog = prog "\n" x
+ print sprintf("\n%s ''%s'' <foo.glop >/dev/null >[2]foo",+ ENVIRON["awk"], prog)
+ print sprintf("grep ''%s'' foo >/dev/null || echo ''BAD: %s'' failed", pat, pat)+}
+' >foo.rc <<'!!!!'
+parsing error
+/(/
+
+illegal break, continue, next or nextfile from BEGIN
+BEGIN { nextfile }+
+illegal break, continue, next or nextfile from END
+END { nextfile }+
+nextfile is illegal inside a function
+function foo() { nextfile }+
+duplicate argument
+function f(i,j,i) { return i }+
+nonterminated character class
+/[[/
+
+nonterminated character class
+/[]/
+
+No closing ] for class
+/[\
+
+No closing ] for class
+BEGIN { s = "[x"; if (1 ~ s) print "foo"}+
+syntax error in regular expression
+BEGIN { if ("x" ~ /$^/) print "ugh" }+
+no matching parenthesis
+/((.)/
+
+division by zero
+BEGIN { print 1/0 }+
+division by zero in /=
+BEGIN { x = 1; print x /= 0 }+
+division by zero in %=
+BEGIN { x = 1; print x %= 0 }+
+division by zero in mod
+BEGIN { print 1%0 }+
+can.t read value.* array name.
+BEGIN { x[1] = 0; split("a b c", y, x) }+
+can.t read value.* function
+function f(){}; {split($0, x, f)}+
+can.t assign.* a function
+function f(){}; {f = split($0, x)}+
+can.t assign to x; it.s an array name.
+{x = split($0, x)}+
+is a function, not an array
+function f(){}; {split($0, f)}+
+function f called with 1 args, uses only 0
+BEGIN { f(f) }+function f() { print "x" }+
+can.t use function f as argument in f
+BEGIN { f(f) }+function f() { print "x" }+
+x is an array, not a function
+{ split($0, x) }; function x() {}+
+illegal nested function
+function x() { function g() {} }+
+return not in function
+{ return }+
+break illegal outside
+{ break }+
+continue illegal outside
+{ continue }+
+non-terminated string
+{ print "abc+}
+
+next is illegal inside a function
+BEGIN { f() }+function f() { next }+
+not enough args in printf\(%s\)
+BEGIN { printf("%s") }+
+weird printf conversion
+BEGIN { printf("%z", "foo")}+
+function f has .* arguments, limit .*
+function f(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,
+ c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,
+ e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10) {}+BEGIN { f(123) }+
+bailing out
+])}
+
+bailing out
+{ print }}+
+bailing out
+{ print }}}+
+bailing out
+]
+
+bailing out
+[
+
+bailing out
+a & b
+
+extra \)
+{ x = 1) }+
+illegal statement
+{ print ))}+
+illegal statement
+{{ print }+
+illegal statement
+{{{ print }+
+illegal .*next.* from BEGIN
+BEGIN { next }+
+illegal .*next.* from END
+END { next; print NR }+
+can.t open file ./nonexistentdir/foo
+BEGIN { print "abc" >"./nonexistentdir/foo" }+
+you can.t define function f more than once
+function f() { print 1 }+function f() { print 2 }+
+function mp called with 1 args, uses only 0
+function mp(){ cnt++;}+BEGIN { mp(xx) }+
+index.*doesn.t permit regular expressions
+BEGIN { index("abc", /a/) }+
+log argument out of domain
+BEGIN { print log(-1) }+
+exp result out of range
+BEGIN {print exp(1000)}+
+null file name in print or getline
+BEGIN { print >foo }+
+function has too many arguments
+BEGIN { length("abc", "def") }+
+calling undefined function foo
+BEGIN { foo() }+
+this should print a BAD message
+BEGIN { print }+!!!!
+
+rc ./foo.rc
+
+echo xxx >foo0
+$awk '{print x}' 'x=a+b' foo0 >foo1 >[2]foo2
+grep 'newline in string' foo2 >/dev/null || echo 'BAD: T.errmsg newline in string'
+
+$awk -safe 'BEGIN{"date" | getline}' >foo >[2]foo2+grep 'cmd | getline is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg cmd|getline unsafe'
+
+$awk -safe 'BEGIN{print >"foo"}' >foo >[2]foo2+grep 'print > is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg print > unsafe'
+
+$awk -safe 'BEGIN{print >> "foo"}' >foo >[2]foo2+grep 'print >> is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg print >> unsafe'
+
+$awk -safe 'BEGIN{print | "foo"}' >foo >[2]foo2+grep 'print | is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg print | unsafe'
+
+$awk -safe 'BEGIN {system("date")}' >foo >[2]foo2+grep 'system is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg system unsafe'
--- /dev/null
+++ b/test/T.flags
@@ -1,0 +1,24 @@
+#!/bin/rc
+echo T.flags: test some commandline flags
+
+$awk >foo >[2=1]
+grep '[Uu]sage' foo >/dev/null || echo 'BAD: usage'
+
+$awk -f >foo >[2=1]
+grep 'no program' foo >/dev/null || echo 'BAD: no program'
+
+$awk -f glop/glop >foo >[2=1]
+grep 'can.t open' foo >/dev/null || echo 'BAD: can''t open program'
+
+$awk -fglop/glop >foo >[2=1]
+grep 'can.t open' foo >/dev/null || echo 'BAD: can''t open program 2'
+
+$awk -zz 'BEGIN{}' >foo >[2=1]+grep 'unknown option' foo >/dev/null || echo 'BAD: unknown option'
+
+$awk -F >foo >[2=1]
+grep 'field separator FS is empty' foo >/dev/null || echo 'BAD: missing field separator'
+
+### Awk is now like gawk and splits into separate characters if FS = ""
+# $awk -F '' >foo >[2=1]
+# grep 'field separator FS is empty' foo >/dev/null || echo 'BAD: empty field separator'
--- /dev/null
+++ b/test/T.int-expr
@@ -1,0 +1,122 @@
+#!/bin/rc
+echo T.int-expr: test interval expressions
+
+rm -f foo
+
+cat << 'EOF' > prog
+NF == 0 { next }+$1 == "pat" { pattern = $2; next }+{+ check = ($1 ~ pattern)
+ printf("%s ~ /%s/ -> should be %d, is %d\n", $1, pattern, $2, check)+}
+EOF
+
+cat << 'EOF' > foo.in
+pat ab{0}c+ac 1
+abc 0
+
+pat a(b{0})c+ac 1
+abc 0
+
+pat ab{0}*c+ac 1
+abc 0
+
+pat a(b{0})*c+ac 1
+abc 0
+
+pat ab{0,}c+ac 1
+abc 1
+
+pat a(b{0,})c+ac 1
+abc 1
+
+pat ab{0,}*c+ac 1
+abc 1
+
+pat a(b{0,})*c+ac 1
+abc 1
+
+pat ab{1}c+ac 0
+abc 1
+abbc 0
+
+pat ab{1,}c+ac 0
+abc 1
+abbc 1
+abbbc 1
+abbbbc 1
+
+pat ab{0,1}c+ac 1
+abc 1
+abbc 0
+
+pat ab{0,3}c+ac 1
+abc 1
+abbc 1
+abbbc 1
+abbbbc 0
+
+pat ab{1,3}c+ac 0
+abc 1
+abbc 1
+abbbc 1
+abbbbc 0
+EOF
+
+cat << 'EOF' > foo1
+ac ~ /ab{0}c/ -> should be 1, is 1+abc ~ /ab{0}c/ -> should be 0, is 0+ac ~ /a(b{0})c/ -> should be 1, is 1+abc ~ /a(b{0})c/ -> should be 0, is 0+ac ~ /ab{0}*c/ -> should be 1, is 1+abc ~ /ab{0}*c/ -> should be 0, is 0+ac ~ /a(b{0})*c/ -> should be 1, is 1+abc ~ /a(b{0})*c/ -> should be 0, is 0+ac ~ /ab{0,}c/ -> should be 1, is 1+abc ~ /ab{0,}c/ -> should be 1, is 1+ac ~ /a(b{0,})c/ -> should be 1, is 1+abc ~ /a(b{0,})c/ -> should be 1, is 1+ac ~ /ab{0,}*c/ -> should be 1, is 1+abc ~ /ab{0,}*c/ -> should be 1, is 1+ac ~ /a(b{0,})*c/ -> should be 1, is 1+abc ~ /a(b{0,})*c/ -> should be 1, is 1+ac ~ /ab{1}c/ -> should be 0, is 0+abc ~ /ab{1}c/ -> should be 1, is 1+abbc ~ /ab{1}c/ -> should be 0, is 0+ac ~ /ab{1,}c/ -> should be 0, is 0+abc ~ /ab{1,}c/ -> should be 1, is 1+abbc ~ /ab{1,}c/ -> should be 1, is 1+abbbc ~ /ab{1,}c/ -> should be 1, is 1+abbbbc ~ /ab{1,}c/ -> should be 1, is 1+ac ~ /ab{0,1}c/ -> should be 1, is 1+abc ~ /ab{0,1}c/ -> should be 1, is 1+abbc ~ /ab{0,1}c/ -> should be 0, is 0+ac ~ /ab{0,3}c/ -> should be 1, is 1+abc ~ /ab{0,3}c/ -> should be 1, is 1+abbc ~ /ab{0,3}c/ -> should be 1, is 1+abbbc ~ /ab{0,3}c/ -> should be 1, is 1+abbbbc ~ /ab{0,3}c/ -> should be 0, is 0+ac ~ /ab{1,3}c/ -> should be 0, is 0+abc ~ /ab{1,3}c/ -> should be 1, is 1+abbc ~ /ab{1,3}c/ -> should be 1, is 1+abbbc ~ /ab{1,3}c/ -> should be 1, is 1+abbbbc ~ /ab{1,3}c/ -> should be 0, is 0+EOF
+
+$awk -f prog foo.in > foo2
+diff foo1 foo2 || echo 'BAD: T.int-expr (1)'
+rm -f prog
--- /dev/null
+++ b/test/T.lilly
@@ -1,0 +1,28 @@
+#!/bin/rc
+echo T.lilly: miscellaneous RE tests from Bruce Lilly
+
+rm -f foo
+$oldawk '
+BEGIN { awk = ENVIRON["oldawk"] }+/./ {+ print $0 >"foo"
+ close("foo")+ print "###", NR, $0
+ system(awk " -f foo <lilly.ifile")
+}' <lilly.progs >foo1 >[2=1]
+
+rm -f foo
+$awk '
+BEGIN { awk = ENVIRON["awk"] }+/./ {+ print $0 >"foo"
+ close("foo")+ print "###", NR, $0
+ system(awk " -f foo <lilly.ifile")
+}' <lilly.progs >foo2 >[2=1]
+
+echo `{cat lilly.progs | wc -l} tests+
+sed -e 's/'^$oldawk^'://' -e 's/Syntax/syntax/' -e '/warning:/d' foo1 >foo.glop1
+sed 's/'^$awk^'://' foo2 >foo.glop2
+diff foo.glop1 foo.glop2 >foo.lilly.diff || echo 'BAD: check foo.lilly.diff'
--- /dev/null
+++ b/test/lilly.ifile
@@ -1,0 +1,16 @@
+foo=bar
+foo==bar
+foo+bar
+foo+=bar
+foo-=bar
+foo*=bar
+foo/=bar
+foo^=bar
+foo%=bar
+foo!=bar
+foo<=bar
+foo>=bar
+foo bar
+foo/bar
+foo=bar=fribble
+=foo=bar
--- /dev/null
+++ b/test/lilly.progs
@@ -1,0 +1,126 @@
+BEGIN{foo=6;print foo/2}+BEGIN{foo=10;foo/=2;print foo}+/=/ {print $0}+/==/ {print $0}+/\+=/ {print $0}+/\*=/ {print $0}+/-=/ {print $0}+/\/=/ {print $0}+/%=/ {print $0}+/^=/ {print $0}+/!=/ {print $0}+/<=/ {print $0}+/>=/ {print $0}+!/=/ {print $0}+!/==/ {print $0}+!/\+=/ {print $0}+!/\*=/ {print $0}+!/-=/ {print $0}+!/\/=/ {print $0}+!/%=/ {print $0}+!/^=/ {print $0}+!/!=/ {print $0}+!/<=/ {print $0}+!/>=/ {print $0}+$0~/=/ {print $0}+$0~/==/ {print $0}+$0~/\+=/ {print $0}+$0~/\*=/ {print $0}+$0~/-=/ {print $0}+$0~/\/=/ {print $0}+$0~/%=/ {print $0}+$0~/^=/ {print $0}+$0~/!=/ {print $0}+$0~/<=/ {print $0}+$0~/>=/ {print $0}+$0!~/=/ {print $0}+$0!~/==/ {print $0}+$0!~/\+=/ {print $0}+$0!~/\*=/ {print $0}+$0!~/-=/ {print $0}+$0!~/%=/ {print $0}+$0!~/^=/ {print $0}+$0!~/!=/ {print $0}+$0!~/<=/ {print $0}+$0!~/>=/ {print $0}+{if(match($0,/=/))print $0}+{if(match($0,/\=/))print $0}+{if(match($0,/==/))print $0}+{if(match($0,/\+=/))print $0}+{if(match($0,/\*=/))print $0}+{if(match($0,/-=/))print $0}+{if(match($0,/%=/))print $0}+{if(match($0,/^=/))print $0}+{if(match($0,/!=/))print $0}+{if(match($0,/<=/))print $0}+{if(match($0,/>=/))print $0}+{if(!match($0,/=/))print $0}+{if(!match($0,/==/))print $0}+{if(!match($0,/\+=/))print $0}+{if(!match($0,/\*=/))print $0}+{if(!match($0,/-=/))print $0}+{if(!match($0,/%=/))print $0}+{if(!match($0,/^=/))print $0}+{if(!match($0,/!=/))print $0}+{if(!match($0,/<=/))print $0}+{if(!match($0,/>=/))print $0}+{if(split($0,foo,/=/))print $0}+{if(split($0,foo,/\=/))print $0}+{if(split($0,foo,/==/))print $0}+{if(split($0,foo,/\+=/))print $0}+{if(split($0,foo,/\*=/))print $0}+{if(split($0,foo,/-=/))print $0}+{if(split($0,foo,/\/=/))print $0}+{if(split($0,foo,/%=/))print $0}+{if(split($0,foo,/^=/))print $0}+{if(split($0,foo,/!=/))print $0}+{if(split($0,foo,/<=/))print $0}+{if(split($0,foo,/>=/))print $0}+{if(sub(/=/,"#"))print $0}+{if(sub(/\=/,"#"))print $0}+{if(sub(/==/,"#"))print $0}+{if(sub(/\+=/,"#"))print $0}+{if(sub(/\*=/,"#"))print $0}+{if(sub(/-=/,"#"))print $0}+{if(sub(/\/=/,"#"))print $0}+{if(sub(/%=/,"#"))print $0}+{if(sub(/^=/,"#"))print $0}+{if(sub(/!=/,"#"))print $0}+{if(sub(/<=/,"#"))print $0}+{if(sub(/>=/,"#"))print $0}+{if(gsub(/=/,"#"))print $0}+{if(gsub(/\=/,"#"))print $0}+{if(gsub(/==/,"#"))print $0}+{if(gsub(/\+=/,"#"))print $0}+{if(gsub(/\*=/,"#"))print $0}+{if(gsub(/-=/,"#"))print $0}+{if(gsub(/\/=/,"#"))print $0}+{if(gsub(/%=/,"#"))print $0}+{if(gsub(/^=/,"#"))print $0}+{if(gsub(/!=/,"#"))print $0}+{if(gsub(/<=/,"#"))print $0}+{if(gsub(/>=/,"#"))print $0}+{if(sub(/=/,"#",$0))print $0}+{if(sub(/\=/,"#",$0))print $0}+{if(sub(/==/,"#",$0))print $0}+{if(sub(/\+=/,"#",$0))print $0}+{if(sub(/\*=/,"#",$0))print $0}+{if(sub(/-=/,"#",$0))print $0}+{if(sub(/\/=/,"#",$0))print $0}+{if(sub(/%=/,"#",$0))print $0}+{if(sub(/^=/,"#",$0))print $0}+{if(sub(/!=/,"#",$0))print $0}+{if(sub(/<=/,"#",$0))print $0}+{if(sub(/>=/,"#",$0))print $0}+{if(sub(/=/,"#",$0))print $0}+{if(gsub(/\=/,"#",$0))print $0}+{if(gsub(/==/,"#",$0))print $0}+{if(gsub(/\+=/,"#",$0))print $0}+{if(gsub(/\*=/,"#",$0))print $0}+{if(gsub(/-=/,"#",$0))print $0}+{if(gsub(/\/=/,"#",$0))print $0}+{if(gsub(/%=/,"#",$0))print $0}+{if(gsub(/^=/,"#",$0))print $0}+{if(gsub(/!=/,"#",$0))print $0}+{if(gsub(/<=/,"#",$0))print $0}+{if(gsub(/>=/,"#",$0))print $0}--
⑨