[racket] Checking for exceptions in RackUnit

From: Gregory Woodhouse (gregwoodhouse at me.com)
Date: Mon Jul 30 15:13:21 EDT 2012

Okay, here's another question related to my little Sudoku project. Before I decided to switch to using rackunit for runit tests, I had a unit test that
looked like this

(define (test3)
      ([val 'fail]
       [g (new grid%)])
    (with-handlers ([exn:fail? (lambda (exn) (set! val 'pass))])
      (send g set-cell! 1 1 1)
      (send g set-cell! 1 2 1))

The idea is that setting cells (1, 1) and (1, 2) to 1 is a duplicate and raises an error. This works. But this does not

 (define x (new grid%))
 (check-exn exn:fail?
            (send x set-cell! 1 1 1)
            (send x set-cell! 1 2 1)))

When I run the tests, I get

Welcome to DrRacket, version 5.2.1 [3m].
Language: racket/base; memory limit: 128 MB.
. . error: duplicate


Posted on the users mailing list.