I made a simple macro which saves me the trouble of defining a test
module, requiring RackUnit and then declaring '(module+ test' after each
procedure definition, as I like to keep unit tests close by. The repo :


  Here's the macro, apologies for the broken formatting :

(define-syntax (assert stx)
(syntax-parse stx
[(_ ?a ?b)
#'(module+ test
(require rackunit)
(check-equal? ?a ?b #'?a))]
[(_ ?a)
#'(module+ test
(require rackunit)
(check-true ?a #'?a))]))

The macro works great, and I was able to pipe through an assertion message
through rackunit's check-equal? and other procedures.
I have one question however: would there be a way to make DrRacket point to
the failed assertion line instead of the macro itself when a failure
occurs? Here's a screenshot of how it looks like at the moment:

[image: assert.PNG]

  It would be even better if DrRacket highlighted the (assert ...) line
itself, but I'm asking a bit much :) If assert is an actual module, I'm not
sure where DrRacket would then point at.
I also have doubts about whenever Racket will remove the test module once
compiled. Since macros are processed at compile-time, I'm guessing it would
remove the test module right after, but let me know if you have a more
definite answer.


You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 

Reply via email to