factor/library/test/test.factor

115 lines
3.1 KiB
Factor
Raw Normal View History

2004-07-16 02:26:21 -04:00
! Factor test suite.
IN: test
2005-02-14 21:58:07 -05:00
USING: errors kernel lists math memory namespaces parser
prettyprint sequences io strings vectors 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-05-10 22:30:58 -04:00
2dup = [ 2drop ] [ <assert> throw ] ifte ;
2004-07-16 02:26:21 -04:00
2004-08-04 03:12:55 -04:00
: print-test ( input output -- )
2005-08-22 15:33:18 -04:00
"--> " write 2vector . 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.
[ [ not ] catch ] cons [ f ] swap 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-04-16 00:23:27 -04:00
[ [ dup error. cons failure f ] [ t ] ifte* ] catch ;
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 ] keep ] assert-depth drop
] 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-06-08 18:11:53 -04:00
"lists/cons" "lists/lists" "lists/assoc"
"lists/namespaces" "lists/queues"
2005-07-08 01:32:29 -04:00
"combinators"
2005-06-08 18:11:53 -04:00
"continuations" "errors" "hashtables" "strings"
"namespaces" "generic" "tuple" "files" "parser"
2005-07-31 23:38:33 -04:00
"parse-number" "init" "io/io"
2005-08-23 15:50:32 -04:00
"vectors" "words" "prettyprint" "random"
2005-06-08 18:11:53 -04:00
"stream" "math/bitops"
"math/math-combinators" "math/rational" "math/float"
"math/complex" "math/irrational" "math/integer"
"math/matrices"
"httpd/url-encoding" "httpd/html" "httpd/httpd"
"httpd/http-client" "sbuf" "threads" "parsing-word"
"inference" "interpreter" "alien"
"gadgets/line-editor" "gadgets/rectangles"
2005-08-25 15:27:38 -04:00
"gadgets/gradients" "gadgets/frames" "memory"
2005-07-17 00:21:10 -04:00
"redefine" "annotate" "sequences" "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"
} run-tests ;
2005-06-08 18:11:53 -04:00
: compiler-tests
{
2005-06-08 18:11:53 -04:00
"io/buffer" "compiler/optimizer"
"compiler/simple"
"compiler/stack" "compiler/ifte"
"compiler/generic" "compiler/bail-out"
"compiler/linearizer" "compiler/intrinsics"
"compiler/identities"
} run-tests ;
2005-06-08 18:11:53 -04:00
: all-tests tests compiler-tests benchmarks ;