1 USING: kernel math namespaces io tools.test sequences vectors
\r
2 continuations debugger parser memory arrays words
\r
3 kernel.private accessors eval ;
\r
4 IN: continuations.tests
\r
6 : (callcc1-test) ( n obj -- n' obj )
\r
7 [ 1 - dup ] dip ?push
\r
8 over 0 = [ "test-cc" get continue-with ] when
\r
11 : callcc1-test ( x -- list )
\r
13 "test-cc" set V{ } clone (callcc1-test)
\r
16 : callcc-namespace-test ( -- ? )
\r
21 6 "x" set "test-cc" get continue
\r
23 ] callcc0 "x" get 5 = ;
\r
25 [ t ] [ 10 callcc1-test 10 iota reverse >vector = ] unit-test
\r
26 [ t ] [ callcc-namespace-test ] unit-test
\r
28 [ 5 throw ] [ 5 = ] must-fail-with
\r
31 [ "Hello" throw ] ignore-errors
\r
36 "!!! The following error is part of the test" print
\r
38 [ ] [ [ 6 [ 12 [ "2 car" ] ] ] print-error ] unit-test
\r
40 "!!! The following error is part of the test" print
\r
42 [ ] [ [ [ "2 car" ] eval ] try ] unit-test
\r
44 [ f throw ] must-fail
\r
46 ! Weird PowerPC bug.
\r
48 [ "4" throw ] ignore-errors
\r
53 ! ! See how well callstack overflow is handled
\r
54 ! [ clear drop ] must-fail
\r
56 ! : callstack-overflow callstack-overflow f ;
\r
57 ! [ callstack-overflow ] must-fail
\r
59 : don't-compile-me ( -- ) ;
\r
60 : foo ( -- ) callstack "c" set don't-compile-me ;
\r
61 : bar ( -- a b ) 1 foo 2 ;
\r
63 << { don't-compile-me foo bar } [ t "no-compile" set-word-prop ] each >>
\r
65 [ 1 2 ] [ bar ] unit-test
\r
67 [ t ] [ \ bar def>> "c" get innermost-frame-executing = ] unit-test
\r
69 [ 1 ] [ "c" get innermost-frame-scan ] unit-test
\r
71 SYMBOL: always-counter
\r
72 SYMBOL: error-counter
\r
75 0 always-counter set
\r
78 [ ] [ always-counter inc ] [ error-counter inc ] cleanup
\r
80 [ 1 ] [ always-counter get ] unit-test
\r
81 [ 0 ] [ error-counter get ] unit-test
\r
85 [ always-counter inc ]
\r
86 [ error-counter inc ] cleanup
\r
87 ] [ "a" = ] must-fail-with
\r
89 [ 2 ] [ always-counter get ] unit-test
\r
90 [ 1 ] [ error-counter get ] unit-test
\r
94 [ always-counter inc "a" throw ]
\r
95 [ error-counter inc ] cleanup
\r
96 ] [ "a" = ] must-fail-with
\r
98 [ 3 ] [ always-counter get ] unit-test
\r
99 [ 1 ] [ error-counter get ] unit-test
\r
102 [ ] [ [ return ] with-return ] unit-test
\r
104 [ { } [ ] attempt-all ] [ attempt-all-error? ] must-fail-with
\r
106 [ { 4 } ] [ { 2 2 } [ + ] with-datastack ] unit-test
\r
108 [ with-datastack ] must-infer
\r