2006-05-09 11:30:26 -04:00
|
|
|
! Copyright (C) 2003, 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2004-07-16 02:26:21 -04:00
|
|
|
IN: test
|
2006-09-05 01:29:26 -04:00
|
|
|
USING: arrays errors hashtables tools io kernel math
|
2006-05-09 12:38:57 -04:00
|
|
|
memory namespaces parser prettyprint sequences strings words
|
|
|
|
vectors ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-05-09 22:34:47 -04:00
|
|
|
TUPLE: assert got expect ;
|
2006-09-06 18:32:41 -04:00
|
|
|
|
2006-08-15 03:01:24 -04:00
|
|
|
: assert ( got expect -- * ) <assert> throw ;
|
2005-05-07 22:53:01 -04:00
|
|
|
|
2006-08-01 17:35:00 -04:00
|
|
|
: assert= ( a b -- ) 2dup = [ 2drop ] [ assert ] if ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2006-07-14 05:37:00 -04:00
|
|
|
: print-test ( input output -- )
|
|
|
|
"----> Quotation: " write .
|
|
|
|
"Expected output: " write . flush ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2006-03-21 00:44:19 -05:00
|
|
|
: benchmark ( quot -- gctime runtime )
|
|
|
|
millis >r gc-time >r call gc-time r> - millis r> - ;
|
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: time ( quot -- )
|
2006-03-21 00:44:19 -05:00
|
|
|
benchmark
|
2005-12-16 21:12:35 -05:00
|
|
|
[ # " ms run / " % # " ms GC time" % ] "" make print flush ;
|
2004-10-17 19:01:16 -04:00
|
|
|
|
2004-08-04 03:12:55 -04:00
|
|
|
: unit-test ( output input -- )
|
2004-08-10 23:48:08 -04:00
|
|
|
[
|
2004-10-17 19:01:16 -04:00
|
|
|
[
|
|
|
|
2dup print-test
|
2005-04-07 18:54:02 -04:00
|
|
|
swap >r >r clear r> call
|
2006-05-09 11:30:26 -04:00
|
|
|
datastack r> >vector assert=
|
2004-10-17 19:01:16 -04:00
|
|
|
] keep-datastack 2drop
|
|
|
|
] time ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-10-10 14:28:56 -04:00
|
|
|
: unit-test-fails ( quot -- )
|
2005-09-28 23:29:00 -04:00
|
|
|
[ f ] swap [ [ call t ] [ 2drop f ] recover ]
|
|
|
|
curry unit-test ;
|
2004-10-10 14:28:56 -04:00
|
|
|
|
2006-07-23 21:38:58 -04:00
|
|
|
: assert-depth ( quot -- ) depth slip depth swap assert= ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-04-07 18:54:02 -04:00
|
|
|
SYMBOL: failures
|
2005-02-12 02:23:38 -05:00
|
|
|
|
2006-05-09 12:38:57 -04:00
|
|
|
: failure failures [ ?push ] change ;
|
2005-04-16 00:23:27 -04:00
|
|
|
|
2005-04-07 18:54:02 -04:00
|
|
|
: test-handler ( name quot -- ? )
|
2006-05-09 11:30:26 -04:00
|
|
|
catch [ dup error. 2array failure f ] [ t ] if* ;
|
2005-04-07 18:54:02 -04:00
|
|
|
|
2006-09-06 18:48:46 -04:00
|
|
|
: run-test ( path -- ? )
|
2004-11-17 20:59:28 -05:00
|
|
|
[
|
2005-12-16 21:12:35 -05:00
|
|
|
"=====> " write dup write "..." print flush
|
2006-09-06 18:32:41 -04:00
|
|
|
[
|
2006-09-29 23:03:27 -04:00
|
|
|
[ [ run-file ] with-scope ] keep
|
2005-09-03 02:19:11 -04:00
|
|
|
] assert-depth drop
|
2005-04-07 18:54:02 -04:00
|
|
|
] test-handler ;
|
|
|
|
|
2006-05-09 11:30:26 -04:00
|
|
|
: prepare-tests ( -- )
|
2006-05-09 12:38:57 -04:00
|
|
|
failures off "temporary" forget-vocab ;
|
2005-04-07 18:54:02 -04:00
|
|
|
|
|
|
|
: passed.
|
|
|
|
"Tests passed:" print . ;
|
|
|
|
|
|
|
|
: failed.
|
|
|
|
"Tests failed:" print
|
2006-10-06 17:42:12 -04:00
|
|
|
failures get [ first2 swap path. ": " write error. ] each ;
|
2005-04-07 18:54:02 -04:00
|
|
|
|
2006-09-06 18:32:41 -04:00
|
|
|
: run-tests ( seq -- )
|
|
|
|
prepare-tests [ run-test ] subset terpri passed. failed. ;
|