7.8

top ← prev up next →

RackUnit Abbrevs

For writing multiple unit tests on a single function. The macros here repeatedly apply a standard RackUnit assertion on a sequence of argument (and result) pairs.

Test failures are reported at the unit test, not at the call to one of our check- macros.

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 location: eval:3:0 name: check-true params: '(#f) --------------------

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 location: eval:5:0 name: check-false params: '(#t) --------------------

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

f to each sequence of arguments arg* and compare to result using equal? == or => or ==> is used as a delimiter, calls ( check-equal? ( f arg* ) result ) . Otherwise, calls ( check-not-equal? ( f arg* ) result ) . Applyto each sequence of argumentsand compare tousing. Whenororis used as a delimiter, calls. Otherwise, calls

Example:

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

syntax (check-exn* exn-predicate f [arg* ] )

f to the arguments arg* and assert ( check-exn exn-predicate ( lambda ( ) ( f arg* ) ) ) for each. Applyto the argumentsand assertfor each.

Examples:

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

2 Library Functions

These functions are internal to the library but may be useful elsewhere.

build-source-location-list Alias for

syntax procedure

Syntax class used to rule out patterns that are definitely not procedures.

syntax exn-predicate

Syntax class used to rule out patterns that are definitely not predicates or regular expressions.

3 Other Testing Libraries