1 USING: accessors continuations debugger eval io kernel kernel.private
2 math math.ratios memory namespaces sequences tools.test vectors words
4 IN: continuations.tests
6 : (callcc1-test) ( n obj -- n' obj )
8 over 0 = [ "test-cc" get continue-with ] when
11 : callcc1-test ( x -- list )
13 "test-cc" set V{ } clone (callcc1-test)
16 : callcc-namespace-test ( -- ? )
21 6 "x" set "test-cc" get continue
23 ] callcc0 "x" get 5 = ;
25 { t } [ 10 callcc1-test 10 <iota> reverse >vector = ] unit-test
26 { t } [ callcc-namespace-test ] unit-test
28 [ 5 throw ] [ 5 = ] must-fail-with
31 [ "Hello" throw ] ignore-errors
37 [ 20 5 / ] [ division-by-zero? ] ignore-error/f
38 [ 20 0 / ] [ division-by-zero? ] ignore-error/f
41 "!!! The following error is part of the test" print
43 { } [ [ 6 [ 12 [ "2 car" ] ] ] print-error ] unit-test
45 "!!! The following error is part of the test" print
47 { } [ [ [ "2 car" ] eval ] try ] unit-test
53 [ "4" throw ] ignore-errors
58 : don't-compile-me ( -- ) ;
59 : foo ( -- ) get-callstack "c" set don't-compile-me ;
60 : bar ( -- a b ) 1 foo 2 ;
62 << { don't-compile-me foo bar } [ t "no-compile" set-word-prop ] each >>
64 { 1 2 } [ bar ] unit-test
66 { t } [ \ bar def>> "c" get innermost-frame-executing = ] unit-test
68 { 1 } [ "c" get innermost-frame-scan ] unit-test
70 SYMBOL: always-counter
78 [ ] [ always-counter inc ] [ error-counter inc ] cleanup
80 [ 1 ] [ always-counter get ] unit-test
81 [ 0 ] [ error-counter get ] unit-test
85 [ always-counter inc ]
86 [ error-counter inc ] cleanup
87 ] [ "a" = ] must-fail-with
89 [ 2 ] [ always-counter get ] unit-test
90 [ 1 ] [ error-counter get ] unit-test
94 [ always-counter inc "a" throw ]
95 [ error-counter inc ] cleanup
96 ] [ "a" = ] must-fail-with
98 [ 3 ] [ always-counter get ] unit-test
99 [ 1 ] [ error-counter get ] unit-test
102 { } [ [ return ] with-return ] unit-test
104 [ { } [ ] attempt-all ] [ attempt-all-error? ] must-fail-with
106 { { 4 } } [ { 2 2 } [ + ] with-datastack ] unit-test
108 [ with-datastack ] must-infer