factor/library/test/test.factor

139 lines
3.0 KiB
Factor
Raw Normal View History

2004-07-16 02:26:21 -04:00
! Factor test suite.
! Some of these words should be moved to the standard library.
IN: test
USE: combinators
USE: errors
USE: kernel
USE: lists
USE: logic
2004-08-26 22:21:17 -04:00
USE: math
2004-07-16 02:26:21 -04:00
USE: namespaces
USE: parser
USE: prettyprint
2004-07-16 02:26:21 -04:00
USE: stack
USE: stdio
USE: strings
USE: words
USE: unparser
: assert ( t -- )
[ "Assertion failed!" throw ] unless ;
2004-08-04 03:12:55 -04:00
: print-test ( input output -- )
2004-08-26 22:21:17 -04:00
"TESTING: " 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.
millis >r call millis r> -
unparse write " milliseconds" print ;
2004-08-04 03:12:55 -04:00
: unit-test ( output input -- )
2004-08-10 23:48:08 -04:00
[
[
2dup print-test
swap >r >r clear r> call datastack vector>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 ;
2004-07-16 02:26:21 -04:00
: test-word ( output input word -- )
2004-08-04 03:12:55 -04:00
#! Old-style test.
append unit-test ;
2004-07-16 02:26:21 -04:00
: do-not-test-word ( output input word -- )
#! Flag for tests that are known not to work.
3drop ;
: test ( name -- )
! Run the given test.
2004-08-10 23:48:08 -04:00
depth pred >r
"Testing " write dup write "..." print
2004-08-10 23:48:08 -04:00
"/library/test/" swap ".factor" cat3 run-resource
"Checking before/after depth..." print
depth r> = assert ;
2004-07-16 02:26:21 -04:00
: all-tests ( -- )
"Running Factor test suite..." print
"vocabularies" get [ f "scratchpad" set ] bind
[
"lists/cons"
"lists/lists"
"lists/assoc"
"lists/namespaces"
2004-07-16 02:26:21 -04:00
"combinators"
"continuations"
2004-08-10 23:48:08 -04:00
"errors"
2004-07-16 02:26:21 -04:00
"hashtables"
2004-08-04 03:12:55 -04:00
"strings"
2004-11-16 23:09:34 -05:00
"namespaces"
"files"
2004-08-04 03:12:55 -04:00
"format"
"parser"
"parse-number"
2004-08-04 03:12:55 -04:00
"prettyprint"
"image"
2004-10-03 16:39:32 -04:00
"init"
"inspector"
"io/io"
"listener"
"vectors"
2004-08-19 19:36:28 -04:00
"words"
"unparser"
"random"
2004-10-03 16:39:32 -04:00
"stream"
"styles"
2004-08-25 20:51:19 -04:00
"math/bignum"
2004-08-17 23:42:10 -04:00
"math/bitops"
2004-08-25 20:51:19 -04:00
"math/gcd"
"math/math-combinators"
"math/rational"
"math/float"
"math/complex"
"math/irrational"
"math/namespaces"
"httpd/url-encoding"
"httpd/html"
"httpd/httpd"
"crashes" test
"sbuf" test
"threads" test
2004-10-27 23:13:00 -04:00
"parsing-word" test
"inference" test
"interpreter" test
2004-11-16 23:09:34 -05:00
] [
test
] each
cpu "x86" = [
[
2004-11-16 23:09:34 -05:00
"hsv"
"x86-compiler/simple"
"x86-compiler/stack"
"x86-compiler/ifte"
"x86-compiler/generic"
"x86-compiler/bail-out"
] [
test
] each
] when
"benchmark/empty-loop" test
"benchmark/fac" test
"benchmark/fib" test
"benchmark/sort" test
2004-10-27 21:21:31 -04:00
"benchmark/continuations" test
"benchmark/ack" test
"benchmark/hashtables" test
"benchmark/strings" test
"benchmark/vectors" test ;