Rack  Unit Abbrevs
1 API Functions
check-true*
check-false*
check-apply*
check-exn*
2 Notes
6.3.90.900

RackUnit Abbrevs

 (require rackunit-abbrevs) package: rackunit-abbrevs

A few helpers for writing many unit tests on a single function. The macros here repeatedly apply a standard RackUnit assertion.

1 API Functions

syntax

(check-true* f [arg* ...] ...)

Apply f to each sequence of arguments arg* and assert check-true on each result.

Examples:
> (check-true* (lambda (x y #:z [z 0]) (= (+ x y z) 3))
   [3 0]
   [1 2]
   [1 1 #:z 1])
> (check-true* integer?
    ["hello"])

--------------------

FAILURE

name:       check-true

expression: (check-true (integer? "hello"))

params:     (#f)

location:   (eval 3 0 3 1)

Check failure

--------------------

syntax

(check-false* f [arg* ...] ...)

Apply f to each sequence of arguments arg* and assert check-false on each result.

Examples:
> (check-false* string?
   [1]
   ['lemons])
> (check-false* =
   [2 2])

--------------------

FAILURE

name:       check-false

expression: (check-false (= 2 2))

params:     (#t)

location:   (eval 5 0 5 1)

Check failure

--------------------

syntax

(check-apply* f [arg* ... (~or == !=) result] ...)

Apply f to each sequence of arguments arg* and compare to result using equal?. More precisely, calls check-equal? (f arg* ...) result if sym is == and calls check-not-equal? (f arg* ...) result if sym is !=.

Example:
> (check-apply* map
   [add1 '(1 2 3) == '(2 3 4)]
   [append '((c)) '((a)) '((t)) != '((d o g))])

syntax

(check-exn* p f [arg* ...] ...)

Apply f to the arguments arg* and assert (check-exn p (lambda () (f arg*))) for each.

Examples:
> (check-exn* exn:fail:contract? vector-ref
   [0 #'()]
   ["hi"])
> (check-exn* "\\+: contract violation" +
   [0 #\0 'O]
   ['() '()])

--------------------

ERROR

check-exn: contract violation

  expected: (-> any/c any/c)

  given: "\\+: contract violation"

  context...:

   /home/racket/build-pkgs/racket/share/pkgs/rackunit-lib/rackunit/private/check.rkt:132:29

   /home/racket/build-pkgs/racket/share/pkgs/rackunit-lib/rackunit/private/check.rkt:57:0: top-level-check-around

   /home/racket/build-pkgs/racket/share/pkgs/rackunit-lib/rackunit/private/check.rkt:118:21: check-exn229011

   /home/racket/build-pkgs/user/.racket/6.3.90.900/pkgs/rackunit-abbrevs/private/rackunit-abbrevs.rkt:83:8

--------------------

--------------------

ERROR

check-exn: contract violation

  expected: (-> any/c any/c)

  given: "\\+: contract violation"

  context...:

   /home/racket/build-pkgs/racket/share/pkgs/rackunit-lib/rackunit/private/check.rkt:132:29

--------------------

2 Notes

You might also like Jay McCarthy’s rackunit-chk.