rackunit-chk: a short hand for writing rackunit tests
Jay McCarthy <jay@racket-lang.org>
(require rackunit/chk) | package: rackunit-chk |
This module defines a macro, chk, that allows you to write many rackunit tests quickly. In addition, it provides some convenient wrappers around rackunit’s checks that work better with multiple values and exceptions.
syntax
(chk test ...)
test | = | strict-test | ||
| | (strict-test) | |||
| | (~seq actual expected) | |||
| | (~seq actual) | |||
strict-test | = | (~seq #:f test) | ||
| | (~seq #:t actual) | |||
| | (~seq #:exn actual exn-expected) | |||
| | (~seq #:= actual expected) |
If a test is not strict-test, then if it has two expressions, it is equivalent to a #:= strict-test. If it has one, it is equivalent to a #:t strict-test.
A #:f strict-test is equivalent to the opposite of the test provided as an argument.
A #:t strict-test is equivalent to check-not-false. Its opposite is check-false.
A #:exn strict-test is equivalent to check-exn. Its opposite is check-not-exn.
A #:= strict-test is equivalent to check-equal?. Its opposite is check-not-equal?.
syntax
(check-equal? x y)
syntax
(check-not-equal? x y)
syntax
(check-not-false x)
syntax
(check-false x)
syntax
(check-exn x e)
syntax
(check-not-exn x e)
Consider the following examples:
> (require rackunit/chk)
> (chk 1 1 #:f 1 0 #:f #:f #:f 1 0 #:f #:f 1 1 #:f (/ 1 0) +inf.0 (/ 1 0) (/ 1 0) #:f (error 'xxx "a") (error 'xxx "b") #:f #:t (/ 1 0) #:t (values 0 1) #:t (values #f 1) #:f #:t (values #f 1) 1 1 2 2 #:exn (/ 1 0) "division" #:exn (/ 1 0) #rx"di.ision" #:exn (/ 1 0) exn:fail? #:f #:exn (/ 1 1) "division" #:f #:exn (/ 1 0) "diblision" (/ 1 0) (error '/ "division by zero") #:t (chk 1) #:t 1 #:f #f #:f #:t #f 1 1 #:t 1 #:f 2 3 (values 1 2) (values 1 2) #:f (values 1 2) (values 2 3) #:f (values 1 2) 3 #:f 3 (values 1 2) (quotient/remainder 10 3) (values 3 1) #:= 1 1 [#:exn (/ 1 0) "division"] [#:f #f] [#:t 1] [#:= 1 1])