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-05-15 01:01:47 -04:00
|
|
|
USING: arrays errors hashtables inspector 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 ;
|
2005-06-19 00:23:01 -04:00
|
|
|
|
2006-01-09 01:34:23 -05:00
|
|
|
M: assert summary drop "Assertion failed" ;
|
2005-05-07 22:53:01 -04:00
|
|
|
|
2006-05-09 11:30:26 -04:00
|
|
|
: assert= ( a b -- ) 2dup = [ 2drop ] [ <assert> throw ] 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> - ;
|
|
|
|
|
2004-10-17 19:01:16 -04:00
|
|
|
: time ( code -- )
|
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
|
|
|
|
|
|
|
: test-path ( name -- path )
|
2005-05-18 16:26:22 -04:00
|
|
|
"/library/test/" swap ".factor" append3 ;
|
2004-10-17 19:01:16 -04:00
|
|
|
|
2005-04-07 18:54:02 -04:00
|
|
|
: test ( name -- ? )
|
2004-11-17 20:59:28 -05:00
|
|
|
[
|
2005-12-16 21:12:35 -05:00
|
|
|
"=====> " write dup write "..." print flush
|
2005-09-03 02:19:11 -04:00
|
|
|
test-path [
|
|
|
|
[ [ run-resource ] with-scope ] keep
|
|
|
|
] 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-05-09 11:30:26 -04:00
|
|
|
failures get [ first2 swap write ": " write error. ] each ;
|
2005-04-07 18:54:02 -04:00
|
|
|
|
2005-06-08 18:11:53 -04:00
|
|
|
: run-tests ( list -- )
|
|
|
|
prepare-tests [ test ] subset terpri passed. failed. ;
|
|
|
|
|
|
|
|
: tests
|
2005-10-29 23:25:38 -04:00
|
|
|
{
|
2006-07-01 16:07:10 -04:00
|
|
|
"alien"
|
|
|
|
"annotate"
|
|
|
|
"binary"
|
|
|
|
"collections/hashtables"
|
|
|
|
"collections/namespaces"
|
|
|
|
"collections/queues"
|
|
|
|
"collections/sbuf"
|
|
|
|
"collections/sequences"
|
|
|
|
"collections/strings"
|
|
|
|
"collections/vectors"
|
2005-07-08 01:32:29 -04:00
|
|
|
"combinators"
|
2006-07-01 16:07:10 -04:00
|
|
|
"continuations"
|
|
|
|
"errors"
|
2006-07-19 02:37:59 -04:00
|
|
|
"gadgets/document"
|
2006-07-01 16:07:10 -04:00
|
|
|
"gadgets/models"
|
|
|
|
"gadgets/rectangles"
|
|
|
|
"generic"
|
|
|
|
"help/porter-stemmer"
|
|
|
|
"help/topics"
|
|
|
|
"inference"
|
|
|
|
"init"
|
|
|
|
"inspector"
|
|
|
|
"interpreter"
|
|
|
|
"io/io"
|
|
|
|
"io/nested-style"
|
|
|
|
"kernel"
|
|
|
|
"math/bitops"
|
|
|
|
"math/complex"
|
|
|
|
"math/float"
|
|
|
|
"math/integer"
|
|
|
|
"math/irrational"
|
|
|
|
"math/math-combinators"
|
|
|
|
"math/random"
|
|
|
|
"math/rational"
|
|
|
|
"memory"
|
|
|
|
"parse-number"
|
|
|
|
"parser"
|
|
|
|
"parsing-word"
|
|
|
|
"prettyprint"
|
|
|
|
"random"
|
|
|
|
"redefine"
|
|
|
|
"stream"
|
|
|
|
"threads"
|
|
|
|
"tuple"
|
|
|
|
"words"
|
2006-07-06 16:16:05 -04:00
|
|
|
}
|
|
|
|
macosx? [ "cocoa" add ] when
|
|
|
|
run-tests ;
|
2005-06-08 18:11:53 -04:00
|
|
|
|
|
|
|
: benchmarks
|
2005-10-29 23:25:38 -04:00
|
|
|
{
|
2005-06-08 18:11:53 -04:00
|
|
|
"benchmark/empty-loop" "benchmark/fac"
|
|
|
|
"benchmark/fib" "benchmark/sort"
|
|
|
|
"benchmark/continuations" "benchmark/ack"
|
|
|
|
"benchmark/hashtables" "benchmark/strings"
|
|
|
|
"benchmark/vectors" "benchmark/prettyprint"
|
2005-12-25 01:27:34 -05:00
|
|
|
"benchmark/iteration"
|
2005-10-29 23:25:38 -04:00
|
|
|
} run-tests ;
|
2005-06-08 18:11:53 -04:00
|
|
|
|
|
|
|
: compiler-tests
|
2005-10-29 23:25:38 -04:00
|
|
|
{
|
2005-12-07 00:14:24 -05:00
|
|
|
"io/buffer"
|
2006-07-01 16:07:10 -04:00
|
|
|
"compiler/simple"
|
|
|
|
"compiler/templates"
|
|
|
|
"compiler/stack"
|
|
|
|
"compiler/ifte"
|
|
|
|
"compiler/generic"
|
|
|
|
"compiler/bail-out"
|
|
|
|
"compiler/intrinsics"
|
|
|
|
"compiler/float"
|
|
|
|
"compiler/identities"
|
|
|
|
"compiler/optimizer"
|
|
|
|
"compiler/alien"
|
|
|
|
"compiler/callbacks"
|
2005-10-29 23:25:38 -04:00
|
|
|
} run-tests ;
|