2004-07-16 02:26:21 -04:00
|
|
|
! Factor test suite.
|
|
|
|
|
|
|
|
IN: test
|
2005-09-11 20:46:55 -04:00
|
|
|
USING: arrays errors kernel lists math memory namespaces parser
|
|
|
|
prettyprint sequences io strings words ;
|
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
|
|
|
|
2005-05-07 22:53:01 -04:00
|
|
|
M: assert error.
|
|
|
|
"Assertion failed" print
|
|
|
|
"Expected: " write dup assert-expect .
|
|
|
|
"Got: " write assert-got . ;
|
|
|
|
|
|
|
|
: assert= ( a b -- )
|
2005-09-24 15:21:17 -04:00
|
|
|
2dup = [ 2drop ] [ <assert> throw ] if ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-08-04 03:12:55 -04:00
|
|
|
: print-test ( input output -- )
|
2005-09-11 20:46:55 -04:00
|
|
|
"--> " write 2array . flush ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-10-17 19:01:16 -04:00
|
|
|
: time ( code -- )
|
|
|
|
#! Evaluates the given code and prints the time taken to
|
|
|
|
#! execute it.
|
2004-11-22 19:15:14 -05:00
|
|
|
millis >r gc-time >r call gc-time r> - millis r> -
|
2005-08-31 21:06:13 -04:00
|
|
|
[ # " ms run / " % # " ms GC time" % ] "" make print ;
|
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
|
2005-05-07 22:53:01 -04:00
|
|
|
datastack >list r> 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 -- )
|
|
|
|
#! Assert that the quotation throws an error.
|
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
|
|
|
: assert-depth ( quot -- )
|
2005-05-07 22:53:01 -04:00
|
|
|
depth slip depth 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
|
|
|
|
2005-04-16 00:23:27 -04:00
|
|
|
: failure failures [ cons ] change ;
|
|
|
|
|
2005-04-07 18:54:02 -04:00
|
|
|
: test-handler ( name quot -- ? )
|
2005-09-24 15:21:17 -04:00
|
|
|
catch [ dup error. cons 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-04-07 18:54:02 -04:00
|
|
|
"=====> " write dup write "..." print
|
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 ;
|
|
|
|
|
|
|
|
: prepare-tests ( -- )
|
|
|
|
failures off
|
|
|
|
vocabularies get [ "temporary" off ] bind ;
|
|
|
|
|
|
|
|
: passed.
|
|
|
|
"Tests passed:" print . ;
|
|
|
|
|
|
|
|
: failed.
|
|
|
|
"Tests failed:" print
|
|
|
|
failures get [ unswons write ": " write error. ] each ;
|
|
|
|
|
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
|
|
|
{
|
2005-11-27 17:45:48 -05:00
|
|
|
"lists/cons" "lists/lists"
|
2005-09-11 20:46:55 -04:00
|
|
|
"lists/namespaces"
|
2005-07-08 01:32:29 -04:00
|
|
|
"combinators"
|
2005-09-11 20:46:55 -04:00
|
|
|
"continuations" "errors"
|
|
|
|
"collections/hashtables" "collections/sbuf"
|
|
|
|
"collections/strings" "collections/namespaces"
|
|
|
|
"collections/vectors" "collections/sequences"
|
|
|
|
"collections/queues"
|
|
|
|
"generic" "tuple" "files" "parser"
|
2005-07-31 23:38:33 -04:00
|
|
|
"parse-number" "init" "io/io"
|
2005-09-11 20:46:55 -04:00
|
|
|
"words" "prettyprint" "random"
|
2005-06-08 18:11:53 -04:00
|
|
|
"stream" "math/bitops"
|
|
|
|
"math/math-combinators" "math/rational" "math/float"
|
2005-10-21 02:46:54 -04:00
|
|
|
"math/complex" "math/irrational"
|
2005-10-24 00:08:09 -04:00
|
|
|
"math/integer" "threads" "parsing-word"
|
2005-08-12 18:02:03 -04:00
|
|
|
"inference" "interpreter" "alien"
|
2005-07-17 03:47:14 -04:00
|
|
|
"gadgets/line-editor" "gadgets/rectangles"
|
2005-10-13 00:30:44 -04:00
|
|
|
"gadgets/frames" "memory"
|
2005-09-11 20:46:55 -04:00
|
|
|
"redefine" "annotate" "binary" "inspector"
|
2005-08-12 18:02:03 -04:00
|
|
|
"kernel"
|
2005-10-29 23:25:38 -04:00
|
|
|
} 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-11-22 21:41:41 -05:00
|
|
|
"benchmark/image" "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"
|
2005-06-08 18:11:53 -04:00
|
|
|
"compiler/simple"
|
2005-09-24 23:21:09 -04:00
|
|
|
"compiler/stack" "compiler/ifte"
|
2005-06-08 18:11:53 -04:00
|
|
|
"compiler/generic" "compiler/bail-out"
|
|
|
|
"compiler/linearizer" "compiler/intrinsics"
|
2005-12-07 00:14:24 -05:00
|
|
|
"compiler/identities" "compiler/optimizer"
|
2005-10-29 23:25:38 -04:00
|
|
|
} run-tests ;
|