shithub: kwa

Download patch

ref: 703960d83de310d26c273c79c2f9abdd645e1eda
parent: edee032b5ea8bdf6dd56b81f9ea0e2efc2750bc5
author: qwx <qwx@sciops.net>
date: Wed Jan 7 19:02:09 EST 2026

test: port more tests

--- a/test/T.expr
+++ b/test/T.expr
@@ -1,5 +1,5 @@
 #!/bin/rc
-echo T.expr: tests of miscellaneous expressions
+echo T.expr: tests of miscellaneous expressions >[1=2]
 
 $awk '
 BEGIN {
@@ -31,7 +31,7 @@
 			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 test %d.%d failed",
+		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
@@ -143,7 +143,6 @@
 1	1 1 -1 1
 -1	-1 -1 1 -1
 0	0 0 0 0
-x	x 0 0 0
 
 try { printf("a%*sb\n", $1, $2) }
 1	x	axb
@@ -165,39 +164,19 @@
 2	1	ah b
 3	1	ah  b
 
-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
 
 try { print $1 || $2 }
 		0
@@ -224,10 +203,6 @@
 # $f++ => ($f)++
 try { f = 1; $f++; print f, $f }
 11	22	33	1 12
-
-# $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
 
 
 !!!!
--- /dev/null
+++ b/test/T.expr.broken
@@ -1,0 +1,103 @@
+#!/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
+
+
+!!!!
--- a/test/T.flags
+++ b/test/T.flags
@@ -1,24 +1,21 @@
 #!/bin/rc
-echo T.flags: test some commandline flags
+echo T.flags: test some commandline flags >[1=2]
 
 $awk >foo >[2=1]
-grep '[Uu]sage' foo >/dev/null || echo 'BAD: usage'
+grep '[Uu]sage' foo >/dev/null || echo 'BAD: T.flags: usage' >[1=2]
 
 $awk -f >foo >[2=1]
-grep 'no program' foo >/dev/null || echo 'BAD: no program'
+grep 'no program' foo >/dev/null || echo 'BAD: T.flags: no program' >[1=2]
 
 $awk -f glop/glop >foo >[2=1]
-grep 'can.t open' foo >/dev/null || echo 'BAD: can''t open program'
+grep 'can.t open' foo >/dev/null || echo 'BAD: T.flags: can''t open program' >[1=2]
 
-$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'
+grep 'unknown option' foo >/dev/null || echo 'BAD: T.flags: unknown option' >[1=2]
 
 $awk -F  >foo >[2=1]
-grep 'field separator FS is empty' foo >/dev/null || echo 'BAD: missing field separator'
+grep 'field separator FS is empty' foo >/dev/null || echo 'BAD: T.flags: missing field separator' >[1=2]
 
 ### 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'
+# grep 'field separator FS is empty' foo >/dev/null || echo 'BAD: T.flags: empty field separator' >[1=2]
--- /dev/null
+++ b/test/T.flags.broken
@@ -1,0 +1,5 @@
+#!/bin/rc
+echo T.flags: test some commandline flags >[1=2]
+
+$awk -fglop/glop >foo >[2=1]
+grep 'can.t open' foo >/dev/null || echo 'BAD: T.flags: can''t open program 2' >[1=2]
--- a/test/kwa.rc
+++ b/test/kwa.rc
@@ -34,8 +34,6 @@
 }
 
 broken=(\
-	T.expr \
-	T.flags \
 	T.func \
 	T.int-expr \
 	T.latin1 \
--