[racket] rackunit positive feedback

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Tue May 17 10:39:45 EDT 2011

On 05/17/2011 06:12 AM, Russell Adams wrote:
> On Mon, May 16, 2011 at 11:34:39PM -0600, Ryan Culpepper wrote:
>> On 05/16/2011 09:38 PM, Russell Adams wrote:
>>> Folks,
>>>
>>> I'm incredibly pleased with rackunit, having just used it on a funky
>>> piece of parsing code, however I encountered a minor issue.
>>>
>>> For all the checks I'm doing, it'd be useful if the check's output an
>>> affirmative result, ie: "Test X: OK". That'd help separate my test
>>> output.
>>>
>>> I didn't see an immediately obvious way to accomplish this, having
>>> tried 'verbose and define-test-suite, which just enabled a summary.
>>>
>>> Suggestions?
>>
>> Are you running tests with 'run-tests'? If so, I can add an option
>> to print a message for each successful test case. Or you can use the
>> rackunit gui ('test/gui'), which gives you a hierarchical view of
>> all the tests.
>>
>> Ryan
>>
>
> I had tried run-tests with 'verbose, and define-test-suite. I really
> just have a file full of checks currently, I didn't need the case or
> suite functionality yet.

If you're just executing checks rather than grouping them into test 
cases and test suites, then you can get something like what you want by 
changing the 'current-test-around' handler:

Save the old check-around handler:

   (define base-check-around (current-check-around))

The new handler will call the thunk (ie, run the check), and if the 
check succeeds (ie, does not raise an exception), then it prints out a 
message. If the check fails, the exception jumps past the call to printf 
and the base handler prints out the normal failure message.

   (define (my-check-around thunk)
     (base-check-around
       (lambda () (begin0 (thunk) (printf "Check passed\n")))))

Install the new handler:

   (current-check-around my-check-around)

Ryan


Posted on the users mailing list.