factor/library/test/test.factor

108 lines
3.0 KiB
Factor
Raw Normal View History

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 ;
2006-01-09 01:34:23 -05:00
M: assert summary drop "Assertion failed" ;
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-05-09 11:30:26 -04:00
: print-test ( input output -- ) "--> " write 2array . flush ;
2004-07-16 02:26:21 -04:00
: benchmark ( quot -- gctime runtime )
millis >r gc-time >r call gc-time r> - millis r> - ;
: time ( code -- )
benchmark
2005-12-16 21:12:35 -05:00
[ # " ms run / " % # " ms GC time" % ] "" make print flush ;
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
2006-05-09 11:30:26 -04:00
datastack r> >vector assert=
] keep-datastack 2drop
] time ;
2004-07-16 02:26:21 -04:00
: unit-test-fails ( quot -- )
2005-09-28 23:29:00 -04:00
[ f ] swap [ [ call t ] [ 2drop f ] recover ]
curry unit-test ;
2006-03-25 01:06:52 -05: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
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 ;
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
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-07-08 01:32:29 -04:00
"combinators"
"continuations" "errors"
"collections/hashtables" "collections/sbuf"
"collections/strings" "collections/namespaces"
"collections/vectors" "collections/sequences"
2005-12-10 01:02:13 -05:00
"collections/queues" "generic" "tuple" "parser"
2005-07-31 23:38:33 -04:00
"parse-number" "init" "io/io"
2005-12-10 01:02:13 -05:00
"words" "prettyprint" "random" "stream" "math/bitops"
2005-06-08 18:11:53 -04:00
"math/math-combinators" "math/rational" "math/float"
2005-10-21 02:46:54 -04:00
"math/complex" "math/irrational"
"math/integer" "math/random" "threads" "parsing-word"
"inference" "interpreter" "alien"
2006-06-07 23:04:37 -04:00
"gadgets/line-editor" "gadgets/rectangles" "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"
2005-12-25 01:27:34 -05:00
"benchmark/iteration"
} run-tests ;
2005-06-08 18:11:53 -04:00
: compiler-tests
{
2005-12-07 00:14:24 -05:00
"io/buffer"
2006-04-11 02:45:24 -04:00
"compiler/simple" "compiler/templates"
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"
2006-05-05 20:06:57 -04:00
"compiler/intrinsics" "compiler/float"
2005-12-07 00:14:24 -05:00
"compiler/identities" "compiler/optimizer"
2006-02-11 02:30:18 -05:00
"compiler/alien" "compiler/callbacks"
} run-tests ;