Gregory Woodhouse | 30 Jul 2012 21:13
Gravatar

Checking for exceptions in RackUnit

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)
  (let
      ([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))
    val))

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

(test-begin
 (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
. . error: duplicate

(Continue reading)

David Van Horn | 30 Jul 2012 21:16
Favicon
Gravatar

Re: Checking for exceptions in RackUnit

On 7/30/12 3:13 PM, Gregory Woodhouse wrote:
> 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)
>    (let
>        ([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))
>      val))
>
> 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
>
> (test-begin
>   (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
(Continue reading)

Gregory Woodhouse | 30 Jul 2012 21:58
Gravatar

Re: Checking for exceptions in RackUnit

Thanks.

On Jul 30, 2012, at 12:16 PM, David Van Horn <dvanhorn-1vnkWVZi4QaVc3sceRu5cw@public.gmane.org> wrote:

check-exn should take a thunk as the second argument.  I think you want:

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

David

____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Gmane