factor/library/test/test.factor

118 lines
3.1 KiB
Factor
Raw Normal View History

2004-07-16 02:26:21 -04:00
! Factor test suite.
IN: test
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 ;
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 -- )
"--> " write 2array . flush ;
2004-07-16 02:26:21 -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> -
[ # " ms run / " % # " ms GC time" % ] "" make print ;
2004-08-04 03:12:55 -04:00
: unit-test ( output input -- )
2004-08-10 23:48:08 -04:00
[
[
2dup print-test
2005-04-07 18:54:02 -04:00
swap >r >r clear r> call
datastack >list r> assert=
] keep-datastack 2drop
] time ;
2004-07-16 02:26:21 -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 ;
2005-04-07 18:54:02 -04:00
: assert-depth ( quot -- )
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 ;
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
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-11-27 17:45:48 -05:00
"lists/cons" "lists/lists"
"lists/namespaces"
2005-07-08 01:32:29 -04:00
"combinators"
"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"
"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"
"math/integer" "threads" "parsing-word"
"inference" "interpreter" "alien"
"gadgets/line-editor" "gadgets/rectangles"
2005-10-13 00:30:44 -04:00
"gadgets/frames" "memory"
"redefine" "annotate" "binary" "inspector"
"kernel"
} run-tests ;
2005-06-08 18:11:53 -04:00
: benchmarks
{
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"
"benchmark/image" "benchmark/iteration"
} run-tests ;
2005-06-08 18:11:53 -04:00
: compiler-tests
{
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"
} run-tests ;