1 ! Copyright (C) 2003, 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces arrays prettyprint sequences kernel
4 vectors quotations words parser assocs combinators
5 continuations debugger io io.files vocabs tools.time
6 vocabs.loader source-files ;
11 : <failure> ( error what -- triple )
12 error-continuation get 3array ;
14 : failure ( error what -- ) <failure> failures get push ;
18 : (unit-test) ( what quot -- )
19 swap dup . flush this-test set
20 [ time ] curry failures get [
22 this-test get <failure> failures get push
28 : unit-test ( output input -- )
30 { } swap with-datastack swap >array assert=
31 ] 2curry (unit-test) ;
33 TUPLE: expected-error ;
35 : unit-test-fails ( quot -- )
36 [ f ] append [ [ drop t ] recover ] curry
37 [ t ] swap unit-test ;
39 : run-test ( path -- failures )
40 "temporary" forget-vocab
44 [ run-file ] [ swap failure ] recover
47 ] keep forget-source ;
49 : failure. ( triple -- )
52 "Traceback" swap third write-object ;
54 : failures. ( path failures -- )
55 "Failing tests in " write swap <pathname> .
56 [ nl failure. nl ] each ;
58 : run-tests ( seq -- )
59 [ dup run-test ] { } map>assoc
60 [ second empty? not ] subset
63 "==== FAILING TESTS:" print
64 [ nl failures. ] assoc-each
67 : run-vocab-tests ( vocabs -- )
68 [ vocab-tests-path ] map
69 [ dup [ ?resource-path exists? ] when ] subset
74 [ vocab-source-loaded? ] subset
77 : test-all ( -- ) "" test ;
79 : test-changes ( -- ) "" (refresh) run-vocab-tests ;