factor/core/tools/test.factor

60 lines
1.4 KiB
Factor
Raw Normal View History

! Copyright (C) 2003, 2007 Slava Pestov.
2006-05-09 11:30:26 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: errors namespaces arrays prettyprint io sequences kernel
vectors quotations words parser tools assocs ;
2004-07-16 02:26:21 -04:00
IN: test
SYMBOL: failures
2004-07-16 02:26:21 -04:00
: <failure> ( error what -- triple )
error-continuation get 3array ;
2004-07-16 02:26:21 -04:00
SYMBOL: this-test
: (unit-test) ( what quot -- )
swap dup . flush this-test set
[ time ] curry failures get [
[
this-test get <failure> failures get push
] recover
] [
call
] if ;
2005-02-12 02:23:38 -05:00
: unit-test ( output input -- )
[ 2array ] 2keep [
V{ } swap with-datastack swap >vector assert=
] curry curry (unit-test) ;
2005-04-16 00:23:27 -04:00
TUPLE: expected-error ;
2005-04-07 18:54:02 -04:00
: unit-test-fails ( quot -- )
[ f ] append [ [ drop t ] recover ] curry
[ t ] swap unit-test ;
: run-test ( path -- failures )
2004-11-17 20:59:28 -05:00
[
"temporary" forget-vocab
V{ } clone failures set
[ run-file { } ] [ swap <failure> 1array ] recover
failures get append
] with-scope ;
2005-04-07 18:54:02 -04:00
: failure. ( triple -- )
dup second .
dup first error.
"Traceback" swap third write-object ;
2005-04-07 18:54:02 -04:00
: failures. ( path failures -- )
"Failing tests in " write swap <pathname> .
[ nl failure. nl ] each ;
2005-04-07 18:54:02 -04:00
2006-09-06 18:32:41 -04:00
: run-tests ( seq -- )
[ dup run-test ] { } map>assoc
[ second empty? not ] subset
dup empty? [ drop ] [
nl
"==== FAILING TESTS:" print
[ nl failures. ] assoc-each
] if ;