[racket] Using rackunit to test that contract violations are caught

From: Greg Hendershott (greghendershott at gmail.com)
Date: Wed Nov 28 01:01:42 EST 2012

Yes, using `check-exn':

(check-exn exn:fail:contract? (lambda () ... ))

On Tue, Nov 27, 2012 at 7:32 PM, Harry Spier <vasishtha.spier at gmail.com> wrote:
> Is it possible in rackunit to test that contract violations are caught?
>
> In my particular case I have functions which operate on a simulated 2
> dimensional byte arrays.  The core functions (among others) are:
> (make-byte-array row-count column-count)
> (byte-array-ref row column)
> (set-byte-array! row column a-byte)
>
> Both byte-array-ref and set-byte-array! have contracts to ensure that
> both row and column arguments are in bounds.
>
> Can I set up tests in rackunit deliberately having row or column out
> of bounds in calls to byte-array-ref and set-byte-array! and if a
> contract violation occurs then thats a pass of the test, the contract
> violation doesn't abort the program and rackunit goes on to the next
> test.
>
> Thanks,
> Harry Spier
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.