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 ;
|
|
|
|
|
|
|
|
: failure ( error what -- ) <failure> failures get push ;
|
|
|
|
|
|
|
|
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
|
|
|
|
[ ] swap unit-test ;
|
|
|
|
|
|
|
|
: 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
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: run-test ( path -- failures )
|
2008-01-09 19:13:26 -05:00
|
|
|
[ "temporary" forget-vocab ] with-compilation-unit
|
2007-09-20 18:09:08 -04:00
|
|
|
[
|
|
|
|
V{ } clone [
|
|
|
|
failures [
|
|
|
|
[ run-file ] [ swap failure ] recover
|
|
|
|
] with-variable
|
|
|
|
] keep
|
2008-01-09 19:13:26 -05:00
|
|
|
] keep
|
|
|
|
[ forget-source ] with-compilation-unit ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: failure. ( triple -- )
|
|
|
|
dup second .
|
|
|
|
dup first print-error
|
|
|
|
"Traceback" swap third write-object ;
|
|
|
|
|
|
|
|
: failures. ( path failures -- )
|
|
|
|
"Failing tests in " write swap <pathname> .
|
|
|
|
[ nl failure. nl ] each ;
|
|
|
|
|
|
|
|
: run-tests ( seq -- )
|
2008-01-11 03:32:25 -05:00
|
|
|
dup empty? [ drop "==== NOTHING TO TEST" print ] [
|
|
|
|
[ dup run-test ] { } map>assoc
|
|
|
|
[ second empty? not ] subset
|
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
|
|
|
|
[ nl failures. ] assoc-each
|
|
|
|
] if
|
2007-09-20 18:09:08 -04:00
|
|
|
] if ;
|
|
|
|
|
|
|
|
: run-vocab-tests ( vocabs -- )
|
|
|
|
[ vocab-tests-path ] map
|
|
|
|
[ dup [ ?resource-path exists? ] when ] subset
|
|
|
|
run-tests ;
|
|
|
|
|
|
|
|
: test ( prefix -- )
|
|
|
|
child-vocabs
|
|
|
|
[ vocab-source-loaded? ] subset
|
|
|
|
run-vocab-tests ;
|
|
|
|
|
|
|
|
: test-all ( -- ) "" test ;
|
|
|
|
|
2007-11-08 01:57:56 -05:00
|
|
|
: test-changes ( -- )
|
|
|
|
"" to-refresh dupd do-refresh run-vocab-tests ;
|