2 * The Regina Rexx Interpreter
3 * Copyright (C) 1992 Anders Christensen <anders@solan.unit.no>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* testing the implementation of the stack */
23 options MAKEBUF_BIF DROPBUF_BIF DESBUF_BIF
25 /* first check PUSH */
32 if (one^
=="SECOND") | (two^
=="FIRST") then
33 call complain
'The PUSH statement does not work'
41 if (one^
=="FIRST") | (two^
=="SECOND") then
42 call complain
'The QUEUE statement does not work'
49 if (one^
=='') | (two^
=="") then
50 call complain
'Either QUEUE or PUSH do not stack empty lines'
52 /* the queued() function */
66 call ch third
, 'three'
90 call notify
'commands'
94 /*----- Let's see if it can pipe the stack ----------------------------*/
96 queue 'To be or not to be'
97 'LIFO> tr abcdefghijkl ABCDEFGHIJKL >LIFO'
100 if line^
=='To BE or not to BE' then
101 call complain
'Can not pipe the stack-contents through a command'
103 queue 'To be or not to be'
104 Address System
'tr abcdefghijkl ABCDEFGHIJKL' With Input LIFO
'' Output LIFO
''
107 if line^
=='To BE or not to BE' then
108 call complain
'Can not pipe the stack-contents through a command using ANSI extensions'
110 /*----- does it clear the stack when command just read a few lines ----*/
116 'LIFO> head -2 | wc >LIFO'
117 if queued()^
=='1' then
118 call complain
'Commands does not clear stack'
120 parse pull lines words chars .
121 if lines words chars^
=='2 4 20' then
122 call complain
'Something is incorrect in the stack'
129 Address System
'head -2 | wc' With Input LIFO
'' Output LIFO
''
130 if queued()^
=='1' then
131 call complain
'Commands does not clear stack using ANSI extensions'
133 parse pull lines words chars .
134 if lines words chars^
=='2 4 20' then
135 call complain
'Something is incorrect in the stack using ANSI extensions'
137 /*----- let's see if it really send it through system(3) ---------------*/
138 /* sorry, too many machines don't set the USER environment variable. */
146 if myself^==alsome then
147 call complain 'Command did not resolve environment variable'
150 /*----- let's take it for some heavy piping ----------------------------*/
152 dict_words
= '/usr/dict/words'
153 if ^
stream(dict_words
, 'c', 'readable') then do
154 'man sh > /tmp/dict 2>/dev/null'
155 'man csh >> /tmp/dict 2>/dev/null'
156 'man vi >> /tmp/dict 2>/dev/null'
157 'cat /tmp/dict | tr -cs ''a-zA-z0-9'' '' '' | sort -u > /tmp/dict_words'
158 dict_words
= '/tmp/dict_words'
161 words = 'wc'('-l dict_words')
162 'cat' dict_words
'>LIFO'
163 if words != queued() then
164 call complain
'Could not get all short lines to the stack'
167 if words != queued() then
168 call complain
'Could not correctly run short lines on the stack'
170 'LIFO> sort -0.3 >LIFO'
171 if words != queued() then
172 call complain
'Could not correctly "rotate" short lines on the stack'
175 if queued() != 1 then
176 call complain
'Could not flush short lines into the stack'
179 if words != lines then
180 call complain
'Not all short lines flushed got through'
182 /*----- then, let's try the same thing with some longer lines ----------*/
185 'awk "BEGIN{while(1){print \"yes\"};}"' copies('X',10) '| head -10000 >LIFO'
187 if queued()!=10000 then
188 call complain
'Could not put 10000 lines to the stack'
191 if queued() != 10000 then
192 call complain
'Could not run long lines through cat'
195 if queued() != 10000 then
196 call complain
'Could not rotate long lines on the stack'
199 if queued() != 1 then
200 call complain
'Could not flush long stack to program'
203 /*----- The nullstring is a valid command ------------------------------*/
205 * This is kind of hard to check, but at least we can try to send a
206 * nullstring as a command, and try to catch any errors that might
209 call notify
'empty command'
213 /* The setting of RC variable checked in signal.rexx */
217 call notify
'buffers'
219 * try to check the performance of buffers. However, this is
220 * specific to some implementations
222 do queued() ; pull ; end /* just in case ... */
224 res
= makebuf() makebuf() makebuf()
225 if res \
== '1 2 3' then
226 call complain
'MAKEBUF does not return correct return value'
229 res
= dropbuf() dropbuf() dropbuf() dropbuf() dropbuf()
230 if res \
= '2 1 0 0 0' then
231 call complain
'DROPBUF does not return correct return value'
241 if line1\
='third' | line2\
='second' then
242 call complain
'DROPBUF kills line below the buffer'
251 if line1\
='second' | line2\
='first' | brc\
='2' then
252 call complain
'Reading lines doesn''t remove buffers'
258 if queued()>0 | res\
=0 then
259 call complain
'DROPBUF does not remove ''zeroth'' buffer'
274 if res\
=3 | line\
='second' then
275 call complain
'DROPBUF with negative argument did not work'
282 if queued()\
=0 | res\
=0 then
283 call complain
'DROPBUF with zero argument didn''t clear stack'
291 ch: procedure expose sigl
292 parse arg first
, second
293 if first ^
== second
then do
295 say "first= /"first
"/"
296 say "second=/"second
"/"
297 say "FuncTrip: error in " sigl":" sourceline(sigl) ; end
303 written
= written
+ length(word) + 2
304 if written
>75 then do
305 written
= length(word)
308 call charout , word || ', '
313 say 'Error discovered in function insert()'
319 say 'Tripped in line' sigl':' arg(1)'.'
320 length = charout(,' (')