1
\ To test the ANS Forth Exception word set and extension words
3
\ This program was written by Gerry Jackson in 2006, with contributions from
4
\ others where indicated, and is in the public domain - it can be distributed
5
\ and/or modified in any way but please retain this notice.
7
\ This program is distributed in the hope that it will be useful,
8
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
9
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
\ The tests are not claimed to be comprehensive or correct
13
\ ------------------------------------------------------------------------------
14
\ Version 0.4 1 April 2012 Tests placed in the public domain.
15
\ 0.3 6 March 2009 { and } replaced with T{ and }T
16
\ 0.2 20 April 2007 ANS Forth words changed to upper case
17
\ 0.1 Oct 2006 First version released
19
\ ------------------------------------------------------------------------------
20
\ The tests are based on John Hayes test program for the core word set
22
\ Words tested in this file are:
23
\ CATCH THROW ABORT ABORT"
25
\ ------------------------------------------------------------------------------
26
\ Assumptions and dependencies:
27
\ - the forth system under test throws an exception with throw
28
\ code -13 for a word not found by the text interpreter. The
29
\ undefined word used is $$qweqweqwert$$, if this happens to be
30
\ a valid word in your system change the definition of t7 below
31
\ - tester.fr or ttester.fs has been loaded prior to this file
32
\ - CASE, OF, ENDOF and ENDCASE from the core extension wordset
33
\ are present and work correctly
34
\ ------------------------------------------------------------------------------
40
: C1 1 2 3 ['] T1 CATCH ;
41
T{ C1 -> 1 2 3 9 0 }T \ No THROW executed
44
: C2 1 2 ['] T2 CATCH ;
45
T{ C2 -> 1 2 8 0 }T \ 0 THROW does nothing
48
: C3 1 2 ['] T3 CATCH ;
49
T{ C3 -> 1 2 99 }T \ Restores stack to CATCH depth
51
: T4 1- DUP 0> IF RECURSE ELSE 999 THROW -222 THEN ;
52
: C4 3 4 5 10 ['] T4 CATCH -111 ;
53
T{ C4 -> 3 4 5 0 999 -111 }T \ Test return stack unwinding
55
: T5 2DROP 2DROP 9999 THROW ;
56
: C5 1 2 3 4 ['] T5 CATCH \ Test depth restored correctly
57
DEPTH >R DROP 2DROP 2DROP R> ; \ after stack has been emptied
60
\ ------------------------------------------------------------------------------
68
\ The 77 in t10 is necessary for the second ABORT" test as the data stack
69
\ is restored to a depth of 2 when THROW is executed. The 77 ensures the top
70
\ of stack value is known for the results check
72
: T10 77 SWAP ABORT" This should not be displayed" ;
74
CASE EXC_ABORT OF 11 ENDOF
75
EXC_ABORT" OF 12 ENDOF
80
T{ 1 2 ' T6 C6 -> 1 2 11 }T \ Test that ABORT is caught
81
T{ 3 0 ' T10 C6 -> 3 77 }T \ ABORT" does nothing
82
T{ 4 5 ' T10 C6 -> 4 77 12 }T \ ABORT" caught, no message
84
\ ------------------------------------------------------------------------------
85
TESTING a system generated exception
87
: T7 S" 333 $$QWEQWEQWERT$$ 334" EVALUATE 335 ;
88
: T8 S" 222 T7 223" EVALUATE 224 ;
89
: T9 S" 111 112 T8 113" EVALUATE 114 ;
91
T{ 6 7 ' T9 C6 3 -> 6 7 13 3 }T \ Test unlinking of sources
93
\ ------------------------------------------------------------------------------
95
EXCEPTION-ERRORS SET-ERROR-COUNT
97
CR .( End of Exception word tests) CR