1 ! Copyright (C) 2003, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors namespaces arrays prettyprint sequences kernel
4 vectors quotations words parser assocs combinators continuations
5 debugger io io.styles io.files vocabs vocabs.loader source-files
6 compiler.units summary stack-checker effects tools.vocabs ;
11 : <failure> ( error what -- triple )
12 error-continuation get 3array ;
14 : failure ( error what -- )
15 <failure> failures get push ;
19 : (unit-test) ( what quot -- )
20 swap dup . flush this-test set
22 [ this-test get failure ] recover
27 : unit-test ( output input -- )
29 { } swap with-datastack swap >array assert=
30 ] 2curry (unit-test) ;
32 : short-effect ( effect -- pair )
33 [ in>> length ] [ out>> length ] bi 2array ;
35 : must-infer-as ( effect quot -- )
36 >r 1quotation r> [ infer short-effect ] curry unit-test ;
38 : must-infer ( word/quot -- )
39 dup word? [ 1quotation ] when
40 [ infer drop ] curry [ ] swap unit-test ;
42 : must-fail-with ( quot pred -- )
45 [ t ] swap unit-test ;
47 : must-fail ( quot -- )
48 [ drop t ] must-fail-with ;
50 : (run-test) ( vocab -- )
51 dup vocab-source-loaded? [
52 vocab-tests [ run-file ] each
55 : run-test ( vocab -- failures )
58 [ (run-test) ] [ swap failure ] recover
62 : failure. ( triple -- )
65 "Traceback" swap third write-object ;
67 : test-failures. ( assoc -- )
71 "==== ALL TESTS PASSED" print
73 "==== FAILING TESTS:" print
80 "==== NOTHING TO TEST" print
83 : run-tests ( prefix -- failures )
85 [ dup run-test ] { } map>assoc
86 [ second empty? not ] filter
90 run-tests test-failures. ;
92 : run-all-tests ( prefix -- failures )
96 run-all-tests test-failures. ;