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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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 -- ? )
|
2019-10-18 09:05:06 -04:00
|
|
|
"temporary" forget-vocab
|
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 ;
|
|
|
|
|
|
|
|
|
|
: passed.
|
|
|
|
|
"Tests passed:" print . ;
|
|
|
|
|
|
|
|
|
|
: failed.
|
|
|
|
|
"Tests failed:" print
|
2006-10-06 20:27:40 -04:00
|
|
|
failures get [
|
|
|
|
|
first2 swap write-pathname ": " write error.
|
|
|
|
|
] each ;
|
2005-04-07 18:54:02 -04:00
|
|
|
|
2006-09-06 18:32:41 -04:00
|
|
|
: run-tests ( seq -- )
|
2019-10-18 09:05:06 -04:00
|
|
|
failures off [ run-test ] subset terpri passed. failed. ;
|