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

From: Harry Spier (vasishtha.spier at gmail.com)
Date: Tue Nov 27 19:32:15 EST 2012

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

Posted on the users mailing list.