[racket] Help with exception raising and testing

From: George Rudolph (rudolphg1 at citadel.edu)
Date: Tue Aug 27 20:02:41 EDT 2013

This helps.
Although the rackunit API shows a thunk, the accompanying documentation doesn't really
make this idea clear.  And as far as I can see, doesn't explain why.  The test suite documentation does talk about
using lambda definitions to delay evaluations, which makes sense given the context.  However,
I have to interpolate that the same thing is going on here, which is counterintuitive.
Does this mean I have to teach my students about lambda definitions before I can have them use rackunit for testing?
(I posted the same question in response to another kind person--I do not want to seem pedantic on the point...)

Where in the racket docs can I find that argument error raises a fail contract exception?  I somehow missed it.
When you say that, it now makes sense
to me given the error I was seeing when I ran my test code.  Thank you.


-----Original Message-----
From: users-bounces at racket-lang.org [mailto:users-bounces at racket-lang.org] On Behalf Of Galler
Sent: Tuesday, August 27, 2013 4:30 PM
To: users at racket-lang.org
Subject: Re: [racket] Help with exception raising and testing

Two issues:

1: wrap the function-under-test in a thunk

2. check for exception type, here exn:fail:contract? which is raised by raise-argument-error.  the more general exn:fail? would also work.

(require rackunit)

(test-exn "negative coin" exn:fail:contract? (λ _ (sum-coins -1 3 5 7) ))


  Racket Users list:

Posted on the users mailing list.