Debian Codegraph @

trip/signal.rexx

raw
1 /*
2 * The Regina Rexx Interpreter
3 * Copyright (C) 1992 Anders Christensen <[email protected]>
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 written = 0
21 trace off
22
23
24 signal test009
25
26 test001:
27 /* === 001 : Simple use of Signal on syntax ============================ */
28 call notify 'simple'
29 signal on syntax name syntax001
30 if ( 1 * 'asdfgsgf' ) then
31 say 'minus one'
32 call complain 'SIGNAL ON SYNTAX does not trap runtime errors'
33 signal test002
34
35 syntax001:
36 signal test002
37
38
39 test002:
40 /* === 002 : Does CALL ON terminate statement =========================== */
41 /* call notify 'call_on' */
42 call random ,,1000
43 num = random()
44 call on halt name halt002
45 call substr 'kill'("-15" getpid()),1,random()
46
47 if ( num == random() ) then
48 call complain "CALL ON HALT does not complete statement"
49
50 if ( magic ^== '002' ) then
51 call complain "CALL ON HALT not performed"
52
53 signal test003
54
55 halt002:
56 magic = '002'
57 return
58
59
60 test003:
61 /* === 003 : Check that ERROR condition works ================== */
62 call notify 'error'
63 signal on error name error003
64 'rc' 10
65 call complain 'condition ERROR does not appear to work'
66 signal test004
67
68 error003:
69 signal test004
70
71
72 test004:
73 /* === 004 : Check that ERROR traps non-trapped FAILURE */
74 call notify 'failure'
75 signal off failure
76 signal on error name error004
77 'rc -10'
78 call complain 'condition ERROR does not trap FAILURES'
79 signal test005
80
81 error004:
82 signal test005
83
84
85 test005:
86 /* === 005 : Check that FAILURE does not trap non-trapped ERROR ====== */
87 call notify 'nofailure'
88 signal off error
89 signal on failure name fail005
90 'rc 10'
91 signal test006
92
93 fail005:
94 call complain 'FAILURE does also trap ERROR conditions'
95 signal test006
96
97
98 test006:
99 /* === 006 : CALL ON can be performed between two statement in an
100 INTERPRET statment ======================================= */
101 call notify 'interpret'
102 call on halt name halt006
103 first = 'none'
104 second = 'none'
105 third = 'none'
106 stmnt = 'first = "one" ;second = "kill"("-2" getpid()) ; third = "three"'
107 interpret stmnt
108 if first^=="one" then
109 call complain "Strange effects with INTERPRET and CALL ON"
110
111 if second^=="" then
112 call complain "CALL ON seems to interrupt the statement"
113
114 if third^=='three' then
115 call complain "CALL ON interrupts INTERPRET statement"
116
117 signal test007
118
119 halt006:
120 if third=='three' then
121 call complain "CALL ON triggered after INTERPRET was finished"
122 else if (third^=='none') then
123 call complain "Strange effects with CALL ON"
124
125 if second=='none' then
126 call complain "CALL ON triggered before statement was finished"
127 else if (second^=='') then
128 call complain "Some strange effects with CALL ON, second=<"second">"
129 return
130
131
132 test007:
133 /* === 007 : That SIGNAL/CALL OFF XXX NAME YYY is illegal ========= */
134 call notify 'off_name'
135 signal on syntax name syntax007
136 where = 'one'
137 interpret 'signal off halt name foobar'
138 where = 'junk'
139 signal next007
140
141 syntax007:
142 if where ^== 'one' then
143 call complain "SIGNAL OFF XXX NAME YYY is (illegally) allowed"
144
145 next007:
146 signal on syntax name syntax007_2
147 where = 'two'
148 interpret 'call off halt name foobar'
149 where = 'junk'
150 signal test008
151
152 syntax007_2:
153 if where ^== 'two' then
154 call complain "CALL OFF XXX NAME YYY is (illegally) allowed"
155
156 signal test008
157
158
159 test008:
160 /* === 008 : Check that DELAY mode works for the conditions it is
161 supposed to work for (ERROR/FAILURE/NOTREADY) =========== */
162 call notify 'delay'
163
164 call on error name error008
165 current = condition('d')
166 'rc 10'
167 if (rc^==11) then
168 call complain 'Variable RC set in errorhandler does not survive return'
169 if (condition('d')^==current) then
170 call complain 'New ERROR condition was not ignore in ERROR handler'
171
172 signal test009
173
174 error008:
175 if (rc^=='10') then
176 call complain 'Variable RC not properly set after ERROR condition'
177 'rc' 11
178 if (rc^=='11') then
179 call complain 'Variable RC seems to be locked in delayed mode'
180 if (condition('d')^='rc 10') then
181 call complain 'ERROR condition does not delay further ERRORS'
182 return
183
184
185 test009:
186 /* === 009 : If HALT delayed? It should not be ==================== */
187 call notify 'halt'
188 signal off syntax
189 call on halt name halt009
190 count = 0
191 junk = 'kill'('-15' getpid())
192 if ( ref == ref2 ) then
193 call complain 'CALL ON HALT appears to be ingored while delayed'
194
195 if (sourceline(sigl) ^== " junk = 'kill'('-15', getpid())") then
196 call complain 'CALL ON HALT offsets SIGL by non-zero value'
197
198 if ( count ^== 2 ) then
199 call complain 'Second HALT seems to have been ignored'
200
201 signal test010
202
203 halt009:
204 if (count = 0) then do
205 ref = sigl
206 count = 1
207 junk = 'kill'('-15', getpid())
208 junk = junk || junk
209 call on halt name halt009
210 end
211 else do
212 ref2 = sigl
213 count = 2
214 if (ref ^== ref2-16) then
215 call complain 'Troubles in line counting ...'
216 end
217 return
218
219
220 test010:
221 /* === 010 : NOVALUE must trigger on both unset and dropped
222 variables ============================================== */
223 call notify 'novalue'
224 signal on novalue name noval010
225 junk = 'just junk'
226 message = ''
227 junk = has_not_been_set
228 call complain "NOVALUE does not trap unset variables"
229
230 noval010:
231 if junk^=='just junk' then
232 call complain 'SIGNAL ON NOVALUE was not interrupted'
233
234 signal on novalue name noval010_2
235 junk = 'bar'
236 has_been_dropped = 'foo'
237 drop has_been_dropped
238 message = 'just before'
239 junk = has_been_dropped
240 call complain 'SIGNAL ON NOVALUE does not seem to have been triggered'
241 signal test011
242
243 noval010_2:
244 if message ^== 'just before' then
245
246 call complain 'Triggered by DROP, not assignment'
247
248 if junk^=='bar' then
249 call complain 'SIGNAL ON NOVALUE finished statement'
250
251 signal test011
252
253
254
255 test011:
256 /* === 011 : SIGNAL stops execution, CALL continues it =========== */
257 call notify 'execution'
258 call random ,,1000
259 first = random()
260 second = random()
261 third = random()
262 call random ,,1000
263 signal on halt name halt011
264 junk = '.' 'kill'('-15' getpid()) '.' random()
265 call complain 'SIGNAL ON HALT does not seem to work'
266
267 halt011:
268 if (first ^== random()) then
269 call complain 'SIGNAL ON HALT does not seem to break statement'
270
271 call on halt name halt011_2
272 call random ,,1000
273 junk = '.' "kill"('-15' getpid()) '.' random()
274 if (third ^== random()) then
275 call complain 'CALL ON HALT evaluates expression twice?'
276
277 signal test012
278
279 halt011_2:
280 if (second ^== random()) then
281 call complain 'CALL ON HALT does not continue expression'
282 return
283
284
285 test012:
286 /* === 012 : Make sure that CALL ON triggered in the expression
287 of an IF, DO or SELECT, is effectuated at the next
288 statement boundary, not after the (structured)
289 statement is finished ==================================== */
290 call notify 'triggered'
291 count = 0
292 signal on syntax name syntax012_1
293 if ( 1 + 1 || 'a' ) then
294 call complain "SYNTAX ON executes IF's statement after syntax error"
295 call complain "SYNTAX ON continued execution"
296
297 syntax012_1:
298 signal on syntax name syntax012_2
299 do i=4 to left('a','b')
300 call complain "SYNTAX ON executes contents of DO after error"
301 end
302 call complain "SYNTAX ON continued execution"
303
304 syntax012_2:
305 signal on syntax name syntax012_3
306 drop two
307 select
308 when 0 then nop
309 when 'two' then
310 call complain 'SYNTAX ON exectues contents after error in WHEN'
311 when 1 then
312 call complain 'SYNTAX ON executes rest of WHEN after error'
313 otherwise
314 nop
315 end
316 call complain 'SYNTAX ON continued execution'
317
318 syntax012_3:
319 signal test013
320
321
322
323 test013:
324 /* === 013 : HALT in a CALL statement is trigger before return ========= */
325 call notify 'return'
326 call on halt name halt013
327 count = 0
328 call sub013 'kill'('-15' getpid())
329 if count^==1 then
330 call complain 'HALT handler does not seem to have been called'
331
332 signal test014
333
334 sub013:
335 count = 1
336 return
337
338 halt013:
339 if count^==0 then
340 call complain 'CALL ON HALT executes subroutine before trigging'
341 return
342
343
344 test014:
345 /* === 014 : RC is set when SYNTAX is triggered ==================== */
346 call notify 'rc/syntax'
347 signal on syntax name syntax014
348 rc = 0
349 old_envir = address()
350 address 'COMMAND'
351
352 junk = no_such_function('foobar')
353 call complain 'SYNTAX condition was not triggered'
354 signal after014
355
356 syntax014:
357 if rc^==43 then
358 call complain 'RC not set when SIGNAL ON SYNTAX triggered'
359
360 after014:
361 address (old_envir)
362 signal test015
363
364
365 test015: trace off
366 /* === 015 : Get the lineno right in INTERPRET ====================== */
367 call notify 'lineno1'
368 signal on syntax name syntax015
369 rc = 0
370 statement = "junk = 'foobar' ; call left() ; morejunk = 'xyzzy'"
371 thisline = syntax015()
372 interpret statement
373 call complain 'SIGNAL SYNTAX did not trigger'
374 signal test016
375
376 syntax015:
377 if rc=0 then
378 return sigl
379 if thisline ^== sigl-1 then
380 call complain 'SIGL not properly set when SYNTAX in INTERPRET'
381 signal test016
382
383
384
385 test016:
386 /* === 015 : Get the lineno right in INTERPRET ====================== */
387 call notify 'lineno2'
388 call on halt name halt016
389 count = 0
390 statement = "junk='foobar'; junk='kill'('-15' getpid()); morejunk='xyzzy'"
391 thisline = halt016()
392 interpret statement
393 signal test017
394
395 halt016:
396 if count=0 then do
397 count = 1 ;
398 return sigl
399 end
400 if thisline ^== sigl-1 then
401 call complain 'SIGL not properly set when CALL ON HALT in INTERPRET'
402 return
403
404
405
406 test017:
407 /* === 017 : When in delayed mode, ERRORs are ignored, and only
408 the last is remembered ================================ */
409 call notify 'in_delay'
410 call on halt name halt017
411 count = 1
412 junk = 'kill'( '-2' getpid())
413 if count^=='4' then
414 call complain 'Something is wrong in the order ERRORs are handled'
415
416 signal test018
417
418 halt017:
419 if count=1 then do
420 if (condition('D')^=='SIGINT') then
421 call complain 'Result from condition() is incorrect'
422
423 junk = 'kill'( '-1' getpid())
424 if (condition('D')^=='SIGINT') then
425 call complain 'ERRORs not ignored while in handler'
426
427 junk = 'kill'( '-15' getpid())
428 count = 2
429 call on halt name halt017
430 return
431 end
432
433 if count=2 then do
434 count = 3
435 if condition('D')^=='SIGTERM' then
436 call complain 'Does not reset DELAY mode with CALL ON'
437 junk = 'kill'( '-1' getpid() )
438 return
439 end
440
441 count = 4
442 if condition('D')^=='SIGHUP' then
443 call complain 'Wrong order in which ERRORs are handled'
444
445 return
446
447
448
449 test018:
450 /* === 018 : Is different conditions properly stacked ============== */
451 call notify 'stacking'
452 call on halt name halt018
453 call on error name error018
454
455 count = 0
456 junk = 'kill'( '-15' getpid())
457 if count ^== '7' then
458 call complain 'did not trigger both ERROR and HALT'
459
460 signal test019
461
462 halt018:
463 if count^=='0' then
464 call complain 'HALT not called initially'
465
466 count = count + 1
467 'rc 10'
468 if count^=='3' then
469 call complain 'ERROR couldnt trigger when HALT was DELAYed'
470
471 count = count + 4
472 return
473
474 error018:
475 if count^=='1' then
476 call complain 'ERROR not properly called'
477
478 count = count + 2
479 return
480
481
482
483 test019:
484 /* === 019 : Is RESULT set at return from CALL ON? =============== */
485 call notify 'result'
486 call on failure name fail019
487 result = 'foobar'
488 'rc -10'
489 if result^=='foobar' then
490 call complain 'RESULT was set at return from CALL ON'
491
492 signal test020
493
494 fail019:
495 return 'xyzzy'
496
497
498
499
500 test020:
501 /* === 020 : That CALL ON HALT in DELAYed mode is processed
502 afterwards, when the DELAY mode is removed ============== */
503 call notify 'after_delay'
504 call on halt name halt020
505 count = 0
506 junk = 'kill'( '-2' getpid())
507 if (count^==15) then
508 call complain 'CALL ON HALT does not seem to work'
509
510 signal test021
511
512 halt020:
513 if count=0 then do
514 count = count + 1
515 junk = 'kill'( '-15' getpid())
516 if (count^==1) then
517 call complain 'CALL ON HALT not in DELAYed mode'
518
519 call on halt name halt020
520 if (count^==15) then
521 call complain 'CALL ON HALT did not remove DELAYed mode'
522
523 return
524 end
525
526 if count=1 then do
527 count = count + 2
528 call on halt name halt020
529 if (count^==3) then
530 call complain 'CALL ON HALT not in DELAYed mode'
531
532 junk = 'kill'( '-15' getpid())
533 if (count^==15) then
534 call complain 'CALL ON HALT did not clear DELAYED mode'
535 return
536 end
537
538 if (count=3) then do
539 count = count + 4
540 junk = 'kill'( '-2' getpid())
541 if (count^==7) then
542 call complain 'CALL ON HALT triggered in DELAYed mode'
543 return
544 end
545
546 if (count=7) then do
547 count = count + 8
548 return
549 end
550
551 call complain 'Something is wrong with CALL ON HALT'
552 return
553
554
555
556 test021:
557 /* === 021 : condition label name is not changed in subroutines ========== */
558 call notify 'subrout'
559 count = 0
560 call on error name err021_1
561 'rc 10'
562 if (count^==1) then
563 call complain 'ERROR not triggered'
564
565 call sub021
566 count = count + 2
567 'rc 10'
568 if count^==4 then
569 call complain 'Trap information set by handler'
570
571 signal test022
572
573 err021_2:
574 count = 100
575 return
576
577 sub021:
578 call on error name err022_2
579 return
580
581 err021_1:
582 if count^==0 & count^==3 then
583 call complain 'Wrong error handler called'
584
585 count = count + 1
586 call on error name err022_2
587 return
588
589
590
591 test022:
592 /* === 022 : If delayed mode is cleared in a subroutine, then
593 it should not be cleared at the level above ============= */
594 call notify 'delay/sub'
595 count = 0
596 call on error name err022
597 'rc 10'
598 if (count^==1) then
599 call complain 'ERROR condition was not properly handled'
600
601 signal test023
602
603 err022:
604 count = count + 1
605 if (count^==1) then
606 call complain 'ERROR handler called incorrectly'
607
608 call sub022
609 'rc 10'
610 return
611
612 sub022:
613 call off error
614 return
615
616
617
618 test023:
619 /* === 023 : Information about the current trapped condition is to
620 be saved across routine calls =========================== */
621 call notify 'ctc/sub'
622 signal on error name err023_1
623 'rc 10'
624 call complain 'ERROR condition was not triggered'
625
626 err023_1:
627 if (condition('D')^=='rc 10') then
628 call complain 'Current trapped condition has incorrect information'
629
630 call sub023
631 if (condition('D')^=='rc 10') then
632 call complain 'Current trapped condition info not saved across subs'
633
634 signal test024
635
636 sub023:
637 signal on error name err023_2
638 if (condition('D')^=='rc 10') then
639 call complain 'CTC not "exposed" to subroutines'
640
641 'rc 11'
642 call complain 'ERROR was not properly triggered'
643
644 err023_2:
645 if (condition('D')^=='rc 11') then
646 call complain 'CTC was not properly set in sub routine'
647
648 return
649
650
651
652 test024:
653 /* === 024 : does SIGNAL OFF remove CALL ON? ====================== */
654 call notify 'on/off'
655 call on error name err024
656 signal off error
657 'rc 10'
658 signal test025
659
660 err024:
661 call complain 'SIGNAL OFF does not remove a CALL ON'
662 return
663
664
665
666 test025:
667 /* === 025 : does CALL ON HALT automagically change SIGL? ============= */
668 call notify 'sigl/halt'
669 call on halt name halt025
670 sigl = 'junk'
671 junk = 'kill'( '-15' getpid())
672 if (sigl=='junk') then
673 call complain 'SIGL not set during CALL ON HALT'
674
675 signal test026
676
677 halt025:
678 return
679
680
681
682 test026:
683 /* === 026 : NOVALUE triggered at all types of symbols ================= */
684 call notify 'symbols'
685 signal on novalue name noval026_1
686 junk = no_such_var_026
687 call complain 'NOVALUE not triggered at simple value'
688
689 noval026_1:
690 signal on novalue name noval026_2
691 junk = no_such_stem_026.
692 call complain 'NOVALUE not triggered on stem symbols'
693
694 noval026_2:
695 signal on novalue name noval026_3
696 junk = no_such_026.compound_026
697 call complain 'NOVALUE not triggered on compound'
698
699 noval026_3:
700 signal on novalue name noval026_4
701 stem_defined_026. = 'foobar'
702 count = 1
703 xyzzy = stem_defined_026.baz
704 count = count + 1
705 if (xyzzy^=='foobar') then
706 call complain 'Something is wrong in the use of stems'
707
708 count = count + 1
709 xyzzy = stem_undefined_026.baz
710 call complain 'NOVALUE not triggered on compound'
711 signal test027
712
713 noval026_4:
714 if count^==3 then
715 call complain 'NOVALUE triggered on unset compound when stem is set'
716 signal test027
717
718
719
720 test027:
721 /* === 027 : Check that drop is triggered at NOVALUE ============= */
722 call notify 'drop'
723 signal on novalue name noval027_1
724 drop no_such_027
725 signal ok027_1
726
727 noval027_1:
728 call complain 'NOVALUE triggered for simple symbol in DROP'
729
730 ok027_1:
731 signal on novalue name noval027_2
732 drop no_such_stem_027.
733 signal ok027_2
734
735 noval027_2:
736 call complain 'NOVALUE triggered for stem symbol in DROP'
737
738 ok027_2:
739 signal on novalue name noval027_3
740 drop no_stem_027.foobar
741 signal ok027_3
742
743 noval027_3:
744 call complain 'NOVALUE triggered for compound symbol in DROP'
745
746 ok027_3:
747 signal test028
748
749
750
751 test028:
752
753 /* need to check novalue for expose and parse */
754
755
756 say ' '
757 exit 0
758
759
760 ch: procedure expose sigl
761 parse arg first, second
762 if first ^== second then do
763 say
764 say 'first = /'first'/'
765 say 'second = /'second'/'
766 say "FuncTrip: error in " sigl":" sourceline(sigl) ; end
767 return
768
769
770 complain:
771 say ' ...'
772 say 'Tripped in line' sigl':' arg(1)'.'
773 length = charout(,' (')
774 return
775
776
777 notify:
778 parse arg word .
779 written = written + length(word) + 2
780 if written>75 then do
781 written = length(word)
782 say ' '
783 end
784 call charout , word || ', '
785 return
786
787
788 error:
789 say 'Error discovered in function insert()'
790 return