factor/library/test/test.factor

118 lines
3.2 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
2005-04-02 02:39:33 -05:00
prettyprint sequences stdio strings unparser vectors words ;
2004-07-16 02:26:21 -04:00
: assert ( t -- )
[ "Assertion failed!" throw ] unless ;
2004-08-04 03:12:55 -04:00
: print-test ( input output -- )
2005-04-07 18:54:02 -04:00
"--> " write 2list . flush ;
2004-07-16 02:26:21 -04:00
2004-08-10 23:48:08 -04:00
: keep-datastack ( quot -- )
datastack >r call r> set-datastack drop ;
: 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-04-07 18:54:02 -04:00
[
unparse , " ms run / " , unparse , " ms GC time" ,
] make-string 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 = [
"Unequal before/after depth" throw
] unless ;
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-07 18:54:02 -04:00
: test-handler ( name quot -- ? )
[
[
2005-04-07 18:54:02 -04:00
dup error. cons failures cons@ f
] [
2005-04-07 18:54:02 -04:00
t
] ifte*
] catch ;
: test-path ( name -- path )
"/library/test/" swap ".factor" cat3 ;
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 ;
: eligible-tests ( -- list )
[
[
"lists/cons" "lists/lists" "lists/assoc"
"lists/namespaces" "lists/combinators" "combinators"
"continuations" "errors" "hashtables" "strings"
"namespaces" "generic" "tuple" "files" "parser"
"parse-number" "prettyprint" "image" "init" "io/io"
"listener" "vectors" "words" "unparser" "random"
"stream" "math/bignum" "math/bitops" "math/gcd"
"math/math-combinators" "math/rational" "math/float"
"math/complex" "math/irrational"
"httpd/url-encoding" "httpd/html" "httpd/httpd"
"crashes" "sbuf" "threads" "parsing-word"
"inference" "dataflow" "interpreter" "alien"
"line-editor" "gadgets" "memory" "redefine"
"annotate"
] append,
os "win32" = [
"buffer" ,
] when
cpu "unknown" = [
[
"io/buffer" "compiler/optimizer"
"compiler/simplifier" "compiler/simple"
"compiler/stack" "compiler/ifte"
"compiler/generic" "compiler/bail-out"
"compiler/linearizer"
] append,
] unless
[
"benchmark/empty-loop" "benchmark/fac"
"benchmark/fib" "benchmark/sort"
"benchmark/continuations" "benchmark/ack"
"benchmark/hashtables" "benchmark/strings"
"benchmark/vectors"
] append,
] make-list ;
: passed.
"Tests passed:" print . ;
: failed.
"Tests failed:" print
failures get [ unswons write ": " write error. ] each ;
: all-tests ( -- )
prepare-tests eligible-tests [ test ] subset
terpri passed. failed. ;