1@echo off
2rem $MawkId: mawktest.bat,v 1.12 2014/08/20 20:01:16 tom Exp $
3rem vile:rs=lf
4rem
5rem  ##########################################################################
6rem  copyright 2010-2012,2014 Thomas E. Dickey
7rem  copyright 1996, Michael D. Brennan
8rem
9rem  This is a source file for mawk, an implementation of
10rem  the AWK programming language.
11rem
12rem  Mawk is distributed without warranty under the terms of
13rem  the GNU General Public License, version 2, 1991.
14rem  ##########################################################################
15rem
16rem  This is a simple test that a new-made mawk seems to
17rem  be working OK.
18rem  It's certainly not exhaustive, but the last two tests in
19rem  particular use most features.
20rem
21rem  It needs to be run from mawk/test.
22rem  You also need a binary-compare utility, e.g., "cmp".
23setlocal
24
25	set dat=mawktest.dat
26	if %CMP%.==. set CMP=cmp
27
28	set PROG=..\mawk
29	set MAWKBINMODE=7
30
31	set STDOUT=temp$$
32
33rem  find out which mawk we're testing
34	%PROG% -Wv
35
36rem ################################
37
38	call :begin testing input and field splitting
39
40	%PROG% -f null-rs.awk null-rs.dat > %STDOUT%
41	call :compare "null-rs.awk" %STDOUT% null-rs.out
42
43	%PROG% -f wc.awk %dat% > %STDOUT%
44	call :compare "wc.awk" %STDOUT% wc-awk.out
45
46	call :cmpsp2 "(a?)*b" "a*b"
47	call :cmpsp2 "(a?)+b" "a*b"
48	call :cmpsp2 "[^^]"   "(.)"
49rem	call :cmpsp2 "[^]]"   "[[#a-zA-Z0-9/*!=<>+,;.&_%(){}" -]"
50	call :cmpsp2 "[a[]"   "[[a]"
51rem	call :cmpsp2 "(])"    "[]]"
52	call :chkone "[\"
53rem	call :cmpsp2 "(^)?)"  ")"
54	call :cmpsp3 "a*+"    "a*"
55
56	%PROG% -F "\000"    -f nulls0.awk mawknull.dat > %STDOUT%
57	%PROG% -F "[\000 ]" -f nulls0.awk mawknull.dat >> %STDOUT%
58	call :compare "nulls" %STDOUT% nulls.out
59
60rem ####################################
61
62	call :begin testing regular expression matching
63	%PROG% -f reg0.awk %dat% > %STDOUT%
64	%PROG% -f reg1.awk %dat% >> %STDOUT%
65	%PROG% -f reg2.awk %dat% >> %STDOUT%
66	%PROG% -f reg3.awk %dat% >> %STDOUT%
67	%PROG% -f reg4.awk %dat% >> %STDOUT%
68	%PROG% -f reg5.awk %dat% >> %STDOUT%
69	%PROG% -f reg6.awk %dat% >> %STDOUT%
70	%PROG% -f reg7.awk %dat% >> %STDOUT%
71	call :compare "reg0-reg7" %STDOUT% reg-awk.out
72
73	echo ''Italics with an apostrophe' embedded'' | %PROG% -f noloop.awk
74	echo ''Italics with an apostrophe'' embedded'' | %PROG% -f noloop.awk
75
76	%PROG% "/^[^^]*$/" %dat% > %STDOUT%
77	call :compare "case 1" %STDOUT% %dat%
78
79rem	call :cmpsp0 "!/^[^]]*$/" "/]/"
80rem	call :cmpsp0 "/[a[]/"     "/[[a]/"
81rem	call :cmpsp0 "/]/"        "/[]]/"
82
83rem ######################################
84
85	call :begin testing arrays and flow of control
86	%PROG% -f wfrq0.awk %dat% > %STDOUT%
87	call :compare "array-test" %STDOUT% wfrq-awk.out
88
89rem ######################################
90
91	call :begin testing nextfile
92	%PROG% -f nextfile.awk full-awk.dat %dat% > %STDOUT%
93	call :compare "nextfile-test" %STDOUT% nextfile.out
94
95rem ################################
96
97	call :begin testing function calls and general stress test
98	%PROG% -f ../examples/decl.awk %dat% > %STDOUT%
99	call :compare "general" %STDOUT% decl-awk.out
100
101	echo.
102	echo if %CMP% always encountered "no differences", then the tested mawk seems OK
103
104	del %STDOUT%
105
106endlocal
107goto :eof
108
109:cmpsp0
110	echo ...checking %1 vs %2
111	%PROG% -F "%1" %dat% > %STDOUT%
112	%PROG% -F "%2" %dat% | cmp -s - %STDOUT%
113	if errorlevel 1 goto :errsp0
114	echo ...ok
115	goto :eof
116:errsp0
117	echo ...fail
118	goto :eof
119
120:chkone
121	echo ...checking %1
122	%PROG% -F "%1" 2> %STDOUT%
123	if errorlevel 1 goto :errsp1
124	echo ...ok
125	goto :eof
126:errsp1
127	echo ...fail
128	goto :eof
129
130:cmpsp2
131	echo ...checking %1 vs %2
132	%PROG% -F "%1" -f wc.awk %dat% > %STDOUT%
133	%PROG% -F "%2" -f wc.awk %dat% | cmp -s - %STDOUT%
134	if errorlevel 1 goto :errsp2
135	echo ...ok
136	goto :eof
137:errsp2
138	echo ...fail
139	goto :eof
140
141:cmpsp3
142	echo ...checking %1 vs %2
143	%PROG% -F "%1" "{print NF}" > %STDOUT%
144	%PROG% -F "%2" "{print NF}" | cmp -s - %STDOUT%
145	if errorlevel 1 goto :errsp3
146	echo ...ok
147	goto :eof
148:errsp3
149	echo ...fail
150	goto :eof
151
152:begin
153	echo.
154	echo %*
155	goto :eof
156
157:compare
158	set TESTNAME=%1
159	echo ...checking %2 %3
160	%CMP% %2 %3
161	if errorlevel 1 goto :failed
162	echo ...ok
163	goto :eof
164:failed
165	echo ...fail
166	goto :eof
167