2008-01-09 19:13:26 -05:00
|
|
|
! Copyright (C) 2003, 2008 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: namespaces arrays prettyprint sequences kernel
|
|
|
|
vectors quotations words parser assocs combinators
|
|
|
|
continuations debugger io io.files vocabs tools.time
|
2008-02-06 14:15:15 -05:00
|
|
|
vocabs.loader source-files compiler.units inspector ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: tools.test
|
|
|
|
|
|
|
|
SYMBOL: failures
|
|
|
|
|
|
|
|
: <failure> ( error what -- triple )
|
|
|
|
error-continuation get 3array ;
|
|
|
|
|
2008-02-06 23:12:44 -05:00
|
|
|
: failure ( error what -- )
|
|
|
|
<failure> failures get push ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
SYMBOL: this-test
|
|
|
|
|
|
|
|
: (unit-test) ( what quot -- )
|
|
|
|
swap dup . flush this-test set
|
|
|
|
[ time ] curry failures get [
|
2007-12-11 22:36:40 -05:00
|
|
|
[ this-test get failure ] recover
|
2007-09-20 18:09:08 -04:00
|
|
|
] [
|
|
|
|
call
|
|
|
|
] if ;
|
|
|
|
|
|
|
|
: unit-test ( output input -- )
|
|
|
|
[ 2array ] 2keep [
|
|
|
|
{ } swap with-datastack swap >array assert=
|
|
|
|
] 2curry (unit-test) ;
|
|
|
|
|
|
|
|
TUPLE: expected-error ;
|
|
|
|
|
2008-02-06 14:15:15 -05:00
|
|
|
M: expected-error summary
|
|
|
|
drop
|
|
|
|
"The unit test expected the quotation to throw an error" ;
|
|
|
|
|
|
|
|
: must-fail-with ( quot test -- )
|
|
|
|
>r [ expected-error construct-empty throw ] compose r>
|
|
|
|
[ recover ] 2curry
|
2008-02-06 16:00:10 -05:00
|
|
|
[ t ] swap unit-test ;
|
2008-02-06 14:15:15 -05:00
|
|
|
|
|
|
|
: must-fail ( quot -- )
|
|
|
|
[ drop t ] must-fail-with ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-06 14:47:19 -05:00
|
|
|
: ignore-errors ( quot -- )
|
|
|
|
[ drop ] recover ; inline
|
|
|
|
|
2008-02-06 23:12:44 -05:00
|
|
|
: (run-test) ( vocab -- )
|
|
|
|
dup vocab-source-loaded? [
|
|
|
|
vocab-tests-path dup [
|
|
|
|
dup ?resource-path exists? [
|
|
|
|
[ "temporary" forget-vocab ] with-compilation-unit
|
|
|
|
dup run-file
|
|
|
|
[ dup forget-source ] with-compilation-unit
|
|
|
|
] when
|
|
|
|
] when
|
|
|
|
] when drop ;
|
|
|
|
|
|
|
|
: run-test ( vocab -- failures )
|
|
|
|
V{ } clone [
|
|
|
|
failures [
|
|
|
|
(run-test)
|
|
|
|
] with-variable
|
|
|
|
] keep ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: failure. ( triple -- )
|
|
|
|
dup second .
|
|
|
|
dup first print-error
|
|
|
|
"Traceback" swap third write-object ;
|
|
|
|
|
2008-02-06 22:15:33 -05:00
|
|
|
: failures. ( assoc -- )
|
|
|
|
dup [
|
2007-09-20 18:09:08 -04:00
|
|
|
nl
|
2008-01-11 03:32:25 -05:00
|
|
|
dup empty? [
|
|
|
|
drop
|
|
|
|
"==== ALL TESTS PASSED" print
|
|
|
|
] [
|
|
|
|
"==== FAILING TESTS:" print
|
2008-02-06 22:15:33 -05:00
|
|
|
[
|
2008-02-06 23:12:44 -05:00
|
|
|
swap vocab-heading.
|
2008-02-06 22:15:33 -05:00
|
|
|
[ nl failure. nl ] each
|
|
|
|
] assoc-each
|
2008-01-11 03:32:25 -05:00
|
|
|
] if
|
2008-02-06 22:15:33 -05:00
|
|
|
] [
|
|
|
|
drop "==== NOTHING TO TEST" print
|
2007-09-20 18:09:08 -04:00
|
|
|
] if ;
|
|
|
|
|
2008-02-06 23:12:44 -05:00
|
|
|
: run-tests ( prefix -- failures )
|
|
|
|
child-vocabs dup empty? [ f ] [
|
2008-02-06 22:15:33 -05:00
|
|
|
[ dup run-test ] { } map>assoc
|
|
|
|
[ second empty? not ] subset
|
|
|
|
] if ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-06 22:15:33 -05:00
|
|
|
: test ( prefix -- )
|
|
|
|
run-tests failures. ;
|
|
|
|
|
|
|
|
: run-all-tests ( prefix -- failures )
|
|
|
|
"" run-tests ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-06 22:15:33 -05:00
|
|
|
: test-all ( -- )
|
|
|
|
run-all-tests failures. ;
|